check anime episode on hard drive
This commit is contained in:
parent
0b53777f39
commit
820d45d80d
40
anime_episode_filepath.go
Normal file
40
anime_episode_filepath.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"git.milar.in/milarin/anilist"
|
||||||
|
"git.milar.in/nyaanime/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AnimePathPatternData struct {
|
||||||
|
Title anilist.MediaTitle
|
||||||
|
Episode int
|
||||||
|
Ext string
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAnimeEpFilepath(animeEp model.AnimeEpisode, ext string) string {
|
||||||
|
tmplData := AnimePathPatternData{
|
||||||
|
Title: animeEp.Anime.Title,
|
||||||
|
Episode: animeEp.Episode,
|
||||||
|
Ext: ext,
|
||||||
|
}
|
||||||
|
|
||||||
|
b := new(strings.Builder)
|
||||||
|
if err := AnimeEpFilepathPattern.Execute(b, tmplData); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return b.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func AnimeEpExistsLocally(animeEp model.AnimeEpisode) bool {
|
||||||
|
animeEpPath := filepath.Join(AnimePath, GetAnimeEpFilepath(animeEp, "*"))
|
||||||
|
|
||||||
|
files, err := filepath.Glob(animeEpPath)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return len(files) > 0
|
||||||
|
}
|
2
go.mod
2
go.mod
@ -9,7 +9,7 @@ require (
|
|||||||
git.milar.in/milarin/envvars v1.0.3
|
git.milar.in/milarin/envvars v1.0.3
|
||||||
git.milar.in/milarin/gmath v0.0.2
|
git.milar.in/milarin/gmath v0.0.2
|
||||||
git.milar.in/milarin/slices v0.0.2
|
git.milar.in/milarin/slices v0.0.2
|
||||||
git.milar.in/nyaanime/model v0.0.0-20220821124037-0a28c6b41556
|
git.milar.in/nyaanime/model v0.0.0-20220821215714-9959e681573f
|
||||||
git.milar.in/nyaanime/parsers v0.0.0-20220815144327-52de61265e27
|
git.milar.in/nyaanime/parsers v0.0.0-20220815144327-52de61265e27
|
||||||
github.com/PuerkitoBio/goquery v1.8.0
|
github.com/PuerkitoBio/goquery v1.8.0
|
||||||
)
|
)
|
||||||
|
6
go.sum
6
go.sum
@ -12,6 +12,12 @@ git.milar.in/milarin/slices v0.0.2 h1:j92MuP0HWKSaHJMq/FRxDtSDIGiOTvw+KogUTwuulr
|
|||||||
git.milar.in/milarin/slices v0.0.2/go.mod h1:XRNfE99aNKeaPOY1phjOlpIQqeGCW1LOqqh8UHS+vAk=
|
git.milar.in/milarin/slices v0.0.2/go.mod h1:XRNfE99aNKeaPOY1phjOlpIQqeGCW1LOqqh8UHS+vAk=
|
||||||
git.milar.in/nyaanime/model v0.0.0-20220821124037-0a28c6b41556 h1:RplYz4+CMK9ByI3ELusBltWFRlDs6VMOGk5EyENnLi0=
|
git.milar.in/nyaanime/model v0.0.0-20220821124037-0a28c6b41556 h1:RplYz4+CMK9ByI3ELusBltWFRlDs6VMOGk5EyENnLi0=
|
||||||
git.milar.in/nyaanime/model v0.0.0-20220821124037-0a28c6b41556/go.mod h1:OzhQgj0b/Hf9fg8VXYxYt8ONQOvHm8xC44TmS9kQ150=
|
git.milar.in/nyaanime/model v0.0.0-20220821124037-0a28c6b41556/go.mod h1:OzhQgj0b/Hf9fg8VXYxYt8ONQOvHm8xC44TmS9kQ150=
|
||||||
|
git.milar.in/nyaanime/model v0.0.0-20220821212334-5e9f052f86b6 h1:vmc1G5uVkYAYJYcaQKLrr+JE6u2780YR6R00EdF5A5I=
|
||||||
|
git.milar.in/nyaanime/model v0.0.0-20220821212334-5e9f052f86b6/go.mod h1:OzhQgj0b/Hf9fg8VXYxYt8ONQOvHm8xC44TmS9kQ150=
|
||||||
|
git.milar.in/nyaanime/model v0.0.0-20220821212807-44de43f4c500 h1:zwYRzcbRiS62hDu6hy4OGxMbhLnTsL13VEXNIoTodsk=
|
||||||
|
git.milar.in/nyaanime/model v0.0.0-20220821212807-44de43f4c500/go.mod h1:OzhQgj0b/Hf9fg8VXYxYt8ONQOvHm8xC44TmS9kQ150=
|
||||||
|
git.milar.in/nyaanime/model v0.0.0-20220821215714-9959e681573f h1:BKxr1hWCl2QfSiOis1NaRcoG1mZlwo5VnB+0mYhmfEw=
|
||||||
|
git.milar.in/nyaanime/model v0.0.0-20220821215714-9959e681573f/go.mod h1:OzhQgj0b/Hf9fg8VXYxYt8ONQOvHm8xC44TmS9kQ150=
|
||||||
git.milar.in/nyaanime/parsers v0.0.0-20220815144327-52de61265e27 h1:0+5j9MMJQS8+Luss19hD6hvNFxcBDRal2XwSUTyq7WU=
|
git.milar.in/nyaanime/parsers v0.0.0-20220815144327-52de61265e27 h1:0+5j9MMJQS8+Luss19hD6hvNFxcBDRal2XwSUTyq7WU=
|
||||||
git.milar.in/nyaanime/parsers v0.0.0-20220815144327-52de61265e27/go.mod h1:qm6fIFBFs90uz7IJ8RKgDir0K8Fa8isixGLgrtC6kgU=
|
git.milar.in/nyaanime/parsers v0.0.0-20220815144327-52de61265e27/go.mod h1:qm6fIFBFs90uz7IJ8RKgDir0K8Fa8isixGLgrtC6kgU=
|
||||||
github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U=
|
github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U=
|
||||||
|
36
main.go
36
main.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -21,6 +22,15 @@ var (
|
|||||||
StorageUser = envvars.String("STORAGE_USER", "")
|
StorageUser = envvars.String("STORAGE_USER", "")
|
||||||
StoragePass = envvars.String("STORAGE_PASS", "")
|
StoragePass = envvars.String("STORAGE_PASS", "")
|
||||||
|
|
||||||
|
DownloadPath = envvars.String("DOWNLOAD_PATH", "")
|
||||||
|
AnimePath = envvars.String("ANIME_PATH", "")
|
||||||
|
|
||||||
|
AnimeEpFilepathPattern = envvars.Object(
|
||||||
|
"EPISODE_FILEPATH_PATTERN",
|
||||||
|
template.Must(template.New("anime-episode-filepath-pattern").Parse(`{{.Title.UserPreferred}}/{{.Title.UserPreferred}} Episode {{.Episode}}.{{.Ext}}`)),
|
||||||
|
template.New("anime-episode-filepath-pattern").Parse,
|
||||||
|
)
|
||||||
|
|
||||||
AnimeStatus = envvars.ObjectSlice("ANIME_STATUS", ",", ParseMediaListStatus)
|
AnimeStatus = envvars.ObjectSlice("ANIME_STATUS", ",", ParseMediaListStatus)
|
||||||
|
|
||||||
// essential torrent properties
|
// essential torrent properties
|
||||||
@ -92,20 +102,34 @@ func checkTorrents() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
/*animes, err = GetAnimesToDownloadByAnimeID()
|
animes, err := GetAnimesToDownloadByAnimeID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(adverr.Wrap("retrieving anime list failed", err))
|
fmt.Println(adverr.Wrap("retrieving anime list failed", err))
|
||||||
return
|
return
|
||||||
}*/
|
}
|
||||||
|
|
||||||
parsedTorrents := ParseTorrentsByAnimeEpSortedByProperties(torrents)
|
parsedTorrents := ParseTorrentsByAnimeEpSortedByProperties(torrents)
|
||||||
|
|
||||||
for animeEp, torrentPriorities := range parsedTorrents {
|
for animeEp, torrentPriorities := range parsedTorrents {
|
||||||
fmt.Printf("\nanime: %s | episode: %d | torrents found: %d\n", animeEp.Anime, animeEp.Episode, len(torrentPriorities))
|
fmt.Printf("\nanime: %s | episode: %d | torrents found: %d\n", animeEp.Anime.Title.Romaji, animeEp.Episode, len(torrentPriorities))
|
||||||
for _, torrentPriority := range torrentPriorities {
|
|
||||||
PrintTorrentPriority(torrentPriority)
|
|
||||||
|
|
||||||
// TODO download anime episode with highest priority (first on in slice)
|
for _, torrentPriority := range torrentPriorities {
|
||||||
|
/*animeListEntry*/ _, ok := animes[torrentPriority.ParsedTorrent.Anime.ID]
|
||||||
|
if !ok {
|
||||||
|
fmt.Printf("%s | NOT ON LIST\n", FormatTorrentPriority(torrentPriority))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if AnimeEpExistsLocally(animeEp) {
|
||||||
|
// TODO check if current torrent has higher priority than downloaded one (might not have any priority)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO is currently downloading? (database query)
|
||||||
|
|
||||||
|
fmt.Println(FormatTorrentPriority(torrentPriority))
|
||||||
|
|
||||||
|
// TODO download anime episode with highest priority (first one in slice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ func ParseTorrentsByAnimeEp(torrents []model.Torrent) map[model.AnimeEpisode][]*
|
|||||||
}
|
}
|
||||||
|
|
||||||
animeEpisode := model.AnimeEpisode{
|
animeEpisode := model.AnimeEpisode{
|
||||||
Anime: parsedTorrent.Anime.Title.Native,
|
Anime: parsedTorrent.Anime,
|
||||||
Episode: parsedTorrent.Episode,
|
Episode: parsedTorrent.Episode,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
utils.go
4
utils.go
@ -43,8 +43,8 @@ func Map2Str[K comparable, T any](m map[K]T) string {
|
|||||||
return str[:len(str)-1]
|
return str[:len(str)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintTorrentPriority(torrentPriority *TorrentPriority) {
|
func FormatTorrentPriority(torrentPriority *TorrentPriority) string {
|
||||||
fmt.Printf("id: %s | resolution: %d | languages: %s | subtitles: %s | seeders: %d | leechers: %d, | downloads: %d | trusted: %t | preferred properties: %s | priority: %d\n",
|
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.Torrent.ID,
|
||||||
torrentPriority.ParsedTorrent.Resolution,
|
torrentPriority.ParsedTorrent.Resolution,
|
||||||
strings.Join(torrentPriority.ParsedTorrent.Languages, ","),
|
strings.Join(torrentPriority.ParsedTorrent.Languages, ","),
|
||||||
|
Loading…
Reference in New Issue
Block a user