Fix repairs
This commit is contained in:
@@ -29,7 +29,7 @@ type TorrentManager struct {
|
|||||||
DownloadMap cmap.ConcurrentMap[string, *realdebrid.Download]
|
DownloadMap cmap.ConcurrentMap[string, *realdebrid.Download]
|
||||||
Repairs cmap.ConcurrentMap[string, bool]
|
Repairs cmap.ConcurrentMap[string, bool]
|
||||||
allAccessKeys mapset.Set[string]
|
allAccessKeys mapset.Set[string]
|
||||||
forRepairs mapset.Set[string]
|
onlyForRepair mapset.Set[string]
|
||||||
latestState *LibraryState
|
latestState *LibraryState
|
||||||
requiredVersion string
|
requiredVersion string
|
||||||
workerPool *ants.Pool
|
workerPool *ants.Pool
|
||||||
@@ -44,7 +44,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
|
|||||||
Config: cfg,
|
Config: cfg,
|
||||||
Api: api,
|
Api: api,
|
||||||
allAccessKeys: mapset.NewSet[string](),
|
allAccessKeys: mapset.NewSet[string](),
|
||||||
forRepairs: mapset.NewSet[string](),
|
onlyForRepair: mapset.NewSet[string](),
|
||||||
latestState: &LibraryState{},
|
latestState: &LibraryState{},
|
||||||
requiredVersion: "11.01.2024",
|
requiredVersion: "11.01.2024",
|
||||||
workerPool: p,
|
workerPool: p,
|
||||||
@@ -63,6 +63,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
|
|||||||
// Fetch downloads
|
// Fetch downloads
|
||||||
t.DownloadCache = cmap.New[*realdebrid.Download]()
|
t.DownloadCache = cmap.New[*realdebrid.Download]()
|
||||||
t.DownloadMap = cmap.New[*realdebrid.Download]()
|
t.DownloadMap = cmap.New[*realdebrid.Download]()
|
||||||
|
t.Repairs = cmap.New[bool]()
|
||||||
if t.Config.EnableDownloadCache() {
|
if t.Config.EnableDownloadCache() {
|
||||||
_ = t.workerPool.Submit(func() {
|
_ = t.workerPool.Submit(func() {
|
||||||
page := 1
|
page := 1
|
||||||
|
|||||||
@@ -45,13 +45,13 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
torrentIDs := info.DownloadedIDs.ToSlice()
|
torrentIDs := info.DownloadedIDs.ToSlice()
|
||||||
if !info.AnyInProgress() && len(torrentIDs) > 0 && t.forRepairs.Contains(info.DownloadedIDs.ToSlice()[0]) {
|
if !info.AnyInProgress() && len(torrentIDs) > 0 && t.onlyForRepair.Contains(info.DownloadedIDs.ToSlice()[0]) {
|
||||||
torrentID := info.DownloadedIDs.ToSlice()[0]
|
torrentID := info.DownloadedIDs.ToSlice()[0]
|
||||||
// if it's 100% and it's a temp repair, remove it
|
// if it's 100% and it's a temp repair, remove it
|
||||||
t.Api.DeleteTorrent(torrentID)
|
t.Api.DeleteTorrent(torrentID)
|
||||||
toReinsert.Add(t.GetKey(info))
|
toReinsert.Add(t.GetKey(info))
|
||||||
infoChan <- nil
|
infoChan <- nil
|
||||||
t.forRepairs.Remove(torrentID)
|
t.onlyForRepair.Remove(torrentID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !info.AnyInProgress() {
|
if !info.AnyInProgress() {
|
||||||
|
|||||||
@@ -212,20 +212,6 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
|||||||
})
|
})
|
||||||
t.log.Debugf("During repair, zurg found %d broken files for torrent %s", len(brokenFiles), t.GetKey(torrent))
|
t.log.Debugf("During repair, zurg found %d broken files for torrent %s", len(brokenFiles), t.GetKey(torrent))
|
||||||
|
|
||||||
if len(brokenFiles) == 1 && torrent.SelectedFiles.Count() > 2 {
|
|
||||||
// if we download a single file, it will be named differently
|
|
||||||
// so we need to download 1 extra file to preserve the name
|
|
||||||
// this is only relevant if we enable retain_rd_torrent_name
|
|
||||||
// add the first file link encountered with a prefix of http
|
|
||||||
t.log.Debugf("Torrent %s has only 1 broken file, adding 1 extra file to preserve the name", t.GetKey(torrent))
|
|
||||||
for _, file := range torrent.SelectedFiles.Items() {
|
|
||||||
if strings.HasPrefix(file.Link, "http") {
|
|
||||||
brokenFiles = append(brokenFiles, *file)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(brokenFiles) > 0 {
|
if len(brokenFiles) > 0 {
|
||||||
t.log.Infof("Redownloading %dof%d files for torrent %s", len(brokenFiles), torrent.SelectedFiles.Count(), t.GetKey(torrent))
|
t.log.Infof("Redownloading %dof%d files for torrent %s", len(brokenFiles), torrent.SelectedFiles.Count(), t.GetKey(torrent))
|
||||||
brokenFileIDs := strings.Join(getFileIDs(brokenFiles), ",")
|
brokenFileIDs := strings.Join(getFileIDs(brokenFiles), ",")
|
||||||
@@ -305,13 +291,13 @@ func (t *TorrentManager) reinsertTorrent(torrent *Torrent, brokenFiles string) b
|
|||||||
|
|
||||||
if info.Progress != 100 {
|
if info.Progress != 100 {
|
||||||
t.log.Infof("Torrent id=%s is not cached anymore so we have to wait until completion (this should fix the issue already)", info.ID)
|
t.log.Infof("Torrent id=%s is not cached anymore so we have to wait until completion (this should fix the issue already)", info.ID)
|
||||||
t.forRepairs.Add(newTorrentID)
|
t.onlyForRepair.Add(newTorrentID)
|
||||||
if len(oldTorrentIDs) > 0 {
|
if len(oldTorrentIDs) > 0 {
|
||||||
for _, id := range oldTorrentIDs {
|
for _, id := range oldTorrentIDs {
|
||||||
t.Api.DeleteTorrent(id)
|
t.Api.DeleteTorrent(id)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
t.forRepairs.Add(newTorrentID)
|
t.onlyForRepair.Add(newTorrentID)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -324,13 +310,13 @@ func (t *TorrentManager) reinsertTorrent(torrent *Torrent, brokenFiles string) b
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.log.Infof("Repair successful id=%s", newTorrentID)
|
t.log.Infof("Repair successful id=%s", newTorrentID)
|
||||||
t.forRepairs.Add(newTorrentID)
|
t.onlyForRepair.Add(newTorrentID)
|
||||||
if len(oldTorrentIDs) > 0 {
|
if len(oldTorrentIDs) > 0 {
|
||||||
for _, id := range oldTorrentIDs {
|
for _, id := range oldTorrentIDs {
|
||||||
t.Api.DeleteTorrent(id)
|
t.Api.DeleteTorrent(id)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
t.forRepairs.Add(newTorrentID)
|
t.onlyForRepair.Add(newTorrentID)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user