Updated episode refresh

This commit is contained in:
Eduard Urbach 2019-08-28 18:37:09 +09:00
parent 384ec41bbf
commit cdfb66657a
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
2 changed files with 9 additions and 5 deletions

View File

@ -403,7 +403,7 @@ func (anime *Anime) RefreshEpisodes() error {
return err
}
episodes.Merge(shoboiEpisodes)
episodes = episodes.Merge(shoboiEpisodes)
// AnimeTwist
twistEpisodes, err := anime.TwistEpisodes()
@ -412,7 +412,7 @@ func (anime *Anime) RefreshEpisodes() error {
return err
}
episodes.Merge(twistEpisodes)
episodes = episodes.Merge(twistEpisodes)
// Count number of available episodes
newAvailableCount := episodes.AvailableCount()
@ -487,8 +487,10 @@ func (anime *Anime) RefreshEpisodes() error {
// Save new episode ID list
episodeIDs := make([]string, len(episodes))
for index := range episodes {
episodeIDs[index] = episodes[index].ID
for index, episode := range episodes {
episodeIDs[index] = episode.ID
episode.AnimeID = anime.ID
episode.Save()
}
anime.EpisodeIDs = episodeIDs

View File

@ -28,7 +28,7 @@ func (episodes EpisodeList) Find(episodeNumber int) (*Episode, int) {
}
// Merge combines the data of both episode lists to one.
func (episodes EpisodeList) Merge(b EpisodeList) {
func (episodes EpisodeList) Merge(b EpisodeList) EpisodeList {
for index, episode := range b {
if index >= len(episodes) {
episodes = append(episodes, episode)
@ -36,6 +36,8 @@ func (episodes EpisodeList) Merge(b EpisodeList) {
episodes[index].Merge(episode)
}
}
return episodes
}
// HumanReadable returns a text representation of the anime episodes.