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 return err
} }
episodes.Merge(shoboiEpisodes) episodes = episodes.Merge(shoboiEpisodes)
// AnimeTwist // AnimeTwist
twistEpisodes, err := anime.TwistEpisodes() twistEpisodes, err := anime.TwistEpisodes()
@ -412,7 +412,7 @@ func (anime *Anime) RefreshEpisodes() error {
return err return err
} }
episodes.Merge(twistEpisodes) episodes = episodes.Merge(twistEpisodes)
// Count number of available episodes // Count number of available episodes
newAvailableCount := episodes.AvailableCount() newAvailableCount := episodes.AvailableCount()
@ -487,8 +487,10 @@ func (anime *Anime) RefreshEpisodes() error {
// Save new episode ID list // Save new episode ID list
episodeIDs := make([]string, len(episodes)) episodeIDs := make([]string, len(episodes))
for index := range episodes { for index, episode := range episodes {
episodeIDs[index] = episodes[index].ID episodeIDs[index] = episode.ID
episode.AnimeID = anime.ID
episode.Save()
} }
anime.EpisodeIDs = episodeIDs 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. // 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 { for index, episode := range b {
if index >= len(episodes) { if index >= len(episodes) {
episodes = append(episodes, episode) episodes = append(episodes, episode)
@ -36,6 +36,8 @@ func (episodes EpisodeList) Merge(b EpisodeList) {
episodes[index].Merge(episode) episodes[index].Merge(episode)
} }
} }
return episodes
} }
// HumanReadable returns a text representation of the anime episodes. // HumanReadable returns a text representation of the anime episodes.