downloader/show_debug_info.go

87 lines
2.6 KiB
Go
Raw Normal View History

2022-08-25 18:13:29 +02:00
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,
2023-01-15 20:21:46 +01:00
collectionPreferredTorrents map[*model.ParsedTorrent]bool,
2022-08-25 18:13:29 +02:00
downloadedTorrents map[model.AnimeEpisode]*TorrentPriority) {
for animeEp, parsedTorrents := range parsedTorrentsByAnimeEp {
2022-08-25 23:25:48 +02:00
table := tprint.NewTable("id", "resolution", "languages", "subtitles", "seeders", "leechers", "downloads", "trusted", "group", "evaluation")
2022-08-25 18:13:29 +02:00
for _, torrent := range parsedTorrents {
eval := getEvaluation(
slices.Contains(essentialTorrents[animeEp], torrent),
preferredTorrents[animeEp] != nil && preferredTorrents[animeEp].ParsedTorrent == torrent,
2023-01-15 20:21:46 +01:00
collectionPreferredTorrents[torrent],
2022-08-25 18:13:29 +02:00
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,
2022-08-25 23:25:48 +02:00
torrent.Parser.Identity,
2022-08-25 18:13:29 +02:00
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")
}
2022-08-25 23:25:48 +02:00
b := new(strings.Builder)
2023-01-16 00:44:30 +01:00
if err := DebugAnimeEpisodePattern.Execute(b, animeEp); err != nil {
panic(err)
}
2022-08-25 23:25:48 +02:00
header := BoldText.Sprintf("%s (%s)", color.MagentaString(b.String()), epState)
2022-08-25 18:13:29 +02:00
fmt.Println(tprint.FormatHeaderTable(header, table))
}
}
2023-01-15 20:21:46 +01:00
func getEvaluation(essential, preferred, collectionPreferred, downloaded bool) string {
2022-08-25 18:13:29 +02:00
if downloaded {
return color.GreenString("DOWNLOAD STARTED")
2023-01-15 20:21:46 +01:00
} else if collectionPreferred {
2022-08-25 18:13:29 +02:00
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")
}
}