feat: option to download all episodes

This commit is contained in:
Simon Ding
2024-07-28 13:22:12 +08:00
parent 34fa05e7dd
commit fc86a441f4
13 changed files with 280 additions and 44 deletions

View File

@@ -221,14 +221,17 @@ func (s *Server) downloadTvSeries() {
for _, series := range allSeries {
tvDetail := s.db.GetMediaDetails(series.ID)
for _, ep := range tvDetail.Episodes {
t, err := time.Parse("2006-01-02", ep.AirDate)
if err != nil {
log.Error("air date not known, skip: %v", ep.Title)
continue
}
if series.CreatedAt.Sub(t) > 24*time.Hour { //剧集在加入watchlist之前不去下载
continue
if !series.DownloadHistoryEpisodes { //设置不下载历史已播出剧集,只下载将来剧集
t, err := time.Parse("2006-01-02", ep.AirDate)
if err != nil {
log.Error("air date not known, skip: %v", ep.Title)
continue
}
if series.CreatedAt.Sub(t) > 24*time.Hour { //剧集在加入watchlist之前不去下载
continue
}
}
if ep.Status != episode.StatusMissing { //已经下载的不去下载
continue
}

View File

@@ -57,10 +57,11 @@ func (s *Server) SearchMedia(c *gin.Context) (interface{}, error) {
}
type addWatchlistIn struct {
TmdbID int `json:"tmdb_id" binding:"required"`
StorageID int `json:"storage_id" `
Resolution string `json:"resolution" binding:"required"`
Folder string `json:"folder"`
TmdbID int `json:"tmdb_id" binding:"required"`
StorageID int `json:"storage_id" `
Resolution string `json:"resolution" binding:"required"`
Folder string `json:"folder"`
DownloadHistoryEpisodes bool `json:"download_history_episodes"` //for tv
}
func (s *Server) AddTv2Watchlist(c *gin.Context) (interface{}, error) {
@@ -121,6 +122,7 @@ func (s *Server) AddTv2Watchlist(c *gin.Context) (interface{}, error) {
Resolution: media.Resolution(in.Resolution),
StorageID: in.StorageID,
TargetDir: in.Folder,
DownloadHistoryEpisodes: in.DownloadHistoryEpisodes,
}, epIds)
if err != nil {
return nil, errors.Wrap(err, "add to list")
@@ -273,7 +275,7 @@ func (s *Server) GetTvWatchlist(c *gin.Context) (interface{}, error) {
}
if ep.Status == episode.StatusMissing {
ms.Status = "monitoring"
}
}
}
}
res[i] = ms