diff --git a/anime_episode_cache.go b/anime_episode_cache.go new file mode 100644 index 0000000..c633e14 --- /dev/null +++ b/anime_episode_cache.go @@ -0,0 +1,23 @@ +package main + +import ( + "git.milar.in/milarin/anilist" + "git.milar.in/nyaanime/model" +) + +var AnimeEpisodeCache = map[anilist.MediaID]map[int]model.AnimeEpisode{} + +func GetAnimeEpisode(anime *anilist.Media, episode int) model.AnimeEpisode { + if _, ok := AnimeEpisodeCache[anime.ID]; !ok { + AnimeEpisodeCache[anime.ID] = map[int]model.AnimeEpisode{} + } + + if _, ok := AnimeEpisodeCache[anime.ID][episode]; !ok { + AnimeEpisodeCache[anime.ID][episode] = model.AnimeEpisode{ + Anime: anime, + Episode: episode, + } + } + + return AnimeEpisodeCache[anime.ID][episode] +} diff --git a/nyaa.go b/get_torrents.go similarity index 99% rename from nyaa.go rename to get_torrents.go index 587bb9c..3abf3d2 100644 --- a/nyaa.go +++ b/get_torrents.go @@ -58,7 +58,6 @@ func GetTorrents() ([]model.Torrent, error) { // goquery can't parse the link tag for some reason // therefore I have to get around this bug by exploiting regex - matches := torrentLinkRegex.FindStringSubmatch(s.Text()) link := matches[0] id := matches[1] diff --git a/go.mod b/go.mod index 0a28bf2..1503b3a 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( git.milar.in/milarin/slices v0.0.6 git.milar.in/milarin/tprint v0.0.7 git.milar.in/nyaanime/logic v0.0.0-20230115215841-53bbded00fe6 - git.milar.in/nyaanime/model v0.0.0-20230115221845-51c282652aef + git.milar.in/nyaanime/model v0.0.0-20230117081612-d3fc649dad67 git.milar.in/nyaanime/parsers v0.0.0-20230115232356-54a23b868d71 github.com/PuerkitoBio/goquery v1.8.0 github.com/fatih/color v1.13.0 diff --git a/go.sum b/go.sum index bd6616c..b4f5ed2 100644 --- a/go.sum +++ b/go.sum @@ -16,6 +16,10 @@ git.milar.in/nyaanime/logic v0.0.0-20230115215841-53bbded00fe6 h1:6GmcKt0TaHxATG git.milar.in/nyaanime/logic v0.0.0-20230115215841-53bbded00fe6/go.mod h1:cLuIBDTtpXdzprOIsz73r6ZCE5s0k+o6HA7fH9OuW/M= git.milar.in/nyaanime/model v0.0.0-20230115221845-51c282652aef h1:Bp1cMHgGnz5SAVWSL1hk1w7F75LGAkfwHqoTZnNQNbY= git.milar.in/nyaanime/model v0.0.0-20230115221845-51c282652aef/go.mod h1:kPWLDvFrhc1Uf77gxsBOxNeJ5JTVF2HhVs1IdVcw0tg= +git.milar.in/nyaanime/model v0.0.0-20230117081410-7701a09a0de0 h1:70QTQYoF3OYkJur6gCygb9D+2awYv2gNjWdWMCl/8FU= +git.milar.in/nyaanime/model v0.0.0-20230117081410-7701a09a0de0/go.mod h1:kPWLDvFrhc1Uf77gxsBOxNeJ5JTVF2HhVs1IdVcw0tg= +git.milar.in/nyaanime/model v0.0.0-20230117081612-d3fc649dad67 h1:p69LqaWzN/2zsgw45tR1XbFxyayu9ffVlikiKE2ibRw= +git.milar.in/nyaanime/model v0.0.0-20230117081612-d3fc649dad67/go.mod h1:kPWLDvFrhc1Uf77gxsBOxNeJ5JTVF2HhVs1IdVcw0tg= git.milar.in/nyaanime/parsers v0.0.0-20230115231942-89b759a7829f h1:xJiFxbLRKyb+43Yfv3UaZO1GiRGAsakebz6mHKUaRdI= git.milar.in/nyaanime/parsers v0.0.0-20230115231942-89b759a7829f/go.mod h1:fqiJqSWxh1YVJkKhvQql/21HmQzv4elhC3SpH/2TybI= git.milar.in/nyaanime/parsers v0.0.0-20230115232356-54a23b868d71 h1:BwWlk7UuQ/Ii97/XUVijujH4nkYJwZ0dHpghQ04hQeo= diff --git a/torrent_parse.go b/torrent_parse.go index e2b384b..dc75ed8 100644 --- a/torrent_parse.go +++ b/torrent_parse.go @@ -42,12 +42,8 @@ func ParseTorrentsByAnimeEp(torrents []model.Torrent) map[model.AnimeEpisode][]* continue } - animeEpisode := model.AnimeEpisode{ - Anime: parsedTorrent.Anime, - Episode: parsedTorrent.Episode, - } - - torrentsByAnimeEp[animeEpisode] = append(torrentsByAnimeEp[animeEpisode], parsedTorrent) + animeEp := GetAnimeEpisode(parsedTorrent.Anime, parsedTorrent.Episode) + torrentsByAnimeEp[animeEp] = append(torrentsByAnimeEp[animeEp], parsedTorrent) } return torrentsByAnimeEp