From 8e7f7c762499158431eede44f437d7fdece6bc64 Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Sat, 25 May 2024 22:02:05 +0200 Subject: [PATCH] Save based on access key and dont retry code 19 --- internal/torrent/manager.go | 4 ++-- internal/torrent/refresh.go | 14 +++++++++----- pkg/http/client.go | 2 -- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/internal/torrent/manager.go b/internal/torrent/manager.go index 24e027f..02e6897 100644 --- a/internal/torrent/manager.go +++ b/internal/torrent/manager.go @@ -103,7 +103,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w allTorrents.IterCb(func(_ string, torrent *Torrent) { t.applyMediaInfoDetails(torrent) t.writeTorrentToFile(torrent) - t.log.Debugf("Applied media info details to torrent %s", torrent.Hash) + t.log.Debugf("Applied media info details to torrent %s", t.GetKey(torrent)) }) }) @@ -198,7 +198,7 @@ func (t *TorrentManager) writeTorrentToFile(torrent *Torrent) { return } - t.log.Debugf("Saved torrent %s (hash=%s) to file", t.GetKey(torrent), torrent.Hash) + t.log.Debugf("Saved torrent %s to file", t.GetKey(torrent), torrent.Hash) } func (t *TorrentManager) applyMediaInfoDetails(torrent *Torrent) { diff --git a/internal/torrent/refresh.go b/internal/torrent/refresh.go index bb715f3..43f3114 100644 --- a/internal/torrent/refresh.go +++ b/internal/torrent/refresh.go @@ -48,11 +48,10 @@ func (t *TorrentManager) refreshTorrents() []string { return false }) - existingHashes := mapset.NewSet[string]() + cachedAccessKeys := mapset.NewSet[string]() t.getTorrentFiles("data").Each(func(path string) bool { path = filepath.Base(path) - hash := strings.TrimSuffix(path, ".zurgtorrent") - existingHashes.Add(hash) + cachedAccessKeys.Add(strings.TrimSuffix(path, ".zurgtorrent")) return false }) @@ -96,7 +95,7 @@ func (t *TorrentManager) refreshTorrents() []string { } // write to file if it is a new torrent - if forMerging == nil && !existingHashes.Contains(tInfo.Hash) { + if forMerging == nil && !cachedAccessKeys.Contains(accessKey) { t.writeTorrentToFile(torrent) } @@ -324,9 +323,14 @@ func (t *TorrentManager) mergeTorrents(existing, toMerge *Torrent) *Torrent { } }) older.SelectedFiles.IterCb(func(key string, file *File) { - if f, ok := mergedTorrent.SelectedFiles.Get(key); !ok || !f.State.Is("ok_file") { + mediaInfo := file.MediaInfo + f, ok := mergedTorrent.SelectedFiles.Get(key) + if !ok || !f.State.Is("ok_file") { mergedTorrent.SelectedFiles.Set(key, file) } + if ok && f.MediaInfo == nil && mediaInfo != nil { + f.MediaInfo = mediaInfo + } }) // unassigned links diff --git a/pkg/http/client.go b/pkg/http/client.go index 2d4b0e7..f2f99b5 100644 --- a/pkg/http/client.go +++ b/pkg/http/client.go @@ -269,8 +269,6 @@ func (r *HTTPClient) shouldRetry(req *http.Request, resp *http.Response, err err return 1 case 18: // Hoster limit reached return 1 - case 19: // Hoster temporarily unavailable - return 1 case 25: // Service unavailable return 1 case 34: // Too many requests (retry infinitely), default: 4 secs