Fix for invalid_download_code
This commit is contained in:
@@ -288,6 +288,26 @@ func (t *TorrentManager) readTorrentFromFile(filePath string) *Torrent {
|
|||||||
if torrent.Version != t.requiredVersion {
|
if torrent.Version != t.requiredVersion {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
|
if strings.HasPrefix(file.Link, "https://real-debrid.com/d/") {
|
||||||
|
// set link to max 39 chars (26 + 13)
|
||||||
|
file.Link = file.Link[0:39]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
unassignedLinks := mapset.NewSet[string]()
|
||||||
|
torrent.UnassignedLinks.Each(func(link string) bool {
|
||||||
|
if strings.HasPrefix(link, "https://real-debrid.com/d/") {
|
||||||
|
// set link to max 39 chars (26 + 13)
|
||||||
|
unassignedLinks.Add(link[0:39])
|
||||||
|
} else {
|
||||||
|
unassignedLinks.Add(link)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
torrent.UnassignedLinks = unassignedLinks
|
||||||
|
|
||||||
return torrent
|
return torrent
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,6 +362,9 @@ func (t *TorrentManager) readInfoFromFile(torrentID string) *realdebrid.TorrentI
|
|||||||
if err := json.Unmarshal(jsonData, &info); err != nil {
|
if err := json.Unmarshal(jsonData, &info); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if info.Progress != 100 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -180,6 +180,12 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *realdebrid.T
|
|||||||
}
|
}
|
||||||
t.writeInfoToFile(info)
|
t.writeInfoToFile(info)
|
||||||
}
|
}
|
||||||
|
for i := range info.Links {
|
||||||
|
if strings.HasPrefix(info.Links[i], "https://real-debrid.com/d/") {
|
||||||
|
// set link to max 39 chars (26 + 13)
|
||||||
|
info.Links[i] = info.Links[i][0:39]
|
||||||
|
}
|
||||||
|
}
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,9 +232,6 @@ func (t *TorrentManager) convertToTorrent(info *realdebrid.TorrentInfo) *Torrent
|
|||||||
// all links are still intact! good!
|
// all links are still intact! good!
|
||||||
for i, file := range selectedFiles {
|
for i, file := range selectedFiles {
|
||||||
file.Link = info.Links[i]
|
file.Link = info.Links[i]
|
||||||
if strings.HasPrefix(file.Link, "https://real-debrid.com/d/") {
|
|
||||||
file.Link = file.Link[0:39]
|
|
||||||
}
|
|
||||||
file.State.Event(context.Background(), "repair_file")
|
file.State.Event(context.Background(), "repair_file")
|
||||||
}
|
}
|
||||||
torrent.UnassignedLinks = mapset.NewSet[string]()
|
torrent.UnassignedLinks = mapset.NewSet[string]()
|
||||||
@@ -236,9 +239,6 @@ func (t *TorrentManager) convertToTorrent(info *realdebrid.TorrentInfo) *Torrent
|
|||||||
} else {
|
} else {
|
||||||
torrent.UnassignedLinks = mapset.NewSet[string]()
|
torrent.UnassignedLinks = mapset.NewSet[string]()
|
||||||
for _, link := range info.Links {
|
for _, link := range info.Links {
|
||||||
if strings.HasPrefix(link, "https://real-debrid.com/d/") {
|
|
||||||
link = link[0:39]
|
|
||||||
}
|
|
||||||
torrent.UnassignedLinks.Add(link)
|
torrent.UnassignedLinks.Add(link)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -354,9 +354,6 @@ func (t *TorrentManager) assignLinks(torrent *Torrent) bool {
|
|||||||
if !assigned && file.State.Is("broken_file") && file.Bytes == unrestrict.Filesize && strings.HasSuffix(strings.ToLower(file.Path), strings.ToLower(unrestrict.Filename)) {
|
if !assigned && file.State.Is("broken_file") && file.Bytes == unrestrict.Filesize && strings.HasSuffix(strings.ToLower(file.Path), strings.ToLower(unrestrict.Filename)) {
|
||||||
file.Link = link
|
file.Link = link
|
||||||
assignedLinks = append(assignedLinks, link)
|
assignedLinks = append(assignedLinks, link)
|
||||||
if strings.HasPrefix(file.Link, "https://real-debrid.com/d/") {
|
|
||||||
file.Link = file.Link[0:39]
|
|
||||||
}
|
|
||||||
file.State.Event(context.Background(), "repair_file")
|
file.State.Event(context.Background(), "repair_file")
|
||||||
assigned = true
|
assigned = true
|
||||||
assignedCount++
|
assignedCount++
|
||||||
@@ -531,6 +528,12 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, selection []string)
|
|||||||
t.DeleteByID(newTorrentID)
|
t.DeleteByID(newTorrentID)
|
||||||
return nil, fmt.Errorf("cannot get info on redownloaded : %v", err)
|
return nil, fmt.Errorf("cannot get info on redownloaded : %v", err)
|
||||||
}
|
}
|
||||||
|
for i := range info.Links {
|
||||||
|
if strings.HasPrefix(info.Links[i], "https://real-debrid.com/d/") {
|
||||||
|
// set link to max 39 chars (26 + 13)
|
||||||
|
info.Links[i] = info.Links[i][0:39]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if info.Status == "magnet_conversion" {
|
if info.Status == "magnet_conversion" {
|
||||||
time.Sleep(60 * time.Second)
|
time.Sleep(60 * time.Second)
|
||||||
@@ -658,9 +661,6 @@ func (t *TorrentManager) checkIfBroken(info *realdebrid.TorrentInfo, brokenFiles
|
|||||||
|
|
||||||
for i, file := range selectedFiles {
|
for i, file := range selectedFiles {
|
||||||
file.Link = info.Links[i]
|
file.Link = info.Links[i]
|
||||||
if strings.HasPrefix(file.Link, "https://real-debrid.com/d/") {
|
|
||||||
file.Link = file.Link[0:39]
|
|
||||||
}
|
|
||||||
file.State.Event(context.Background(), "repair_file")
|
file.State.Event(context.Background(), "repair_file")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -276,11 +276,14 @@ func (r *HTTPClient) shouldRetry(req *http.Request, resp *http.Response, err err
|
|||||||
return -1 // don't retry
|
return -1 // don't retry
|
||||||
}
|
}
|
||||||
} else if downloadErr, ok := err.(*DownloadErrorResponse); ok {
|
} else if downloadErr, ok := err.(*DownloadErrorResponse); ok {
|
||||||
switch downloadErr.Code {
|
switch downloadErr.Message {
|
||||||
case http.StatusServiceUnavailable: // Service unavailable
|
case "bytes_limit_reached": // 503
|
||||||
return -1
|
return -1
|
||||||
default:
|
case "invalid_download_code": // 404
|
||||||
|
time.Sleep(time.Duration(rateLimitSleep) * time.Second)
|
||||||
return 1
|
return 1
|
||||||
|
default:
|
||||||
|
return 1 // retry
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil && strings.Contains(err.Error(), "timeout") {
|
if err != nil && strings.Contains(err.Error(), "timeout") {
|
||||||
|
|||||||
@@ -78,13 +78,13 @@ func (rd *RealDebrid) UnrestrictAndVerify(link string) (*Download, error) {
|
|||||||
rd.TokenManager.SetTokenAsExpired(token, "bandwidth limit exceeded")
|
rd.TokenManager.SetTokenAsExpired(token, "bandwidth limit exceeded")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err == nil {
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
rd.verifiedLinks.Set(download.ID, time.Now().Unix()+60*60*24)
|
rd.verifiedLinks.Set(download.ID, time.Now().Unix()+60*60*24)
|
||||||
|
|
||||||
return download, nil
|
return download, nil
|
||||||
}
|
}
|
||||||
|
rd.verifiedLinks.Remove(download.ID)
|
||||||
|
tokenMap.Remove(link)
|
||||||
|
}
|
||||||
|
|
||||||
download, err := rd.UnrestrictLinkWithToken(link, token)
|
download, err := rd.UnrestrictLinkWithToken(link, token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user