Compare commits

...

2 Commits

Author SHA1 Message Date
Bel LaPointe
0afb6535b6 impl -e=best-ass-to-srt 2025-06-01 09:55:01 -06:00
Bel LaPointe
10a40d4a54 nopanik choose best lang 2025-06-01 09:52:18 -06:00
3 changed files with 68 additions and 19 deletions

View File

@@ -198,27 +198,45 @@ func assToSRT(ctx context.Context, ass string) (string, error) {
}
func SRTsByGoodness(srts []string) []string {
/*
1 lat.*amer Lat.*Amer \
2 signs \
3 rus Rus \
4 por Por \
5 ita Ita \
6 fre Fre \
7 spa Spa \
8 ger Ger \
9 ara Ara \
10 jpn Jpn \
11 Europ \
12 Brazil \
13 Deu \
*/
panic("NOT IMPL")
skippers := []*regexp.Regexp{
regexp.MustCompile(`(?i)lat.*amer`),
regexp.MustCompile(`(?i)signs`),
regexp.MustCompile(`(?i)rus`),
regexp.MustCompile(`(?i)por`),
regexp.MustCompile(`(?i)ita`),
regexp.MustCompile(`(?i)fre`),
regexp.MustCompile(`(?i)spa`),
regexp.MustCompile(`(?i)ger`),
regexp.MustCompile(`(?i)ara`),
regexp.MustCompile(`(?i)jpn`),
regexp.MustCompile(`(?i)urop`),
regexp.MustCompile(`(?i)razil`),
regexp.MustCompile(`(?i)Deu`),
regexp.MustCompile(`(?i)ara`),
}
keepers := []*regexp.Regexp{
regexp.MustCompile(`(?i)^eng$`),
}
srts = slices.Clone(srts)
slices.SortFunc(srts, func(a, b string) int {
// if skip a { return 1 }
// if skip b { return -1 }
// return -1 * (wc(a) - wc(b))
a = strings.ToLower(a)
b = strings.ToLower(b)
for _, skipper := range skippers {
if skipper.MatchString(b) {
return -1
} else if skipper.MatchString(a) {
return 1
}
}
for _, keeper := range keepers {
if keeper.MatchString(a) {
return -1
} else if keeper.MatchString(b) {
return 1
}
}
return strings.Compare(a, b)
})
return srts

View File

@@ -14,6 +14,24 @@ func TestSRTsByGoodness(t *testing.T) {
given: []string{"a", "eng"},
want: "eng",
},
"eng nocap": {
given: []string{"A", "eng"},
want: "eng",
},
".Apothecary_Diaries_S02E19.mkv.0:9.ita.ass": {
given: []string{
".Apothecary_Diaries_S02E19.mkv.0:10.rus.srt",
".Apothecary_Diaries_S02E19.mkv.0:2.eng.srt",
".Apothecary_Diaries_S02E19.mkv.0:3.por.srt",
".Apothecary_Diaries_S02E19.mkv.0:4.spa.srt",
".Apothecary_Diaries_S02E19.mkv.0:5.spa.srt",
".Apothecary_Diaries_S02E19.mkv.0:6.ara.srt",
".Apothecary_Diaries_S02E19.mkv.0:7.fre.srt",
".Apothecary_Diaries_S02E19.mkv.0:8.ger.srt",
".Apothecary_Diaries_S02E19.mkv.0:9.ita.srt",
},
want: ".Apothecary_Diaries_S02E19.mkv.0:2.eng.srt",
},
}
for name, d := range cases {

View File

@@ -47,6 +47,13 @@ func Main(ctx context.Context, args []string) error {
}
}
return nil
case BestAssToSRT:
for _, pos := range flags.Pos {
if err := inass.BestAssToSRT(ctx, pos); err != nil {
return err
}
}
return nil
default:
panic(flags.Entrypoint.String())
}
@@ -58,6 +65,7 @@ type Entrypoint int
const (
Defacto Entrypoint = iota
DeportAss
BestAssToSRT
)
func (e *Entrypoint) Set(s string) error {
@@ -66,10 +74,13 @@ func (e *Entrypoint) Set(s string) error {
*e = Defacto
case DeportAss.String():
*e = DeportAss
case BestAssToSRT.String():
*e = BestAssToSRT
default:
return fmt.Errorf("%s nin (%s)", s, strings.Join([]string{
Defacto.String(),
DeportAss.String(),
BestAssToSRT.String(),
}, ", "))
}
return nil
@@ -81,6 +92,8 @@ func (e Entrypoint) String() string {
return ""
case DeportAss:
return "deport-ass"
case BestAssToSRT:
return "best-ass-to-srt"
}
panic("cannot serialize entrypoint")
}