Identify broken links properly
This commit is contained in:
@@ -16,16 +16,12 @@ func (t *TorrentManager) CheckDeletedStatus(torrent *Torrent) bool {
|
|||||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
torrent.DownloadedIDs.Each(func(id string) bool {
|
||||||
info, _ := infoCache.Get(id)
|
info, _ := infoCache.Get(id)
|
||||||
info.SelectedFiles.IterCb(func(_ string, file *File) {
|
info.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
found := false
|
|
||||||
for _, unselectedID := range unselectedIDs {
|
for _, unselectedID := range unselectedIDs {
|
||||||
if file.ID == unselectedID {
|
if file.ID == unselectedID {
|
||||||
found = true
|
file.Link = "unselect"
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if found {
|
|
||||||
file.Link = "unselect"
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
t.writeTorrentToFile(id, info, false)
|
t.writeTorrentToFile(id, info, false)
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
|
|||||||
Api: api,
|
Api: api,
|
||||||
allAccessKeys: mapset.NewSet[string](),
|
allAccessKeys: mapset.NewSet[string](),
|
||||||
latestState: &LibraryState{},
|
latestState: &LibraryState{},
|
||||||
requiredVersion: "10.01.2024",
|
requiredVersion: "11.01.2024",
|
||||||
workerPool: p,
|
workerPool: p,
|
||||||
log: log,
|
log: log,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,6 +180,7 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
|||||||
} else {
|
} else {
|
||||||
torrent.InProgressIDs.Add(info.ID)
|
torrent.InProgressIDs.Add(info.ID)
|
||||||
}
|
}
|
||||||
|
torrent.BrokenLinks = mapset.NewSet[string]()
|
||||||
|
|
||||||
t.writeTorrentToFile(rdTorrent.ID, &torrent, true)
|
t.writeTorrentToFile(rdTorrent.ID, &torrent, true)
|
||||||
infoCache.Set(rdTorrent.ID, &torrent)
|
infoCache.Set(rdTorrent.ID, &torrent)
|
||||||
|
|||||||
@@ -102,26 +102,16 @@ func (t *TorrentManager) repairAll() {
|
|||||||
|
|
||||||
func (t *TorrentManager) Repair(torrent *Torrent) {
|
func (t *TorrentManager) Repair(torrent *Torrent) {
|
||||||
// save the broken files to the file cache
|
// save the broken files to the file cache
|
||||||
var brokenFileIDs []int
|
|
||||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
|
||||||
if file.Link == "repair" {
|
|
||||||
brokenFileIDs = append(brokenFileIDs, file.ID)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
||||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
torrent.DownloadedIDs.Each(func(id string) bool {
|
||||||
info, _ := infoCache.Get(id)
|
info, _ := infoCache.Get(id)
|
||||||
info.SelectedFiles.IterCb(func(_ string, file *File) {
|
info.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
found := false
|
torrent.BrokenLinks.Each(func(link string) bool {
|
||||||
for _, brokenFileID := range brokenFileIDs {
|
if file.Link == link {
|
||||||
if file.ID == brokenFileID {
|
file.Link = "repair"
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
return file.Link == link
|
||||||
if found {
|
})
|
||||||
file.Link = "unselect"
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
t.writeTorrentToFile(id, info, false)
|
t.writeTorrentToFile(id, info, false)
|
||||||
return false
|
return false
|
||||||
@@ -221,7 +211,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
|||||||
// second solution: add only the broken files
|
// second solution: add only the broken files
|
||||||
var brokenFiles []File
|
var brokenFiles []File
|
||||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
if file.Link == "repair" || file.Link == "" {
|
if !strings.HasPrefix(file.Link, "http") && file.Link != "unselect" {
|
||||||
brokenFiles = append(brokenFiles, *file)
|
brokenFiles = append(brokenFiles, *file)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ type Torrent struct {
|
|||||||
DownloadedIDs mapset.Set[string] `json:"DownloadedIDs"`
|
DownloadedIDs mapset.Set[string] `json:"DownloadedIDs"`
|
||||||
InProgressIDs mapset.Set[string] `json:"InProgressIDs"`
|
InProgressIDs mapset.Set[string] `json:"InProgressIDs"`
|
||||||
UnassignedLinks mapset.Set[string] `json:"UnassignedLinks"`
|
UnassignedLinks mapset.Set[string] `json:"UnassignedLinks"`
|
||||||
|
BrokenLinks mapset.Set[string] `json:"BrokenLinks"`
|
||||||
|
|
||||||
Version string `json:"Version"` // only used for files
|
Version string `json:"Version"` // only used for files
|
||||||
}
|
}
|
||||||
@@ -35,6 +36,7 @@ func (t *Torrent) MarshalJSON() ([]byte, error) {
|
|||||||
DownloadedIDsJson stdjson.RawMessage `json:"DownloadedIDs"`
|
DownloadedIDsJson stdjson.RawMessage `json:"DownloadedIDs"`
|
||||||
InProgressIDsJson stdjson.RawMessage `json:"InProgressIDs"`
|
InProgressIDsJson stdjson.RawMessage `json:"InProgressIDs"`
|
||||||
UnassignedLinksJson stdjson.RawMessage `json:"UnassignedLinks"`
|
UnassignedLinksJson stdjson.RawMessage `json:"UnassignedLinks"`
|
||||||
|
BrokenLinksJson stdjson.RawMessage `json:"BrokenLinks"`
|
||||||
*Alias
|
*Alias
|
||||||
}{
|
}{
|
||||||
Alias: (*Alias)(t),
|
Alias: (*Alias)(t),
|
||||||
@@ -67,6 +69,13 @@ func (t *Torrent) MarshalJSON() ([]byte, error) {
|
|||||||
temp.UnassignedLinksJson = []byte(unassignedLinksStr)
|
temp.UnassignedLinksJson = []byte(unassignedLinksStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if t.BrokenLinks.IsEmpty() {
|
||||||
|
temp.BrokenLinksJson = []byte(`""`)
|
||||||
|
} else {
|
||||||
|
brokenLinksStr := `"` + strings.Join(t.BrokenLinks.ToSlice(), ",") + `"`
|
||||||
|
temp.BrokenLinksJson = []byte(brokenLinksStr)
|
||||||
|
}
|
||||||
|
|
||||||
return json.Marshal(temp)
|
return json.Marshal(temp)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +86,7 @@ func (t *Torrent) UnmarshalJSON(data []byte) error {
|
|||||||
DownloadedIDsJson stdjson.RawMessage `json:"DownloadedIDs"`
|
DownloadedIDsJson stdjson.RawMessage `json:"DownloadedIDs"`
|
||||||
InProgressIDsJson stdjson.RawMessage `json:"InProgressIDs"`
|
InProgressIDsJson stdjson.RawMessage `json:"InProgressIDs"`
|
||||||
UnassignedLinksJson stdjson.RawMessage `json:"UnassignedLinks"`
|
UnassignedLinksJson stdjson.RawMessage `json:"UnassignedLinks"`
|
||||||
|
BrokenLinksJson stdjson.RawMessage `json:"BrokenLinks"`
|
||||||
*Alias
|
*Alias
|
||||||
}{
|
}{
|
||||||
Alias: (*Alias)(t),
|
Alias: (*Alias)(t),
|
||||||
@@ -113,6 +123,13 @@ func (t *Torrent) UnmarshalJSON(data []byte) error {
|
|||||||
t.UnassignedLinks = mapset.NewSet[string]()
|
t.UnassignedLinks = mapset.NewSet[string]()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(temp.BrokenLinksJson) > 2 {
|
||||||
|
brokenLinks := strings.Split(strings.ReplaceAll(string(temp.BrokenLinksJson), `"`, ""), ",")
|
||||||
|
t.BrokenLinks = mapset.NewSet[string](brokenLinks...)
|
||||||
|
} else {
|
||||||
|
t.BrokenLinks = mapset.NewSet[string]()
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ func (dl *Downloader) DownloadFile(directory, torrentName, fileName string, resp
|
|||||||
if unrestrict == nil {
|
if unrestrict == nil {
|
||||||
log.Warnf("File %s cannot be unrestricted (link=%s)", fileName, link)
|
log.Warnf("File %s cannot be unrestricted (link=%s)", fileName, link)
|
||||||
if cfg.EnableRepair() {
|
if cfg.EnableRepair() {
|
||||||
|
torrent.BrokenLinks.Add(file.Link)
|
||||||
file.Link = "repair"
|
file.Link = "repair"
|
||||||
torMgr.Repair(torrent)
|
torMgr.Repair(torrent)
|
||||||
} else {
|
} else {
|
||||||
@@ -159,6 +160,7 @@ func (dl *Downloader) streamFileToResponse(torrent *intTor.Torrent, file *intTor
|
|||||||
if file != nil && unrestrict.Streamable == 1 {
|
if file != nil && unrestrict.Streamable == 1 {
|
||||||
log.Warnf("Cannot download file %s: %v", file.Path, err)
|
log.Warnf("Cannot download file %s: %v", file.Path, err)
|
||||||
if cfg.EnableRepair() && torrent != nil {
|
if cfg.EnableRepair() && torrent != nil {
|
||||||
|
torrent.BrokenLinks.Add(file.Link)
|
||||||
file.Link = "repair"
|
file.Link = "repair"
|
||||||
torMgr.Repair(torrent)
|
torMgr.Repair(torrent)
|
||||||
} else {
|
} else {
|
||||||
@@ -174,6 +176,7 @@ func (dl *Downloader) streamFileToResponse(torrent *intTor.Torrent, file *intTor
|
|||||||
if file != nil && unrestrict.Streamable == 1 {
|
if file != nil && unrestrict.Streamable == 1 {
|
||||||
log.Warnf("Received a %s status code for file %s", download.Status, file.Path)
|
log.Warnf("Received a %s status code for file %s", download.Status, file.Path)
|
||||||
if cfg.EnableRepair() && torrent != nil {
|
if cfg.EnableRepair() && torrent != nil {
|
||||||
|
torrent.BrokenLinks.Add(file.Link)
|
||||||
file.Link = "repair"
|
file.Link = "repair"
|
||||||
torMgr.Repair(torrent)
|
torMgr.Repair(torrent)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user