From 89104785d7f1fa947dab04d228117ce579f27ddc Mon Sep 17 00:00:00 2001 From: Simon Ding Date: Mon, 23 Sep 2024 23:12:06 +0800 Subject: [PATCH] fix: monitor lastest season --- server/core/importlist.go | 22 +++++++++++++++------- ui/lib/providers/welcome_data.dart | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/server/core/importlist.go b/server/core/importlist.go index a45b4351..a9684d00 100644 --- a/server/core/importlist.go +++ b/server/core/importlist.go @@ -133,14 +133,17 @@ func (c *Client) AddTv2Watchlist(in AddWatchlistIn) (interface{}, error) { } else { detail = detailEn } - log.Infof("find detail for tv id %d: %v", in.TmdbID, detail) + log.Infof("find detail for tv id %d: %+v", in.TmdbID, detail) - maxSeason := 0 + lastSeason := 0 for _, season := range detail.Seasons { - if season.SeasonNumber > maxSeason { - maxSeason = season.SeasonNumber + if season.SeasonNumber > lastSeason && season.EpisodeCount > 0 { //如果最新一季已经有剧集信息,则以最新一季为准 + lastSeason = season.SeasonNumber } } + + log.Debugf("latest season is %v", lastSeason) + var epIds []int for _, season := range detail.Seasons { seasonId := season.SeasonNumber @@ -149,8 +152,11 @@ func (c *Client) AddTv2Watchlist(in AddWatchlistIn) (interface{}, error) { log.Errorf("get season detail (%s) error: %v", detail.Name, err) continue } + + shouldMonitor := seasonId >= lastSeason //监控最新的一季 + for _, ep := range se.Episodes { - shouldMonitor := season.SeasonNumber >= maxSeason //监控最新的一季 + // //如果设置下载往期剧集,则监控所有剧集。如果没有则监控未上映的剧集,考虑时差等问题留24h余量 // if in.DownloadHistoryEpisodes { // shouldMonitor = true @@ -167,18 +173,20 @@ func (c *Client) AddTv2Watchlist(in AddWatchlistIn) (interface{}, error) { // } // } - epid, err := c.db.SaveEposideDetail(&ent.Episode{ + ep := ent.Episode{ SeasonNumber: seasonId, EpisodeNumber: ep.EpisodeNumber, Title: ep.Name, Overview: ep.Overview, AirDate: ep.AirDate, Monitored: shouldMonitor, - }) + } + epid, err := c.db.SaveEposideDetail(&ep) if err != nil { log.Errorf("save episode info error: %v", err) continue } + log.Debugf("success save episode %+v", ep) epIds = append(epIds, epid) } } diff --git a/ui/lib/providers/welcome_data.dart b/ui/lib/providers/welcome_data.dart index 6f27a708..5c21a85a 100644 --- a/ui/lib/providers/welcome_data.dart +++ b/ui/lib/providers/welcome_data.dart @@ -115,7 +115,7 @@ class SearchPageData if (sp.code != 0) { throw sp.message; } - ref.invalidate(tvWatchlistDataProvider); + //ref.invalidate(tvWatchlistDataProvider); } else { var resp = await dio.post(APIs.watchlistMovieUrl, data: { "tmdb_id": tmdbId,