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 {
|
func SRTsByGoodness(srts []string) []string {
|
||||||
/*
|
skippers := []*regexp.Regexp{
|
||||||
1 lat.*amer Lat.*Amer \
|
regexp.MustCompile(`(?i)lat.*amer`),
|
||||||
2 signs \
|
regexp.MustCompile(`(?i)signs`),
|
||||||
3 rus Rus \
|
regexp.MustCompile(`(?i)rus`),
|
||||||
4 por Por \
|
regexp.MustCompile(`(?i)por`),
|
||||||
5 ita Ita \
|
regexp.MustCompile(`(?i)ita`),
|
||||||
6 fre Fre \
|
regexp.MustCompile(`(?i)fre`),
|
||||||
7 spa Spa \
|
regexp.MustCompile(`(?i)spa`),
|
||||||
8 ger Ger \
|
regexp.MustCompile(`(?i)ger`),
|
||||||
9 ara Ara \
|
regexp.MustCompile(`(?i)ara`),
|
||||||
10 jpn Jpn \
|
regexp.MustCompile(`(?i)jpn`),
|
||||||
11 Europ \
|
regexp.MustCompile(`(?i)urop`),
|
||||||
12 Brazil \
|
regexp.MustCompile(`(?i)razil`),
|
||||||
13 Deu \
|
regexp.MustCompile(`(?i)Deu`),
|
||||||
*/
|
regexp.MustCompile(`(?i)ara`),
|
||||||
panic("NOT IMPL")
|
}
|
||||||
|
|
||||||
|
keepers := []*regexp.Regexp{
|
||||||
|
regexp.MustCompile(`(?i)^eng$`),
|
||||||
|
}
|
||||||
|
|
||||||
srts = slices.Clone(srts)
|
srts = slices.Clone(srts)
|
||||||
slices.SortFunc(srts, func(a, b string) int {
|
slices.SortFunc(srts, func(a, b string) int {
|
||||||
// if skip a { return 1 }
|
a = strings.ToLower(a)
|
||||||
// if skip b { return -1 }
|
b = strings.ToLower(b)
|
||||||
// return -1 * (wc(a) - wc(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 strings.Compare(a, b)
|
||||||
})
|
})
|
||||||
return srts
|
return srts
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,24 @@ func TestSRTsByGoodness(t *testing.T) {
|
||||||
given: []string{"a", "eng"},
|
given: []string{"a", "eng"},
|
||||||
want: "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 {
|
for name, d := range cases {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue