88 lines
2.5 KiB
Go
88 lines
2.5 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
|
||
|
"github.com/fatih/color"
|
||
|
|
||
|
"git.milar.in/milarin/slices"
|
||
|
"git.milar.in/milarin/tprint"
|
||
|
"git.milar.in/nyaanime/model"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
BoldText = color.New(color.Bold)
|
||
|
)
|
||
|
|
||
|
func ShowDebugInfo(
|
||
|
parsedTorrentsByAnimeEp, animeListTorrents, essentialTorrents map[model.AnimeEpisode][]*model.ParsedTorrent,
|
||
|
preferredTorrents map[model.AnimeEpisode]*TorrentPriority,
|
||
|
downloadingEpisodes map[model.AnimeEpisode]struct{},
|
||
|
inCollectionEpisodes map[model.AnimeEpisode]bool,
|
||
|
lowerPrioTorrents map[*model.ParsedTorrent]bool,
|
||
|
downloadedTorrents map[model.AnimeEpisode]*TorrentPriority) {
|
||
|
|
||
|
for animeEp, parsedTorrents := range parsedTorrentsByAnimeEp {
|
||
|
table := tprint.NewTable("id", "resolution", "languages", "subtitles", "seeders", "leechers", "downloads", "trusted", "evaluation")
|
||
|
|
||
|
for _, torrent := range parsedTorrents {
|
||
|
eval := getEvaluation(
|
||
|
slices.Contains(essentialTorrents[animeEp], torrent),
|
||
|
preferredTorrents[animeEp] != nil && preferredTorrents[animeEp].ParsedTorrent == torrent,
|
||
|
lowerPrioTorrents[torrent],
|
||
|
downloadedTorrents[animeEp] != nil && downloadedTorrents[animeEp].ParsedTorrent == torrent,
|
||
|
)
|
||
|
|
||
|
table.AddRow(
|
||
|
torrent.Torrent.ID,
|
||
|
torrent.Resolution,
|
||
|
strings.Join(torrent.Languages, ", "),
|
||
|
strings.Join(torrent.Subtitles, ", "),
|
||
|
torrent.Torrent.Seeders,
|
||
|
torrent.Torrent.Leechers,
|
||
|
torrent.Torrent.Downloads,
|
||
|
torrent.Torrent.Trusted,
|
||
|
eval,
|
||
|
)
|
||
|
}
|
||
|
|
||
|
var epState string
|
||
|
|
||
|
if _, onList := animeListTorrents[animeEp]; onList {
|
||
|
if _, downloading := downloadingEpisodes[animeEp]; downloading {
|
||
|
epState = color.BlueString("CURRENTLY DOWNLOADING")
|
||
|
} else if inCollectionEpisodes[animeEp] {
|
||
|
epState = color.GreenString("IN COLLECTION")
|
||
|
} else {
|
||
|
epState = color.YellowString("ON LIST")
|
||
|
}
|
||
|
} else {
|
||
|
epState = color.RedString("NOT ON LIST")
|
||
|
}
|
||
|
|
||
|
header := BoldText.Sprintf(
|
||
|
"%s episode %s (found: %d) (%s)",
|
||
|
color.MagentaString(animeEp.Anime.Title.Romaji),
|
||
|
color.MagentaString("%d", animeEp.Episode),
|
||
|
len(parsedTorrents), epState,
|
||
|
)
|
||
|
|
||
|
fmt.Println(tprint.FormatHeaderTable(header, table))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func getEvaluation(essential, preferred, lowerPrio, downloaded bool) string {
|
||
|
if downloaded {
|
||
|
return color.GreenString("DOWNLOAD STARTED")
|
||
|
} else if lowerPrio {
|
||
|
return color.GreenString("collection preferred")
|
||
|
} else if preferred {
|
||
|
return color.BlueString("torrent preferred")
|
||
|
} else if essential {
|
||
|
return color.YellowString("torrent considered")
|
||
|
} else {
|
||
|
return color.RedString("torrent ignored")
|
||
|
}
|
||
|
}
|