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

@@ -84,8 +84,8 @@ lo:
if len(episodeNums) == 0 { //want season pack if len(episodeNums) == 0 { //want season pack
if m.IsSeasonPack { if m.IsSeasonPack {
name, err := c.DownloadEpisodeTorrent(r, DownloadOptions{ name, err := c.DownloadEpisodeTorrent(r, DownloadOptions{
SeasonNum: seasonNum, SeasonNum: seasonNum,
MediaId: seriesId, MediaId: seriesId,
HashFilterFn: c.hashInBlacklist, HashFilterFn: c.hashInBlacklist,
}) })
if err != nil { if err != nil {
@@ -104,9 +104,9 @@ lo:
torrentEpisodes = append(torrentEpisodes, i) torrentEpisodes = append(torrentEpisodes, i)
} }
name, err := c.DownloadEpisodeTorrent(r, DownloadOptions{ name, err := c.DownloadEpisodeTorrent(r, DownloadOptions{
SeasonNum: seasonNum, SeasonNum: seasonNum,
MediaId: seriesId, MediaId: seriesId,
EpisodeNums: torrentEpisodes, EpisodeNums: torrentEpisodes,
HashFilterFn: c.hashInBlacklist, HashFilterFn: c.hashInBlacklist,
}) })
if err != nil { if err != nil {
@@ -135,7 +135,7 @@ func (c *Engine) DownloadMovie(m *ent.Media, r1 torznab.Result) (*string, error)
func (c *Engine) hashInBlacklist(hash string) bool { func (c *Engine) hashInBlacklist(hash string) bool {
blacklist, err := c.db.GetTorrentBlacklist() blacklist, err := c.db.GetTorrentBlacklist()
if err!= nil { if err != nil {
log.Warnf("get torrent blacklist error: %v", err) log.Warnf("get torrent blacklist error: %v", err)
return false return false
} }
@@ -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)
} }
} }