polishing

This commit is contained in:
Timon Ringwald 2022-08-25 23:25:48 +02:00
parent bffab8e3fd
commit 9110cf4076
9 changed files with 61 additions and 22 deletions

View File

@ -44,26 +44,30 @@ func checkTorrents() {
for animeEp, torrentPrio := range preferredTorrents {
if IsCurrentlyDownloading(animeEp) {
downloadingEpisodes[animeEp] = struct{}{}
downloadingEpisodes[animeEp] = struct{}{} // debug output
continue
}
props, inCollection := GetAnimeEpProps(animeEp)
lowerPrio := props.Priority > torrentPrio.Priority
inCollectionEpisodes[animeEp] = inCollection
lowerPrioTorrents[torrentPrio.ParsedTorrent] = lowerPrio
if inCollection && lowerPrio {
continue
inCollectionEpisodes[animeEp] = inCollection // debug output
if inCollection {
lowerPrio := props.Priority > torrentPrio.Priority
lowerPrioTorrents[torrentPrio.ParsedTorrent] = lowerPrio // debug output
if lowerPrio {
continue
}
}
if err := DownloadTorrent(animeEp, torrentPrio.ParsedTorrent); err != nil {
fmt.Println(fmt.Sprintf("could not download torrent %s", torrentPrio.ParsedTorrent.Torrent.ID), err)
}
downloadedTorrents[animeEp] = torrentPrio
downloadedTorrents[animeEp] = torrentPrio // debug output
}
duration := time.Since(start)
ShowDebugInfo(
parsedTorrentsByAnimeEp,
animeListTorrents,
@ -75,6 +79,5 @@ func checkTorrents() {
downloadedTorrents,
)
duration := time.Since(start)
fmt.Printf("check took %s. sleeping for %s\n", duration.Truncate(time.Millisecond), (PollRate - duration).Truncate(time.Millisecond))
}

View File

@ -1,7 +1,6 @@
package main
import (
"fmt"
"io"
"net/http"
"os"
@ -18,7 +17,7 @@ func DownloadTorrent(animeEp model.AnimeEpisode, torrent *model.ParsedTorrent) e
torrentFilePath := filepath.Join(TorrentPath, path.Base(torrent.Torrent.Link))
fmt.Printf("download: %s -> %s\n", torrent.Torrent.Link, torrentFilePath)
//fmt.Printf("download: %s -> %s\n", torrent.Torrent.Link, torrentFilePath)
resp, err := http.Get(torrent.Torrent.Link)
if err != nil {

View File

@ -11,6 +11,9 @@ import (
)
var (
Uid = envvars.Int("UID", 1000)
Gid = envvars.Int("GID", 1000)
PollRate = envvars.Object("POLL_RATE", 30*time.Minute, time.ParseDuration)
AnilistUsername = envvars.String("ANILIST_USERNAME", "username")
@ -29,11 +32,19 @@ var (
template.New("anime-episode-filepath-pattern").Parse,
)
DebugAnimeEpisodePattern = envvars.Object(
"DEBUG_ANIME_LANGUAGE_PATTERN",
template.Must(template.New("anime-episode-filepath-pattern").Parse(`{{.Title.UserPreferred}} episode {{.Episode}}`)),
template.New("anime-episode-pattern").Parse,
)
AnimeStatus = envvars.ObjectSlice("ANIME_STATUS", ",", []anilist.MediaListStatus{
anilist.MediaListStatusCurrent,
anilist.MediaListStatusPlanning,
}, ParseMediaListStatus)
DownloadAll = envvars.Bool("DOWNLOAD_ALL_ANIMES", false)
// essential torrent properties
MaxResolution = envvars.Object("MAX_RESOLUTION", model.Resolution4K, model.ParseResolution)

8
go.mod
View File

@ -9,18 +9,20 @@ require (
git.milar.in/milarin/envvars/v2 v2.0.0
git.milar.in/milarin/gmath v0.0.2
git.milar.in/milarin/slices v0.0.3
git.milar.in/nyaanime/model v0.0.0-20220822093541-87208e95e7ac
git.milar.in/nyaanime/parsers v0.0.0-20220822100125-2813a7868f6a
git.milar.in/nyaanime/model v0.0.0-20220825203652-2504dcc85f73
git.milar.in/nyaanime/parsers v0.0.0-20220825163541-c840c68b761d
github.com/PuerkitoBio/goquery v1.8.0
github.com/fatih/color v1.13.0
gopkg.in/vansante/go-ffprobe.v2 v2.1.0
)
require (
git.milar.in/milarin/tprint v0.0.6 // indirect
git.milar.in/milarin/tprint v0.0.7 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/rivo/uniseg v0.3.4 // indirect
golang.org/x/net v0.0.0-20220812174116-3211cb980234 // indirect
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24 // indirect
)

17
go.sum
View File

@ -24,10 +24,22 @@ git.milar.in/milarin/tprint v0.0.5 h1:T4gszcFME+hW9bwTS/gCelFOwq7aZOX6qTngPiZor7
git.milar.in/milarin/tprint v0.0.5/go.mod h1:KVwwKRggS88ZePLssFXMdisOzJr1SU8hVEUQDzrVtAA=
git.milar.in/milarin/tprint v0.0.6 h1:OSiboAnZaeXxx/utZU4nUPSSqamdHYlh89TD02WVOwQ=
git.milar.in/milarin/tprint v0.0.6/go.mod h1:KVwwKRggS88ZePLssFXMdisOzJr1SU8hVEUQDzrVtAA=
git.milar.in/milarin/tprint v0.0.7 h1:dvm4l4BhXOie4vtnRMZii0WTLTz2wju8wyUPB/lNeVo=
git.milar.in/milarin/tprint v0.0.7/go.mod h1:UwW/B+0cTCbN5hi0bQBE9rIRgLkq+x4V751rrS2KVoI=
git.milar.in/nyaanime/model v0.0.0-20220822093541-87208e95e7ac h1:rM5Mpo4/OJuZaBNZdylag+gi8giWVwDbqsoPjhDP9+g=
git.milar.in/nyaanime/model v0.0.0-20220822093541-87208e95e7ac/go.mod h1:OzhQgj0b/Hf9fg8VXYxYt8ONQOvHm8xC44TmS9kQ150=
git.milar.in/nyaanime/model v0.0.0-20220823115053-441386b0def9 h1:5VhVM6S9NfUmjb7qbmv10RK3YE2cM5FdrfVZy2OHTXQ=
git.milar.in/nyaanime/model v0.0.0-20220823115053-441386b0def9/go.mod h1:DqRaTKOh6JRSTVLmoTQ6jrnDvGZvWrfKj3nimr6yuKs=
git.milar.in/nyaanime/model v0.0.0-20220825203105-caabe20b311b h1:u5uv/DGUaboua/GCs3zpEWZI9sI7gNg7apZNgyy0eaw=
git.milar.in/nyaanime/model v0.0.0-20220825203105-caabe20b311b/go.mod h1:DqRaTKOh6JRSTVLmoTQ6jrnDvGZvWrfKj3nimr6yuKs=
git.milar.in/nyaanime/model v0.0.0-20220825203652-2504dcc85f73 h1:fnHpasTZiZyVrXH6Yt0pARibWUveO8pLO+3upK1tboc=
git.milar.in/nyaanime/model v0.0.0-20220825203652-2504dcc85f73/go.mod h1:DqRaTKOh6JRSTVLmoTQ6jrnDvGZvWrfKj3nimr6yuKs=
git.milar.in/nyaanime/parsers v0.0.0-20220822100125-2813a7868f6a h1:7vrKOL/vpqJ8YFZ9tmq9iPLoBuLnZgptHWaScyFOFFo=
git.milar.in/nyaanime/parsers v0.0.0-20220822100125-2813a7868f6a/go.mod h1:qm6fIFBFs90uz7IJ8RKgDir0K8Fa8isixGLgrtC6kgU=
git.milar.in/nyaanime/parsers v0.0.0-20220825162145-d343540b0f88 h1:jaNVi6srnsozxSjGzQwlf+ouZr0RLOEvrGPrXCttWV0=
git.milar.in/nyaanime/parsers v0.0.0-20220825162145-d343540b0f88/go.mod h1:qm6fIFBFs90uz7IJ8RKgDir0K8Fa8isixGLgrtC6kgU=
git.milar.in/nyaanime/parsers v0.0.0-20220825163541-c840c68b761d h1:LskYoxsMQ3UgPF/6P7p7qm5xYCoe7GrYH1MZnwMTdEI=
git.milar.in/nyaanime/parsers v0.0.0-20220825163541-c840c68b761d/go.mod h1:qm6fIFBFs90uz7IJ8RKgDir0K8Fa8isixGLgrtC6kgU=
github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U=
github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI=
github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c=
@ -43,6 +55,11 @@ github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.3.4 h1:3Z3Eu6FGHZWSfNKJTOUiPatWwfc7DzJRU04jFUqJODw=
github.com/rivo/uniseg v0.3.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220812174116-3211cb980234 h1:RDqmgfe7SvlMWoqC3xwQ2blLO3fcWcxMa3eBLRdRW7E=
golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=

View File

@ -78,6 +78,12 @@ func IsCurrentlyDownloading(animeEp model.AnimeEpisode) bool {
func SetCurrentlyDownloading(animeEp model.AnimeEpisode) error {
animeEpPath := GetAnimeEpFilepath(animeEp, "lock")
dir := filepath.Dir(animeEpPath)
if err := os.MkdirAll(dir, 0755); err != nil {
return err
}
file, err := os.Create(animeEpPath)
if err != nil {
defer file.Close()

View File

@ -24,7 +24,7 @@ func ShowDebugInfo(
downloadedTorrents map[model.AnimeEpisode]*TorrentPriority) {
for animeEp, parsedTorrents := range parsedTorrentsByAnimeEp {
table := tprint.NewTable("id", "resolution", "languages", "subtitles", "seeders", "leechers", "downloads", "trusted", "evaluation")
table := tprint.NewTable("id", "resolution", "languages", "subtitles", "seeders", "leechers", "downloads", "trusted", "group", "evaluation")
for _, torrent := range parsedTorrents {
eval := getEvaluation(
@ -43,6 +43,7 @@ func ShowDebugInfo(
torrent.Torrent.Leechers,
torrent.Torrent.Downloads,
torrent.Torrent.Trusted,
torrent.Parser.Identity,
eval,
)
}
@ -61,13 +62,9 @@ func ShowDebugInfo(
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,
)
b := new(strings.Builder)
DebugAnimeEpisodePattern.Execute(b, AnimePathPatternData{Title: animeEp.Anime.Title, Episode: animeEp.Episode})
header := BoldText.Sprintf("%s (%s)", color.MagentaString(b.String()), epState)
fmt.Println(tprint.FormatHeaderTable(header, table))
}
}

View File

@ -7,6 +7,10 @@ import (
)
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 {

View File

@ -19,7 +19,7 @@ var AllMediaListStatuses = []anilist.MediaListStatus{
}
func ParseMediaListStatus(str string) (anilist.MediaListStatus, error) {
s := anilist.MediaListStatus(str)
s := anilist.MediaListStatus(strings.ToUpper(str))
allStatusesStr := slices.Map(AllMediaListStatuses, func(status anilist.MediaListStatus) string {
return string(status)