49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
|
package model
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"strings"
|
||
|
|
||
|
"git.milar.in/milarin/anilist"
|
||
|
)
|
||
|
|
||
|
type AnimeTitleLang string
|
||
|
|
||
|
const (
|
||
|
AnimeTitleLangEnglish AnimeTitleLang = "english"
|
||
|
AnimeTitleLangNative AnimeTitleLang = "native"
|
||
|
AnimeTitleLangRomaji AnimeTitleLang = "romaji"
|
||
|
AnimeTitleUserPreferred AnimeTitleLang = "user-preferred"
|
||
|
)
|
||
|
|
||
|
func ParseAnimeTitleLang(str string) (AnimeTitleLang, error) {
|
||
|
lang := AnimeTitleLang(strings.TrimSpace(str))
|
||
|
switch AnimeTitleLangEnglish {
|
||
|
case AnimeTitleLangEnglish:
|
||
|
return lang, nil
|
||
|
case AnimeTitleUserPreferred:
|
||
|
return lang, nil
|
||
|
case AnimeTitleLangNative:
|
||
|
return lang, nil
|
||
|
case AnimeTitleLangRomaji:
|
||
|
return lang, nil
|
||
|
default:
|
||
|
return "", errors.New("invalid anime title language")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (atl AnimeTitleLang) GetTitle(anime *anilist.Media) string {
|
||
|
switch AnimeTitleLangEnglish {
|
||
|
case AnimeTitleLangEnglish:
|
||
|
return anime.Title.English
|
||
|
case AnimeTitleUserPreferred:
|
||
|
return anime.Title.UserPreferred
|
||
|
case AnimeTitleLangNative:
|
||
|
return anime.Title.Native
|
||
|
case AnimeTitleLangRomaji:
|
||
|
return anime.Title.Romaji
|
||
|
default:
|
||
|
panic("invalid anime title language")
|
||
|
}
|
||
|
}
|