fix: download series all

This commit is contained in:
Simon Ding
2024-08-12 18:13:34 +08:00
parent 0cce4ffee0
commit 57ec0b9eb9
3 changed files with 16 additions and 11 deletions

View File

@@ -206,7 +206,7 @@ type Task struct {
pkg.Torrent pkg.Torrent
} }
func (c *Client) DownloadSeriesAllEpisodes(id int) ([]string, error) { func (c *Client) DownloadSeriesAllEpisodes(id int) []string {
tvDetail := c.db.GetMediaDetails(id) tvDetail := c.db.GetMediaDetails(id)
m := make(map[int][]*ent.Episode) m := make(map[int][]*ent.Episode)
for _, ep := range tvDetail.Episodes { for _, ep := range tvDetail.Episodes {
@@ -214,6 +214,9 @@ func (c *Client) DownloadSeriesAllEpisodes(id int) ([]string, error) {
} }
var allNames []string var allNames []string
for seasonNum, epsides := range m { for seasonNum, epsides := range m {
if seasonNum == 0 {
continue
}
wantedSeasonPack := true wantedSeasonPack := true
for _, ep := range epsides { for _, ep := range epsides {
if !ep.Monitored { if !ep.Monitored {
@@ -225,14 +228,16 @@ func (c *Client) DownloadSeriesAllEpisodes(id int) ([]string, error) {
} }
if wantedSeasonPack { if wantedSeasonPack {
name, err := c.SearchAndDownload(id, seasonNum, -1) name, err := c.SearchAndDownload(id, seasonNum, -1)
if err != nil { if err == nil {
return nil, errors.Wrap(err, "find resource")
} else {
allNames = append(allNames, *name) allNames = append(allNames, *name)
log.Infof("begin download torrent resource: %v", name) log.Infof("begin download torrent resource: %v", name)
} else {
log.Warnf("finding season pack error: %v", err)
wantedSeasonPack = false
} }
} else { }
if !wantedSeasonPack {
for _, ep := range epsides { for _, ep := range epsides {
if !ep.Monitored { if !ep.Monitored {
continue continue
@@ -242,7 +247,8 @@ func (c *Client) DownloadSeriesAllEpisodes(id int) ([]string, error) {
} }
name, err := c.SearchAndDownload(id, ep.SeasonNumber, ep.EpisodeNumber) name, err := c.SearchAndDownload(id, ep.SeasonNumber, ep.EpisodeNumber)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "find resource to download") log.Warnf("finding resoruces of season %d episode %d error: %v", ep.SeasonNumber, ep.EpisodeNumber, err)
continue
} else { } else {
allNames = append(allNames, *name) allNames = append(allNames, *name)
log.Infof("begin download torrent resource: %v", name) log.Infof("begin download torrent resource: %v", name)
@@ -252,16 +258,14 @@ func (c *Client) DownloadSeriesAllEpisodes(id int) ([]string, error) {
} }
} }
return allNames, nil return allNames
} }
func (c *Client) downloadAllTvSeries() { func (c *Client) downloadAllTvSeries() {
log.Infof("begin check all tv series resources") log.Infof("begin check all tv series resources")
allSeries := c.db.GetMediaWatchlist(media.MediaTypeTv) allSeries := c.db.GetMediaWatchlist(media.MediaTypeTv)
for _, series := range allSeries { for _, series := range allSeries {
if _, err := c.DownloadSeriesAllEpisodes(series.ID); err != nil { c.DownloadSeriesAllEpisodes(series.ID)
return
}
} }
} }

View File

@@ -180,7 +180,7 @@ func (s *Server) DownloadAll(c *gin.Context) (interface{}, error) {
return nil, errors.Wrap(err, "get media") return nil, errors.Wrap(err, "get media")
} }
if m.MediaType == media.MediaTypeTv { if m.MediaType == media.MediaTypeTv {
return s.core.DownloadSeriesAllEpisodes(m.ID) return s.core.DownloadSeriesAllEpisodes(m.ID), nil
} }
name, err := s.core.DownloadMovieByID(m.ID) name, err := s.core.DownloadMovieByID(m.ID)

View File

@@ -190,6 +190,7 @@ class _MainSkeletonState extends State<MainSkeleton> {
onPressed: () => context.go(WelcomePage.routeTv), onPressed: () => context.go(WelcomePage.routeTv),
child: Text( child: Text(
"Polaris", "Polaris",
overflow: TextOverflow.clip,
style: TextStyle(fontSize: 28), style: TextStyle(fontSize: 28),
), ),
), ),