Remove download mount config, it is now always enabled
This commit is contained in:
@@ -174,7 +174,7 @@ func (rd *RealDebrid) GetTorrents(onlyOne bool) ([]Torrent, int, error) {
|
||||
page := 1
|
||||
// compute ceiling of totalCount / limit
|
||||
maxPages := (totalCount + rd.cfg.GetTorrentsCount() - 1) / rd.cfg.GetTorrentsCount()
|
||||
rd.log.Debugf("Total count is %d, max pages is %d", totalCount, maxPages)
|
||||
rd.log.Debugf("Torrents total count is %d, max pages is %d", totalCount, maxPages)
|
||||
maxParallelThreads := 4
|
||||
if maxPages < maxParallelThreads {
|
||||
maxParallelThreads = maxPages
|
||||
@@ -240,7 +240,7 @@ func (rd *RealDebrid) GetTorrentInfo(id string) (*TorrentInfo, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rd.log.Debugf("Got info for torrent %s (progress=%d%%)", id, response.Progress)
|
||||
// rd.log.Debugf("Got info for torrent %s (progress=%d%%)", id, response.Progress)
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
@@ -356,21 +356,22 @@ func (rd *RealDebrid) GetActiveTorrentCount() (*ActiveTorrentCountResponse, erro
|
||||
}
|
||||
|
||||
// GetDownloads returns all torrents, paginated
|
||||
func (rd *RealDebrid) GetDownloads() ([]Download, int, error) {
|
||||
_, totalCount, err := rd.fetchPageOfDownloads(1, 0)
|
||||
func (rd *RealDebrid) GetDownloads() []Download {
|
||||
_, totalCount, err := rd.fetchPageOfDownloads(1, 1)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
return nil
|
||||
}
|
||||
|
||||
const maxItems = 50000
|
||||
|
||||
// reset allDownloads
|
||||
allDownloads := []Download{}
|
||||
page := 1
|
||||
offset := 0
|
||||
limit := 100
|
||||
|
||||
// compute ceiling of totalCount / limit
|
||||
maxPages := (totalCount + limit - 1) / limit
|
||||
// rd.log.Debugf("Total count is %d, max pages is %d", totalCount, maxPages)
|
||||
rd.log.Debugf("Total downloads count is %d, max pages is %d", totalCount, maxPages)
|
||||
maxParallelThreads := 8
|
||||
if maxPages < maxParallelThreads {
|
||||
maxParallelThreads = maxPages
|
||||
@@ -385,7 +386,7 @@ func (rd *RealDebrid) GetDownloads() ([]Download, int, error) {
|
||||
errChan <- nil
|
||||
return
|
||||
}
|
||||
result, _, err := rd.fetchPageOfDownloads(page+add, offset+add*limit)
|
||||
result, _, err := rd.fetchPageOfDownloads(page+add, limit)
|
||||
if err != nil {
|
||||
allResults <- nil
|
||||
errChan <- err
|
||||
@@ -400,35 +401,34 @@ func (rd *RealDebrid) GetDownloads() ([]Download, int, error) {
|
||||
res := <-allResults
|
||||
err := <-errChan
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
return allDownloads
|
||||
}
|
||||
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 {
|
||||
if len(allDownloads) >= totalCount || page >= maxPages || len(allDownloads) >= maxItems {
|
||||
if len(allDownloads) > maxItems {
|
||||
rd.log.Debugf("Capping it to %d downloads", len(allDownloads))
|
||||
allDownloads = allDownloads[:maxItems]
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
page += maxParallelThreads
|
||||
offset += maxParallelThreads * limit
|
||||
}
|
||||
|
||||
rd.log.Debugf("Got %d downloads", len(allDownloads))
|
||||
|
||||
return allDownloads, totalCount, nil
|
||||
return allDownloads
|
||||
}
|
||||
|
||||
func (rd *RealDebrid) fetchPageOfDownloads(page, offset int) ([]Download, int, error) {
|
||||
func (rd *RealDebrid) fetchPageOfDownloads(page, limit int) ([]Download, int, error) {
|
||||
baseURL := "https://api.real-debrid.com/rest/1.0/downloads"
|
||||
var downloads []Download
|
||||
limit := 500
|
||||
totalCount := 0
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("page", fmt.Sprintf("%d", page))
|
||||
params.Set("offset", fmt.Sprintf("%d", offset))
|
||||
params.Set("limit", fmt.Sprintf("%d", limit))
|
||||
// params.Set("filter", "active")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user