downloader/torrent_sort.go

29 lines
677 B
Go

package main
import (
"git.milar.in/milarin/slices"
"git.milar.in/nyaanime/model"
)
func GetTorrentsWithMaxPrioByAnimeEp(torrents map[model.AnimeEpisode][]*model.ParsedTorrent) map[model.AnimeEpisode]*TorrentPriority {
torrentsWithPrio := map[model.AnimeEpisode]*TorrentPriority{}
for animeEp, torrentList := range torrents {
torrentPrioList := slices.Map(torrentList, NewTorrentPriority)
var maxPrio *TorrentPriority
for _, torrentPrio := range torrentPrioList {
if maxPrio == nil || torrentPrio.Priority > maxPrio.Priority {
maxPrio = torrentPrio
}
}
if maxPrio != nil {
torrentsWithPrio[animeEp] = maxPrio
}
}
return torrentsWithPrio
}