Fix locale panic (#29)

This commit is contained in:
bytedream 2022-05-08 11:06:37 +02:00
parent 5e3636015b
commit ed8e63c268

View file

@ -33,9 +33,13 @@ var urlFilter = regexp.MustCompile(`(S(\d+))?(E(\d+))?((-)(S(\d+))?(E(\d+))?)?(,
func systemLocale(verbose bool) crunchyroll.LOCALE { func systemLocale(verbose bool) crunchyroll.LOCALE {
if runtime.GOOS != "windows" { if runtime.GOOS != "windows" {
if lang, ok := os.LookupEnv("LANG"); ok { if lang, ok := os.LookupEnv("LANG"); ok {
prefix := strings.Split(lang, "_")[0] var l crunchyroll.LOCALE
suffix := strings.Split(strings.Split(lang, ".")[0], "_")[1] if preSuffix := strings.Split(strings.Split(lang, ".")[0], "_"); len(preSuffix) == 1 {
l := crunchyroll.LOCALE(fmt.Sprintf("%s-%s", prefix, suffix)) l = crunchyroll.LOCALE(preSuffix[0])
} else {
prefix := strings.Split(lang, "_")[0]
l = crunchyroll.LOCALE(fmt.Sprintf("%s-%s", prefix, preSuffix[1]))
}
if !utils.ValidateLocale(l) { if !utils.ValidateLocale(l) {
if verbose { if verbose {
out.Err("%s is not a supported locale, using %s as fallback", l, crunchyroll.US) out.Err("%s is not a supported locale, using %s as fallback", l, crunchyroll.US)