Add library update hook on repair all

This commit is contained in:
Ben Sarmiento
2023-12-07 15:58:22 +01:00
parent 10aac20030
commit 845a01d7f3
5 changed files with 18 additions and 10 deletions

View File

@@ -26,7 +26,7 @@ func (t *TorrentManager) Delete(accessKey string, deleteInRD bool) {
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE) infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
if torrent, ok := allTorrents.Get(accessKey); ok { if torrent, ok := allTorrents.Get(accessKey); ok {
torrent.DownloadedIDs.Each(func(id string) bool { torrent.DownloadedIDs.Each(func(id string) bool {
t.log.Infof("Deleting torrent %s %s in RD", id, accessKey) t.log.Debugf("Deleting torrent %s %s in RD", id, accessKey)
t.Api.DeleteTorrent(id) t.Api.DeleteTorrent(id)
infoCache.Remove(id) infoCache.Remove(id)
t.deleteTorrentFile(id) t.deleteTorrentFile(id)

View File

@@ -43,6 +43,6 @@ func OnLibraryUpdateHook(paths []string, config config.ConfigInterface, log *log
return return
} }
if output != "" { if output != "" {
log.Infof("Output of hook on_library_update:\n%s", output) log.Debugf("Output of hook on_library_update:\n%s", output)
} }
} }

View File

@@ -31,7 +31,7 @@ func (t *TorrentManager) RefreshTorrents() []string {
} }
wg.Wait() wg.Wait()
close(infoChan) close(infoChan)
t.log.Infof("Fetched info for %d torrents", len(instances)) t.log.Debugf("Fetched info for %d torrents", len(instances))
freshKeys := set.NewStringSet() freshKeys := set.NewStringSet()
allTorrents, _ := t.DirectoryMap.Get(INT_ALL) allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
@@ -55,6 +55,7 @@ func (t *TorrentManager) RefreshTorrents() []string {
strset.Difference(freshKeys, t.allAccessKeys).Each(func(accessKey string) bool { strset.Difference(freshKeys, t.allAccessKeys).Each(func(accessKey string) bool {
// assign to directories // assign to directories
tor, _ := allTorrents.Get(accessKey) tor, _ := allTorrents.Get(accessKey)
var directories []string
t.assignedDirectoryCb(tor, func(directory string) { t.assignedDirectoryCb(tor, func(directory string) {
if strings.HasPrefix(directory, "int__") { if strings.HasPrefix(directory, "int__") {
return return
@@ -62,8 +63,11 @@ func (t *TorrentManager) RefreshTorrents() []string {
torrents, _ := t.DirectoryMap.Get(directory) torrents, _ := t.DirectoryMap.Get(directory)
torrents.Set(accessKey, tor) torrents.Set(accessKey, tor)
updatedPaths = append(updatedPaths, fmt.Sprintf("%s/%s", directory, accessKey)) updatedPaths = append(updatedPaths, fmt.Sprintf("%s/%s", directory, accessKey))
if directory != "__all__" {
directories = append(directories, directory)
}
}) })
t.log.Infof("Added %s to the library", accessKey) t.log.Debugf("Added %s to %v", accessKey, directories)
t.allAccessKeys.Add(accessKey) t.allAccessKeys.Add(accessKey)
return true return true
}) })

View File

@@ -9,9 +9,8 @@ import (
func (t *TorrentManager) RepairAll() { func (t *TorrentManager) RepairAll() {
_ = t.repairWorker.Submit(func() { _ = t.repairWorker.Submit(func() {
t.log.Info("Checking for torrents to repair")
t.repairAll() t.repairAll()
t.log.Info("Finished checking for torrents to repair") t.log.Debug("Finished repairing all torrents")
}) })
} }
@@ -27,10 +26,16 @@ func (t *TorrentManager) repairAll() {
} }
}) })
t.log.Debugf("Found %d torrents to repair", len(toRepair)) t.log.Debugf("Found %d torrents to repair", len(toRepair))
var updatedPaths []string
for i := range toRepair { for i := range toRepair {
t.log.Infof("Repairing %s", toRepair[i].AccessKey) torrent := toRepair[i]
t.repair(toRepair[i]) t.log.Infof("Repairing %s", torrent.AccessKey)
t.repair(torrent)
t.assignedDirectoryCb(torrent, func(directory string) {
updatedPaths = append(updatedPaths, fmt.Sprintf("%s/%s", directory, torrent.AccessKey))
})
} }
t.TriggerHookOnLibraryUpdate(updatedPaths)
} }
func (t *TorrentManager) Repair(torrent *Torrent) { func (t *TorrentManager) Repair(torrent *Torrent) {
@@ -205,7 +210,6 @@ func (t *TorrentManager) canCapacityHandle() bool {
} }
if count.DownloadingCount < count.MaxNumberOfTorrents { if count.DownloadingCount < count.MaxNumberOfTorrents {
// t.log.Infof("We can still add a new torrent, we have capacity for %d more", count.MaxNumberOfTorrents-count.DownloadingCount)
return true return true
} }

View File

@@ -56,7 +56,7 @@ func (rd *RealDebrid) UnrestrictCheck(link string) (*Download, error) {
return nil, err return nil, err
} }
rd.log.Info("Link %s is streamable? %v", response.Streamable) rd.log.Debugf("Link %s is streamable? %v", response.Streamable)
return &response, nil return &response, nil
} }