feat: default monitor lastest season all episodes

This commit is contained in:
Simon Ding
2024-09-20 11:03:01 +08:00
parent 4f3e3e399d
commit f696b78260

View File

@@ -16,7 +16,6 @@ import (
"polaris/pkg/utils" "polaris/pkg/utils"
"regexp" "regexp"
"strings" "strings"
"time"
tmdb "github.com/cyruzin/golang-tmdb" tmdb "github.com/cyruzin/golang-tmdb"
"github.com/pkg/errors" "github.com/pkg/errors"
@@ -134,6 +133,12 @@ func (c *Client) AddTv2Watchlist(in AddWatchlistIn) (interface{}, error) {
} }
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
for _, season := range detail.Seasons {
if season.SeasonNumber > maxSeason {
maxSeason = season.SeasonNumber
}
}
var epIds []int var epIds []int
for _, season := range detail.Seasons { for _, season := range detail.Seasons {
seasonId := season.SeasonNumber seasonId := season.SeasonNumber
@@ -143,22 +148,22 @@ func (c *Client) AddTv2Watchlist(in AddWatchlistIn) (interface{}, error) {
continue continue
} }
for _, ep := range se.Episodes { for _, ep := range se.Episodes {
shouldMonitor := false shouldMonitor := season.SeasonNumber >= maxSeason //监控最新的一季
//如果设置下载往期剧集则监控所有剧集。如果没有则监控未上映的剧集考虑时差等问题留24h余量 // //如果设置下载往期剧集则监控所有剧集。如果没有则监控未上映的剧集考虑时差等问题留24h余量
if in.DownloadHistoryEpisodes { // if in.DownloadHistoryEpisodes {
shouldMonitor = true // shouldMonitor = true
} else { // } else {
t, err := time.Parse("2006-01-02", ep.AirDate) // t, err := time.Parse("2006-01-02", ep.AirDate)
if err != nil { // if err != nil {
log.Error("air date not known, will monitor: %v", ep.AirDate) // log.Error("air date not known, will monitor: %v", ep.AirDate)
shouldMonitor = true // shouldMonitor = true
} else { // } else {
if time.Since(t) < 24*time.Hour { //monitor episode air 24h before now // if time.Since(t) < 24*time.Hour { //monitor episode air 24h before now
shouldMonitor = true // shouldMonitor = true
} // }
} // }
} // }
epid, err := c.db.SaveEposideDetail(&ent.Episode{ epid, err := c.db.SaveEposideDetail(&ent.Episode{
SeasonNumber: seasonId, SeasonNumber: seasonId,