assigned links
This commit is contained in:
@@ -114,13 +114,29 @@ func (t *TorrentManager) startRefreshJob() {
|
||||
// getMoreInfo gets original name, size and files for a torrent
|
||||
func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
||||
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
||||
if torrentFromCache, exists := infoCache.Get(rdTorrent.ID); exists && !torrentFromCache.AnyInProgress() && torrentFromCache.SelectedFiles.Count() == len(rdTorrent.Links) {
|
||||
if torrentFromCache, exists := infoCache.Get(rdTorrent.ID); exists &&
|
||||
!torrentFromCache.AnyInProgress() &&
|
||||
torrentFromCache.SelectedFiles.Count() == len(rdTorrent.Links) {
|
||||
|
||||
return torrentFromCache
|
||||
}
|
||||
|
||||
torrentFromFile := t.readTorrentFromFile(rdTorrent.ID)
|
||||
if torrentFromFile != nil && !torrentFromFile.AnyInProgress() && torrentFromFile.SelectedFiles.Count() == len(rdTorrent.Links) {
|
||||
infoCache.Set(rdTorrent.ID, torrentFromFile)
|
||||
return torrentFromFile
|
||||
if torrentFromFile != nil &&
|
||||
!torrentFromFile.AnyInProgress() &&
|
||||
torrentFromFile.SelectedFiles.Count() == len(rdTorrent.Links) {
|
||||
|
||||
hasBrokenFiles := false
|
||||
torrentFromFile.SelectedFiles.IterCb(func(filepath string, file *File) {
|
||||
if !strings.HasPrefix(file.Link, "http") && file.Link != "unselect" {
|
||||
hasBrokenFiles = true
|
||||
}
|
||||
})
|
||||
|
||||
if !hasBrokenFiles {
|
||||
infoCache.Set(rdTorrent.ID, torrentFromFile)
|
||||
return torrentFromFile
|
||||
}
|
||||
}
|
||||
|
||||
info, err := t.Api.GetTorrentInfo(rdTorrent.ID)
|
||||
@@ -132,7 +148,7 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
||||
torrent := Torrent{
|
||||
Name: info.Name,
|
||||
OriginalName: info.OriginalName,
|
||||
LatestAdded: info.Added,
|
||||
Added: info.Added,
|
||||
Hash: info.Hash,
|
||||
}
|
||||
// SelectedFiles is a subset of Files with only the selected ones
|
||||
@@ -182,8 +198,8 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
||||
}
|
||||
torrent.BrokenLinks = mapset.NewSet[string]()
|
||||
|
||||
t.writeTorrentToFile(rdTorrent.ID, &torrent, true)
|
||||
infoCache.Set(rdTorrent.ID, &torrent)
|
||||
t.writeTorrentToFile(rdTorrent.ID, &torrent)
|
||||
|
||||
return &torrent
|
||||
}
|
||||
@@ -198,6 +214,7 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) Torrent {
|
||||
InProgressIDs: mapset.NewSet[string](),
|
||||
Unfixable: existing.Unfixable || toMerge.Unfixable,
|
||||
UnassignedLinks: existing.UnassignedLinks.Union(toMerge.UnassignedLinks),
|
||||
BrokenLinks: existing.BrokenLinks.Union(toMerge.BrokenLinks),
|
||||
}
|
||||
|
||||
// this function triggers only when we have a new DownloadedID
|
||||
@@ -219,8 +236,8 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) Torrent {
|
||||
// if it doesn't exist in the main torrent, add it
|
||||
mainTorrent.SelectedFiles.Set(filepath, fileToMerge)
|
||||
} else if originalFile.Link != "unselect" {
|
||||
// if it exists, compare the LatestAdded property and the link
|
||||
if existing.LatestAdded < toMerge.LatestAdded {
|
||||
// if it exists, compare the Added property and the link
|
||||
if existing.Added < toMerge.Added {
|
||||
// && strings.HasPrefix(fileToMerge.Link, "http")
|
||||
// if torrentToMerge is more recent and its file has a link, update the main torrent's file
|
||||
mainTorrent.SelectedFiles.Set(filepath, fileToMerge)
|
||||
@@ -229,10 +246,10 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) Torrent {
|
||||
}
|
||||
})
|
||||
|
||||
if existing.LatestAdded < toMerge.LatestAdded {
|
||||
mainTorrent.LatestAdded = toMerge.LatestAdded
|
||||
if existing.Added < toMerge.Added {
|
||||
mainTorrent.Added = toMerge.Added
|
||||
} else {
|
||||
mainTorrent.LatestAdded = existing.LatestAdded
|
||||
mainTorrent.Added = existing.Added
|
||||
}
|
||||
|
||||
return mainTorrent
|
||||
|
||||
Reference in New Issue
Block a user