diff --git a/check_torrents.go b/check_torrents.go index 2b97c94..8fcdb4d 100644 --- a/check_torrents.go +++ b/check_torrents.go @@ -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)) } diff --git a/download_torrent_file.go b/download_torrent_file.go index d0396f5..96c8eca 100644 --- a/download_torrent_file.go +++ b/download_torrent_file.go @@ -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 { diff --git a/envvars.go b/envvars.go index 3166500..2880637 100644 --- a/envvars.go +++ b/envvars.go @@ -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) diff --git a/go.mod b/go.mod index 351b83d..0e92281 100644 --- a/go.mod +++ b/go.mod @@ -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/milarin/tprint v0.0.7 + 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 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 ) diff --git a/go.sum b/go.sum index 679c38e..19fd76f 100644 --- a/go.sum +++ b/go.sum @@ -8,41 +8,32 @@ git.milar.in/milarin/envvars/v2 v2.0.0 h1:DWRQCWaHqzDD8NGpSgv5tYLuF9A/dVFPAtTvz3 git.milar.in/milarin/envvars/v2 v2.0.0/go.mod h1:HkdEi+gG2lJSmVq547bTlQV4qQ0hO333bE8IrE0B9yY= git.milar.in/milarin/gmath v0.0.2 h1:avz+75f8XqAYA1wEB6kis0R5xvRuepBKTqBuJBjh6Yw= git.milar.in/milarin/gmath v0.0.2/go.mod h1:HDLftG5RLpiNGKiIWh+O2G1PYkNzyLDADO8Cd/1abiE= -git.milar.in/milarin/slices v0.0.2 h1:j92MuP0HWKSaHJMq/FRxDtSDIGiOTvw+KogUTwuulr0= -git.milar.in/milarin/slices v0.0.2/go.mod h1:XRNfE99aNKeaPOY1phjOlpIQqeGCW1LOqqh8UHS+vAk= git.milar.in/milarin/slices v0.0.3 h1:kzaLrE/G4rO2DQq3nVk2TYbuqOsiauLHClVUpgSZM8s= git.milar.in/milarin/slices v0.0.3/go.mod h1:XRNfE99aNKeaPOY1phjOlpIQqeGCW1LOqqh8UHS+vAk= -git.milar.in/milarin/tprint v0.0.1 h1:ohsQIV8tinBBjUtNXvDBtnH3xZ0F55d6o9i42S+LICY= -git.milar.in/milarin/tprint v0.0.1/go.mod h1:KVwwKRggS88ZePLssFXMdisOzJr1SU8hVEUQDzrVtAA= -git.milar.in/milarin/tprint v0.0.2 h1:K6Qh+3/9IGAJvywKsKKrALLAqIOg2eTr21ZJ6HT4+Ac= -git.milar.in/milarin/tprint v0.0.2/go.mod h1:KVwwKRggS88ZePLssFXMdisOzJr1SU8hVEUQDzrVtAA= -git.milar.in/milarin/tprint v0.0.3 h1:Pq5sG2nm0gDSbdg/uYmpFcFT26oEQBQ62eanV7/wHA0= -git.milar.in/milarin/tprint v0.0.3/go.mod h1:KVwwKRggS88ZePLssFXMdisOzJr1SU8hVEUQDzrVtAA= -git.milar.in/milarin/tprint v0.0.4 h1:SqDKABINQg7qYO/6XQbuydUJM4tEFMlUFMqnZNVAAmo= -git.milar.in/milarin/tprint v0.0.4/go.mod h1:KVwwKRggS88ZePLssFXMdisOzJr1SU8hVEUQDzrVtAA= -git.milar.in/milarin/tprint v0.0.5 h1:T4gszcFME+hW9bwTS/gCelFOwq7aZOX6qTngPiZor7c= -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/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/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/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-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-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= github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= -github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= 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= @@ -51,8 +42,6 @@ golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg= -golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24 h1:TyKJRhyo17yWxOMCTHKWrc5rddHORMlnZ/j57umaUd8= golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/local_file_check.go b/local_file_check.go index 9ed5f55..fdec8fd 100644 --- a/local_file_check.go +++ b/local_file_check.go @@ -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() diff --git a/show_debug_info.go b/show_debug_info.go index f71be54..d2c9d6b 100644 --- a/show_debug_info.go +++ b/show_debug_info.go @@ -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)) } } diff --git a/torrent_filter.go b/torrent_filter.go index 93933e5..14ea96b 100644 --- a/torrent_filter.go +++ b/torrent_filter.go @@ -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 { diff --git a/utils.go b/utils.go index eeac1c1..4ad4e42 100644 --- a/utils.go +++ b/utils.go @@ -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)