diff --git a/internal/universal/downloader.go b/internal/universal/downloader.go index 8cbdaff..2cc8da9 100644 --- a/internal/universal/downloader.go +++ b/internal/universal/downloader.go @@ -171,8 +171,10 @@ func (dl *Downloader) streamFileToResponse( // log.Errorf("Your account has reached the bandwidth limit, please try again after 12AM CET") http.Error(resp, "File is not available (bandwidth limit reached)", http.StatusBadRequest) return - } - if err != nil { + } else if utils.IsInvalidDownloadCode(err) { + http.Error(resp, "File is not available (invalid download code)", http.StatusInternalServerError) + return + } else if err != nil { log.Errorf("Cannot download file %s: %v", unrestrict.Download, err) if file != nil && file.State.Event(context.Background(), "break_file") == nil { torMgr.EnqueueForRepair(torrent) diff --git a/pkg/realdebrid/api.go b/pkg/realdebrid/api.go index 987b9e6..ca17062 100644 --- a/pkg/realdebrid/api.go +++ b/pkg/realdebrid/api.go @@ -81,8 +81,9 @@ func (rd *RealDebrid) UnrestrictAndVerify(link string) (*Download, error) { if utils.IsBytesLimitReached(err) { rd.TokenManager.SetTokenAsExpired(token, "bandwidth limit exceeded") continue - } - if err == nil { + } else if utils.IsInvalidDownloadCode(err) { + continue + } else if err == nil { rd.verifiedLinks.Set(download.ID, time.Now().Unix()+DOWNLOAD_LINK_EXPIRY) return download, nil } @@ -101,8 +102,9 @@ func (rd *RealDebrid) UnrestrictAndVerify(link string) (*Download, error) { if utils.IsBytesLimitReached(err) { rd.TokenManager.SetTokenAsExpired(token, "bandwidth limit exceeded") continue - } - if err != nil { + } else if utils.IsInvalidDownloadCode(err) { + continue + } else if err != nil { return nil, err } diff --git a/pkg/utils/bwlimit.go b/pkg/utils/bwlimit.go index c444318..c3e8b63 100644 --- a/pkg/utils/bwlimit.go +++ b/pkg/utils/bwlimit.go @@ -9,6 +9,13 @@ func IsBytesLimitReached(err error) bool { return false } +func IsInvalidDownloadCode(err error) bool { + if dlErr, ok := err.(*http.DownloadErrorResponse); ok && dlErr.Message == "invalid_download_code" { + return true + } + return false +} + func AreAllTokensExpired(err error) bool { return err != nil && err.Error() == "all tokens are expired" }