initial commit
This commit is contained in:
58
file_props.go
Normal file
58
file_props.go
Normal file
@ -0,0 +1,58 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"git.tordarus.net/nyaanime/model"
|
||||
"git.tordarus.net/nyaanime/parsers"
|
||||
"git.tordarus.net/tordarus/slices"
|
||||
)
|
||||
|
||||
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 {
|
||||
props, err := parsers.AnalyzeFile(file)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// if !HasFileEssentialProperties(props) {
|
||||
// continue
|
||||
// }
|
||||
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user