mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-10 03:57:39 +08:00
feat: find season pack first
This commit is contained in:
@@ -80,11 +80,14 @@ func (c *Client) DownloadEpisodeTorrent(r1 torznab.Result, seriesId, seasonNum,
|
|||||||
|
|
||||||
}
|
}
|
||||||
func (c *Client) SearchAndDownload(seriesId, seasonNum, episodeNum int) (*string, error) {
|
func (c *Client) SearchAndDownload(seriesId, seasonNum, episodeNum int) (*string, error) {
|
||||||
|
var episodes []int
|
||||||
|
if episodeNum > 0 {
|
||||||
|
episodes = append(episodes, episodeNum)
|
||||||
|
}
|
||||||
res, err := SearchTvSeries(c.db, &SearchParam{
|
res, err := SearchTvSeries(c.db, &SearchParam{
|
||||||
MediaId: seriesId,
|
MediaId: seriesId,
|
||||||
SeasonNum: seasonNum,
|
SeasonNum: seasonNum,
|
||||||
Episodes: []int{episodeNum},
|
Episodes: episodes,
|
||||||
CheckFileSize: true,
|
CheckFileSize: true,
|
||||||
CheckResolution: true,
|
CheckResolution: true,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -207,23 +207,46 @@ func (c *Client) downloadTvSeries() {
|
|||||||
allSeries := c.db.GetMediaWatchlist(media.MediaTypeTv)
|
allSeries := c.db.GetMediaWatchlist(media.MediaTypeTv)
|
||||||
for _, series := range allSeries {
|
for _, series := range allSeries {
|
||||||
tvDetail := c.db.GetMediaDetails(series.ID)
|
tvDetail := c.db.GetMediaDetails(series.ID)
|
||||||
|
m := make(map[int][]*ent.Episode)
|
||||||
for _, ep := range tvDetail.Episodes {
|
for _, ep := range tvDetail.Episodes {
|
||||||
if !ep.Monitored { //未监控的剧集不去下载
|
m[ep.SeasonNumber] = append(m[ep.SeasonNumber], ep)
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if ep.Status != episode.StatusMissing { //已经下载的不去下载
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
name, err := c.SearchAndDownload(series.ID, ep.SeasonNumber, ep.EpisodeNumber)
|
|
||||||
if err != nil {
|
|
||||||
log.Infof("cannot find resource to download for %s: %v", ep.Title, err)
|
|
||||||
} else {
|
|
||||||
log.Infof("begin download torrent resource: %v", name)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
for seasonNum, epsides := range m {
|
||||||
|
wantedSeasonPack := true
|
||||||
|
for _, ep := range epsides {
|
||||||
|
if !ep.Monitored {
|
||||||
|
wantedSeasonPack = false
|
||||||
|
}
|
||||||
|
if ep.Status != episode.StatusMissing {
|
||||||
|
wantedSeasonPack = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if wantedSeasonPack {
|
||||||
|
name, err := c.SearchAndDownload(series.ID, seasonNum, -1)
|
||||||
|
if err != nil {
|
||||||
|
log.Infof("cannot find resource to download : %v", err)
|
||||||
|
} else {
|
||||||
|
log.Infof("begin download torrent resource: %v", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
for _, ep := range epsides {
|
||||||
|
if !ep.Monitored {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if ep.Status != episode.StatusMissing {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
name, err := c.SearchAndDownload(series.ID, ep.SeasonNumber, ep.EpisodeNumber)
|
||||||
|
if err != nil {
|
||||||
|
log.Infof("cannot find resource to download for %s: %v", ep.Title, err)
|
||||||
|
} else {
|
||||||
|
log.Infof("begin download torrent resource: %v", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user