mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-09 11:39:46 +08:00
feat: change method to monitor episodes
This commit is contained in:
@@ -112,7 +112,7 @@ func (c *Client) DownloadEpisodeTorrent(r1 torznab.Result, seriesId, seasonNum,
|
||||
}
|
||||
func (c *Client) SearchAndDownload(seriesId, seasonNum, episodeNum int) (*string, error) {
|
||||
|
||||
res, err := SearchEpisode(c.db, seriesId, seasonNum, episodeNum, true)
|
||||
res, err := SearchTvSeries(c.db, seriesId, seasonNum, []int{episodeNum}, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"polaris/pkg"
|
||||
"polaris/pkg/notifier/message"
|
||||
"polaris/pkg/utils"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@@ -140,7 +139,7 @@ func (c *Client) moveCompletedTask(id int) (err1 error) {
|
||||
c.sendMsg(fmt.Sprintf(message.ProcessingComplete, torrentName))
|
||||
|
||||
//判断是否需要删除本地文件
|
||||
ok, err := c.isSeedRatioLimitReached(r.IndexerID, torrent)
|
||||
ok, err := c.isSeedRatioLimitReached(r.IndexerID, torrent)
|
||||
if err != nil {
|
||||
log.Warnf("getting torrent seed ratio %s: %v", torrent.Name(), err)
|
||||
ok = false
|
||||
@@ -217,15 +216,8 @@ func (c *Client) downloadTvSeries() {
|
||||
for _, series := range allSeries {
|
||||
tvDetail := c.db.GetMediaDetails(series.ID)
|
||||
for _, ep := range tvDetail.Episodes {
|
||||
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.Monitored { //未监控的剧集不去下载
|
||||
continue
|
||||
}
|
||||
|
||||
if ep.Status != episode.StatusMissing { //已经下载的不去下载
|
||||
@@ -338,6 +330,7 @@ func (c *Client) checkSeiesNewSeason(media *ent.Media) error {
|
||||
Overview: ep.Overview,
|
||||
AirDate: ep.AirDate,
|
||||
Status: episode.StatusMissing,
|
||||
Monitored: true,
|
||||
}
|
||||
c.db.SaveEposideDetail2(episode)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"polaris/pkg/metadata"
|
||||
"polaris/pkg/torznab"
|
||||
"polaris/pkg/utils"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -15,30 +16,12 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func SearchSeasonPackage(db1 *db.Client, seriesId, seasonNum int, checkResolution bool) ([]torznab.Result, error) {
|
||||
return SearchEpisode(db1, seriesId, seasonNum, -1, checkResolution)
|
||||
}
|
||||
|
||||
func isNumberedSeries(detail *db.MediaDetails) bool {
|
||||
hasSeason2 := false
|
||||
season2HasEpisode1 := false
|
||||
for _, ep := range detail.Episodes {
|
||||
if ep.SeasonNumber == 2 {
|
||||
hasSeason2 = true
|
||||
if ep.EpisodeNumber == 1 {
|
||||
season2HasEpisode1 = true
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return hasSeason2 && !season2HasEpisode1 //only one 1st episode
|
||||
}
|
||||
|
||||
func SearchEpisode(db1 *db.Client, seriesId, seasonNum, episodeNum int, checkResolution bool) ([]torznab.Result, error) {
|
||||
func SearchTvSeries(db1 *db.Client, seriesId, seasonNum int, episodes []int, checkResolution bool) ([]torznab.Result, error) {
|
||||
series := db1.GetMediaDetails(seriesId)
|
||||
if series == nil {
|
||||
return nil, fmt.Errorf("no tv series of id %v", seriesId)
|
||||
}
|
||||
slices.Contains(episodes, 1)
|
||||
|
||||
res := searchWithTorznab(db1, series.NameEn)
|
||||
resCn := searchWithTorznab(db1, series.NameCn)
|
||||
@@ -56,14 +39,14 @@ func SearchEpisode(db1 *db.Client, seriesId, seasonNum, episodeNum int, checkRes
|
||||
continue
|
||||
}
|
||||
}
|
||||
if isNumberedSeries(series) && episodeNum == -1 {
|
||||
if isNumberedSeries(series) && len(episodes) == 0 {
|
||||
//should not want season
|
||||
continue
|
||||
}
|
||||
|
||||
if episodeNum != -1 && meta.Episode != episodeNum { //not season pack, episode number equals
|
||||
if len(episodes) > 0 && slices.Contains(episodes, meta.Episode) { //not season pack, episode number equals
|
||||
continue
|
||||
}else if episodeNum == -1 && !meta.IsSeasonPack { //want season pack, but not season pack
|
||||
}else if len(episodes) == 0 && !meta.IsSeasonPack { //want season pack, but not season pack
|
||||
continue
|
||||
}
|
||||
if checkResolution && meta.Resolution != series.Resolution.String() {
|
||||
@@ -82,6 +65,21 @@ func SearchEpisode(db1 *db.Client, seriesId, seasonNum, episodeNum int, checkRes
|
||||
|
||||
}
|
||||
|
||||
func isNumberedSeries(detail *db.MediaDetails) bool {
|
||||
hasSeason2 := false
|
||||
season2HasEpisode1 := false
|
||||
for _, ep := range detail.Episodes {
|
||||
if ep.SeasonNumber == 2 {
|
||||
hasSeason2 = true
|
||||
if ep.EpisodeNumber == 1 {
|
||||
season2HasEpisode1 = true
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return hasSeason2 && !season2HasEpisode1 //only one 1st episode
|
||||
}
|
||||
|
||||
func SearchMovie(db1 *db.Client, movieId int, checkResolution bool) ([]torznab.Result, error) {
|
||||
movieDetail := db1.GetMediaDetails(movieId)
|
||||
if movieDetail == nil {
|
||||
|
||||
Reference in New Issue
Block a user