2023-01-13 10:39:59 +01:00
|
|
|
package logic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"git.milar.in/milarin/slices"
|
|
|
|
"git.milar.in/nyaanime/model"
|
2023-01-16 10:00:10 +01:00
|
|
|
"git.milar.in/nyaanime/parsers"
|
2023-01-13 10:39:59 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func GetAnimeEpProps(animeEp model.AnimeEpisode) (*FilePriority, bool) {
|
|
|
|
animeEpPath := GetAnimeEpFilepath(animeEp, "*")
|
|
|
|
files, err := filepath.Glob(animeEpPath)
|
|
|
|
if err != nil {
|
|
|
|
panic(ErrInvalidGlobSyntax.Wrap(err, animeEpPath))
|
|
|
|
}
|
|
|
|
|
|
|
|
var mostPrio *FilePriority
|
|
|
|
|
|
|
|
for _, file := range files {
|
2023-01-16 10:00:10 +01:00
|
|
|
props, err := parsers.AnalyzeFile(file)
|
2023-01-13 10:39:59 +01:00
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2023-01-15 22:58:41 +01:00
|
|
|
// if !HasFileEssentialProperties(props) {
|
|
|
|
// continue
|
|
|
|
// }
|
2023-01-13 10:39:59 +01:00
|
|
|
|
|
|
|
fp := NewFilePriority(props)
|
|
|
|
|
|
|
|
if mostPrio == nil || fp.Priority > mostPrio.Priority {
|
|
|
|
mostPrio = fp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mostPrio, mostPrio != nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func HasFileEssentialProperties(props model.PropertyHolder) bool {
|
|
|
|
if props.GetResolution() < MinResolution || props.GetResolution() > MaxResolution {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, essentialLanguage := range EssentialLanguages {
|
|
|
|
if !slices.Contains(props.GetLanguages(), essentialLanguage) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, essentialSubtitle := range EssentialSubtitles {
|
|
|
|
if !slices.Contains(props.GetSubtitles(), essentialSubtitle) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|