nopanik choose best lang
parent
4bdfbd1f06
commit
10a40d4a54
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue