Fixes on merge behavior; remove downloads cap

This commit is contained in:
Ben Adrian Sarmiento
2024-06-04 23:58:56 +02:00
parent b0d05d27d4
commit f977abc052
5 changed files with 15 additions and 35 deletions

View File

@@ -30,7 +30,6 @@ type ConfigInterface interface {
GetRateLimitSleepSecs() int GetRateLimitSleepSecs() int
ShouldDeleteRarFiles() bool ShouldDeleteRarFiles() bool
GetDownloadsEveryMins() int GetDownloadsEveryMins() int
GetDownloadsLimit() int
GetDumpTorrentsEveryMins() int GetDumpTorrentsEveryMins() int
GetPlayableExtensions() []string GetPlayableExtensions() []string
GetTorrentsCount() int GetTorrentsCount() int
@@ -117,35 +116,28 @@ func (z *ZurgConfig) GetNumOfWorkers() int {
func (z *ZurgConfig) GetRefreshEverySecs() int { func (z *ZurgConfig) GetRefreshEverySecs() int {
if z.RefreshEverySecs == 0 { if z.RefreshEverySecs == 0 {
return 60 return 15
} }
return z.RefreshEverySecs return z.RefreshEverySecs
} }
func (z *ZurgConfig) GetRepairEveryMins() int { func (z *ZurgConfig) GetRepairEveryMins() int {
if z.RepairEveryMins == 0 { if z.RepairEveryMins == 0 {
return 60 return 60 // 1 hour
} }
return z.RepairEveryMins return z.RepairEveryMins
} }
func (z *ZurgConfig) GetDownloadsEveryMins() int { func (z *ZurgConfig) GetDownloadsEveryMins() int {
if z.DownloadsEveryMins == 0 { if z.DownloadsEveryMins == 0 {
return 1440 return 720 // 12 hours
} }
return z.DownloadsEveryMins return z.DownloadsEveryMins
} }
func (z *ZurgConfig) GetDownloadsLimit() int {
if z.DownloadsLimit == 0 {
return 10000
}
return z.DownloadsLimit
}
func (z *ZurgConfig) GetDumpTorrentsEveryMins() int { func (z *ZurgConfig) GetDumpTorrentsEveryMins() int {
if z.DumpTorrentsEveryMins == 0 { if z.DumpTorrentsEveryMins == 0 {
return 1440 return 1440 // 1 day
} }
return z.DumpTorrentsEveryMins return z.DumpTorrentsEveryMins
} }
@@ -226,7 +218,7 @@ func (z *ZurgConfig) GetPlayableExtensions() []string {
func (z *ZurgConfig) GetTorrentsCount() int { func (z *ZurgConfig) GetTorrentsCount() int {
if z.TorrentsCount == 0 { if z.TorrentsCount == 0 {
return 100 return 250
} }
return z.TorrentsCount return z.TorrentsCount
} }

View File

@@ -222,10 +222,6 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
<td>Refresh Download Mount Every...</td> <td>Refresh Download Mount Every...</td>
<td>%d mins</td> <td>%d mins</td>
</tr> </tr>
<tr>
<td>Get downloads limit</td>
<td>%d items</td>
</tr>
<tr> <tr>
<td>Dump Torrents Every...</td> <td>Dump Torrents Every...</td>
<td>%d mins</td> <td>%d mins</td>
@@ -336,7 +332,6 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
response.Config.GetTorrentsCount(), response.Config.GetTorrentsCount(),
response.Config.GetDownloadTimeoutSecs(), response.Config.GetDownloadTimeoutSecs(),
response.Config.GetDownloadsEveryMins(), response.Config.GetDownloadsEveryMins(),
response.Config.GetDownloadsLimit(),
response.Config.GetDumpTorrentsEveryMins(), response.Config.GetDumpTorrentsEveryMins(),
response.Config.GetRateLimitSleepSecs(), response.Config.GetRateLimitSleepSecs(),
response.Config.GetRetriesUntilFailed(), response.Config.GetRetriesUntilFailed(),

View File

@@ -342,12 +342,10 @@ func (t *TorrentManager) mountNewDownloads() {
downloads := t.api.GetDownloads() downloads := t.api.GetDownloads()
for i := range downloads { for i := range downloads {
isRealDebrid := strings.HasPrefix(downloads[i].Link, "https://real-debrid.com/d/") isRealDebrid := strings.HasPrefix(downloads[i].Link, "https://real-debrid.com/d/")
if isRealDebrid && !t.UnrestrictMap.Has(downloads[i].Link[0:39]) { if isRealDebrid {
t.UnrestrictMap.Set(downloads[i].Link[0:39], &downloads[i]) t.UnrestrictMap.SetIfAbsent(downloads[i].Link[0:39], &downloads[i])
} else if !isRealDebrid { } else {
if !t.UnrestrictMap.Has(downloads[i].Link) { t.UnrestrictMap.SetIfAbsent(downloads[i].Link, &downloads[i])
t.UnrestrictMap.Set(downloads[i].Link, &downloads[i])
}
filename := filepath.Base(downloads[i].Filename) filename := filepath.Base(downloads[i].Filename)
t.DownloadMap.Set(filename, &downloads[i]) t.DownloadMap.Set(filename, &downloads[i])
} }
@@ -362,6 +360,7 @@ func (t *TorrentManager) StartDownloadsJob() {
for { for {
select { select {
case <-remountTicker.C: case <-remountTicker.C:
t.DownloadMap.Clear()
t.mountNewDownloads() t.mountNewDownloads()
case <-t.RemountTrigger: case <-t.RemountTrigger:
t.DownloadMap.Clear() t.DownloadMap.Clear()

View File

@@ -296,9 +296,7 @@ func (t *TorrentManager) mergeTorrents(existing, toMerge *Torrent) *Torrent {
// selected files // selected files
mergedTorrent.SelectedFiles = cmap.New[*File]() mergedTorrent.SelectedFiles = cmap.New[*File]()
newer.SelectedFiles.IterCb(func(key string, file *File) { newer.SelectedFiles.IterCb(func(key string, file *File) {
if f, ok := mergedTorrent.SelectedFiles.Get(key); !ok || !f.State.Is("ok_file") { mergedTorrent.SelectedFiles.SetIfAbsent(key, file)
mergedTorrent.SelectedFiles.Set(key, file)
}
}) })
older.SelectedFiles.IterCb(func(key string, file *File) { older.SelectedFiles.IterCb(func(key string, file *File) {
mediaInfo := file.MediaInfo mediaInfo := file.MediaInfo

View File

@@ -194,6 +194,7 @@ func (rd *RealDebrid) GetTorrents(onlyOne bool) ([]Torrent, int, error) {
for i := 0; i < maxParallelThreads; i++ { for i := 0; i < maxParallelThreads; i++ {
res := <-allResults res := <-allResults
if res.err != nil { if res.err != nil {
rd.log.Warnf("Ignoring error when fetching torrents: %v", res.err)
continue continue
} }
allTorrents = append(allTorrents, res.torrents...) allTorrents = append(allTorrents, res.torrents...)
@@ -362,8 +363,6 @@ func (rd *RealDebrid) GetDownloads() []Download {
return nil return nil
} }
maxItems := rd.cfg.GetDownloadsLimit()
// reset allDownloads // reset allDownloads
allDownloads := []Download{} allDownloads := []Download{}
page := 1 page := 1
@@ -401,18 +400,15 @@ func (rd *RealDebrid) GetDownloads() []Download {
res := <-allResults res := <-allResults
err := <-errChan err := <-errChan
if err != nil { if err != nil {
return allDownloads rd.log.Warnf("Ignoring error when fetching downloads: %v", err)
continue
} }
allDownloads = append(allDownloads, res...) allDownloads = append(allDownloads, res...)
} }
rd.log.Debugf("Got %d/%d downloads", len(allDownloads), totalCount) rd.log.Debugf("Got %d/%d downloads", len(allDownloads), totalCount)
if len(allDownloads) >= totalCount || page >= maxPages || len(allDownloads) >= maxItems { if len(allDownloads) >= totalCount || page >= maxPages {
if len(allDownloads) > maxItems {
rd.log.Debugf("Capping it to %d downloads", len(allDownloads))
allDownloads = allDownloads[:maxItems]
}
break break
} }