- Delete empty files selected torrents

- Add more info to UI
- Add a global file download limit for local downloads
This commit is contained in:
Mukhtar Akere
2025-04-27 01:16:24 +01:00
parent e8112a4647
commit a3e64cc269
11 changed files with 88 additions and 46 deletions
+5 -5
View File
@@ -66,7 +66,7 @@ func (q *QBit) ProcessManualFile(torrent *Torrent) (string, error) {
func (q *QBit) downloadFiles(torrent *Torrent, parent string) {
debridTorrent := torrent.DebridTorrent
var wg sync.WaitGroup
semaphore := make(chan struct{}, 5)
totalSize := int64(0)
for _, file := range debridTorrent.Files {
totalSize += file.Size
@@ -92,8 +92,8 @@ func (q *QBit) downloadFiles(torrent *Torrent, parent string) {
q.UpdateTorrentMin(torrent, debridTorrent)
}
client := &grab.Client{
UserAgent: "qBitTorrent",
HTTPClient: request.New(request.WithTimeout(0)),
UserAgent: "Decypharr[QBitTorrent]",
HTTPClient: request.New(request.WithTimeout(60 * time.Second)),
}
for _, file := range debridTorrent.Files {
if file.DownloadLink == nil {
@@ -101,10 +101,10 @@ func (q *QBit) downloadFiles(torrent *Torrent, parent string) {
continue
}
wg.Add(1)
semaphore <- struct{}{}
q.downloadSemaphore <- struct{}{}
go func(file debrid.File) {
defer wg.Done()
defer func() { <-semaphore }()
defer func() { <-q.downloadSemaphore }()
filename := file.Link
err := Download(
+12 -9
View File
@@ -20,6 +20,8 @@ type QBit struct {
Tags []string
RefreshInterval int
SkipPreCache bool
downloadSemaphore chan struct{}
}
func New() *QBit {
@@ -28,14 +30,15 @@ func New() *QBit {
port := cmp.Or(_cfg.Port, os.Getenv("QBIT_PORT"), "8282")
refreshInterval := cmp.Or(cfg.RefreshInterval, 10)
return &QBit{
Username: cfg.Username,
Password: cfg.Password,
Port: port,
DownloadFolder: cfg.DownloadFolder,
Categories: cfg.Categories,
Storage: NewTorrentStorage(filepath.Join(_cfg.Path, "torrents.json")),
logger: logger.New("qbit"),
RefreshInterval: refreshInterval,
SkipPreCache: cfg.SkipPreCache,
Username: cfg.Username,
Password: cfg.Password,
Port: port,
DownloadFolder: cfg.DownloadFolder,
Categories: cfg.Categories,
Storage: NewTorrentStorage(filepath.Join(_cfg.Path, "torrents.json")),
logger: logger.New("qbit"),
RefreshInterval: refreshInterval,
SkipPreCache: cfg.SkipPreCache,
downloadSemaphore: make(chan struct{}, cmp.Or(cfg.MaxDownloads, 5)),
}
}
+4
View File
@@ -76,6 +76,10 @@ func (q *QBit) ProcessFiles(torrent *Torrent, debridTorrent *debrid.Torrent, arr
q.logger.Debug().Msgf("%s <- (%s) Download Progress: %.2f%%", debridTorrent.Debrid, debridTorrent.Name, debridTorrent.Progress)
dbT, err := client.CheckStatus(debridTorrent, isSymlink)
if err != nil {
if dbT != nil && dbT.Id != "" {
// Delete the torrent if it was not downloaded
_ = client.DeleteTorrent(dbT.Id)
}
q.logger.Error().Msgf("Error checking status: %v", err)
q.MarkAsFailed(torrent)
if err := arr.Refresh(); err != nil {