logic/determine_priority.go

29 lines
745 B
Go
Raw Normal View History

2023-01-13 10:21:45 +01:00
package logic
import "git.milar.in/nyaanime/model"
func DeterminePriority(props model.PropertyHolder) (priority int, preferredProperties map[string]int) {
preferredProperties = map[string]int{}
for _, lang := range props.GetLanguages() {
if langPriority, ok := PreferredLanguages[lang]; ok {
priority += langPriority
preferredProperties["lang/"+lang] = langPriority
}
}
for _, sub := range props.GetSubtitles() {
if subPriority, ok := PreferredSubtitles[sub]; ok {
priority += subPriority
preferredProperties["sub/"+sub] = subPriority
}
}
if prefRes, ok := PreferredResolutions[props.GetResolution()]; ok {
priority += prefRes
preferredProperties["res/"+props.GetResolution().String()] = prefRes
}
return
}