87 lines
2.4 KiB
Go
87 lines
2.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"git.milar.in/milarin/anilist"
|
|
"git.milar.in/milarin/slices"
|
|
"git.milar.in/nyaanime/model"
|
|
)
|
|
|
|
var AllMediaListStatuses = []anilist.MediaListStatus{
|
|
anilist.MediaListStatusCurrent,
|
|
anilist.MediaListStatusPlanning,
|
|
anilist.MediaListStatusCompleted,
|
|
anilist.MediaListStatusDropped,
|
|
anilist.MediaListStatusPaused,
|
|
anilist.MediaListStatusRepeating,
|
|
}
|
|
|
|
func ParseMediaListStatus(str string) (anilist.MediaListStatus, error) {
|
|
s := anilist.MediaListStatus(str)
|
|
|
|
allStatusesStr := slices.Map(AllMediaListStatuses, func(status anilist.MediaListStatus) string {
|
|
return string(status)
|
|
})
|
|
|
|
if !slices.Contains(AllMediaListStatuses, s) {
|
|
return s, ErrInvalidAnimeStatus.New(s, strings.Join(allStatusesStr, ","))
|
|
}
|
|
|
|
return s, nil
|
|
}
|
|
|
|
func Map2Str[K comparable, T any](m map[K]T) string {
|
|
b := new(strings.Builder)
|
|
|
|
for k, v := range m {
|
|
b.WriteString(fmt.Sprintf("%v:%v ", k, v))
|
|
}
|
|
|
|
str := b.String()
|
|
|
|
return str[:len(str)-1]
|
|
}
|
|
|
|
func FormatTorrentPriority(torrentPriority *TorrentPriority) string {
|
|
return fmt.Sprintf("id: %s | resolution: %d | languages: %s | subtitles: %s | seeders: %d | leechers: %d, | downloads: %d | trusted: %t | preferred properties: %s | priority: %d",
|
|
torrentPriority.ParsedTorrent.Torrent.ID,
|
|
torrentPriority.ParsedTorrent.Resolution,
|
|
strings.Join(torrentPriority.ParsedTorrent.Languages, ","),
|
|
strings.Join(torrentPriority.ParsedTorrent.Subtitles, ","),
|
|
torrentPriority.ParsedTorrent.Torrent.Seeders,
|
|
torrentPriority.ParsedTorrent.Torrent.Leechers,
|
|
torrentPriority.ParsedTorrent.Torrent.Downloads,
|
|
torrentPriority.ParsedTorrent.Torrent.Trusted,
|
|
Map2Str(torrentPriority.PreferredProperties),
|
|
torrentPriority.Priority,
|
|
)
|
|
}
|
|
|
|
func FormatFilePriority(animeEp model.AnimeEpisode, props *FilePriority, onList, inCollection bool, torrentCount int) string {
|
|
if !onList {
|
|
return fmt.Sprintf("\nanime: %s | episode: %d | torrents found: %d | NOT ON LIST\n",
|
|
animeEp.Anime.Title.Romaji,
|
|
animeEp.Episode,
|
|
torrentCount,
|
|
)
|
|
}
|
|
|
|
if inCollection {
|
|
return fmt.Sprintf("\nanime: %s | episode: %d | torrents found: %d | IN COLLECTION | file properties: %s | file priority: %d\n",
|
|
animeEp.Anime.Title.Romaji,
|
|
animeEp.Episode,
|
|
torrentCount,
|
|
Map2Str(props.PreferredProperties),
|
|
props.Priority,
|
|
)
|
|
}
|
|
|
|
return fmt.Sprintf("\nanime: %s | episode: %d | torrents found: %d\n",
|
|
animeEp.Anime.Title.Romaji,
|
|
animeEp.Episode,
|
|
torrentCount,
|
|
)
|
|
}
|