downloader/torrent_sort.go

29 lines
677 B
Go
Raw Normal View History

2022-08-15 15:55:27 +02:00
package main
2022-08-21 21:14:44 +02:00
import (
"git.milar.in/milarin/slices"
"git.milar.in/nyaanime/model"
)
2022-08-23 13:24:03 +02:00
func GetTorrentsWithMaxPrioByAnimeEp(torrents map[model.AnimeEpisode][]*model.ParsedTorrent) map[model.AnimeEpisode]*TorrentPriority {
torrentsWithPrio := map[model.AnimeEpisode]*TorrentPriority{}
2022-08-21 21:14:44 +02:00
for animeEp, torrentList := range torrents {
torrentPrioList := slices.Map(torrentList, NewTorrentPriority)
2022-08-23 13:24:03 +02:00
var maxPrio *TorrentPriority
for _, torrentPrio := range torrentPrioList {
if maxPrio == nil || torrentPrio.Priority > maxPrio.Priority {
maxPrio = torrentPrio
}
}
if maxPrio != nil {
torrentsWithPrio[animeEp] = maxPrio
}
2022-08-21 21:14:44 +02:00
}
return torrentsWithPrio
}