fix: will restore episode status after download fail

This commit is contained in:
Simon Ding
2025-09-12 21:28:17 +08:00
parent 3519715212
commit 6a5cf9c484

View File

@@ -147,7 +147,7 @@ func (c *Engine) hashInBlacklist(hash string) bool {
return false return false
} }
func (c *Engine) downloadTorrent(m *ent.Media, r1 torznab.Result, op DownloadOptions) (*string, error) { func (c *Engine) downloadTorrent(m *ent.Media, r1 torznab.Result, op DownloadOptions) (s *string, err1 error) {
trc, dlc, err := c.GetDownloadClient() trc, dlc, err := c.GetDownloadClient()
if err != nil { if err != nil {
return nil, errors.Wrap(err, "get download client") return nil, errors.Wrap(err, "get download client")
@@ -176,6 +176,11 @@ func (c *Engine) downloadTorrent(m *ent.Media, r1 torznab.Result, op DownloadOpt
} }
if ep.Status == episode.StatusMissing { if ep.Status == episode.StatusMissing {
c.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading) c.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading)
defer func(episodeId int) {
if err1 != nil {
c.db.SetEpisodeStatus(episodeId, episode.StatusMissing)
}
}(ep.ID)
} }
} }
buff := &bytes.Buffer{} buff := &bytes.Buffer{}
@@ -191,12 +196,23 @@ func (c *Engine) downloadTorrent(m *ent.Media, r1 torznab.Result, op DownloadOpt
} else { //season package download } else { //season package download
name = fmt.Sprintf("全集 (%s)", name) name = fmt.Sprintf("全集 (%s)", name)
c.db.SetSeasonAllEpisodeStatus(m.ID, op.SeasonNum, episode.StatusDownloading) c.db.SetSeasonAllEpisodeStatus(m.ID, op.SeasonNum, episode.StatusDownloading)
defer func(mediaId int, seasonNum int) {
if err1 != nil {
c.db.SetSeasonAllEpisodeStatus(mediaId, seasonNum, episode.StatusMissing)
}
}(m.ID, op.SeasonNum)
} }
} else { //movie download } else { //movie download
ep, _ := c.db.GetMovieDummyEpisode(m.ID) ep, _ := c.db.GetMovieDummyEpisode(m.ID)
if ep.Status == episode.StatusMissing { if ep.Status == episode.StatusMissing {
c.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading) c.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading)
defer func(episodeId int) {
if err1 != nil {
c.db.SetEpisodeStatus(episodeId, episode.StatusMissing)
}
}(ep.ID)
} }
} }