fixed map indexing for anime episodes

This commit is contained in:
milarin 2023-01-17 09:25:03 +01:00
parent 6adf6f276d
commit a541267c20
5 changed files with 30 additions and 8 deletions

23
anime_episode_cache.go Normal file
View File

@ -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]
}

View File

@ -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]

2
go.mod
View File

@ -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

4
go.sum
View File

@ -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=

View File

@ -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