initial commit
This commit is contained in:
70
torrent_filter.go
Normal file
70
torrent_filter.go
Normal file
@ -0,0 +1,70 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"git.tordarus.net/nyaanime/logic"
|
||||
"git.tordarus.net/nyaanime/model"
|
||||
"git.tordarus.net/tordarus/anilist"
|
||||
"git.tordarus.net/tordarus/slices"
|
||||
)
|
||||
|
||||
func FilterTorrentsByAnimeList(allTorrents map[model.AnimeEpisode][]*model.ParsedTorrent, animeList map[anilist.MediaID]*anilist.MediaList) map[model.AnimeEpisode][]*model.ParsedTorrent {
|
||||
if DownloadAll {
|
||||
return allTorrents
|
||||
}
|
||||
|
||||
filtered := map[model.AnimeEpisode][]*model.ParsedTorrent{}
|
||||
for animeEp, torrents := range allTorrents {
|
||||
if _, ok := animeList[animeEp.Anime.ID]; ok {
|
||||
filtered[animeEp] = torrents
|
||||
}
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
||||
func FilterEssentialTorrents(allTorrents map[model.AnimeEpisode][]*model.ParsedTorrent) map[model.AnimeEpisode][]*model.ParsedTorrent {
|
||||
filtered := map[model.AnimeEpisode][]*model.ParsedTorrent{}
|
||||
for animeEpisode, parsedTorrents := range allTorrents {
|
||||
for _, parsedTorrent := range parsedTorrents {
|
||||
if HasEssentialProperties(parsedTorrent) {
|
||||
filtered[animeEpisode] = append(filtered[animeEpisode], parsedTorrent)
|
||||
}
|
||||
}
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
||||
func HasEssentialProperties(torrent *model.ParsedTorrent) bool {
|
||||
if torrent.Resolution < logic.MinResolution || torrent.Resolution > logic.MaxResolution {
|
||||
return false
|
||||
}
|
||||
|
||||
if torrent.Torrent.Seeders < logic.MinSeeders || torrent.Torrent.Seeders > logic.MaxSeeders {
|
||||
return false
|
||||
}
|
||||
|
||||
if torrent.Torrent.Leechers < logic.MinLeechers || torrent.Torrent.Leechers > logic.MaxLeechers {
|
||||
return false
|
||||
}
|
||||
|
||||
if torrent.Torrent.Downloads < logic.MinDownloads || torrent.Torrent.Downloads > logic.MaxDownloads {
|
||||
return false
|
||||
}
|
||||
|
||||
if logic.TrustedOnly && !torrent.Torrent.Trusted {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, essentialLanguage := range logic.EssentialLanguages {
|
||||
if !slices.Contains(torrent.Languages, essentialLanguage) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
for _, essentialSubtitle := range logic.EssentialSubtitles {
|
||||
if !slices.Contains(torrent.Subtitles, essentialSubtitle) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
Reference in New Issue
Block a user