feat: handle torrent downloading errors

This commit is contained in:
Soner Sayakci 2023-11-16 23:13:03 +01:00
parent 347b85eb17
commit cf5019db40
No known key found for this signature in database
2 changed files with 16 additions and 0 deletions

12
main.go
View File

@ -8,6 +8,7 @@ import (
"log"
"os"
"path/filepath"
"time"
)
var client realdebrid.Client
@ -136,7 +137,18 @@ func handleTorrentDownload(ctx context.Context, id string) {
break
}
if status.IsError() {
log.Printf("error downloading torrent %s: %s", id, status.Status)
if err := client.DeleteTorrent(ctx, id); err != nil {
log.Printf("error deleting torrent: %s", err)
}
return
}
log.Printf("still downloading torrent %s, progress %d", status.FileName, status.Progress)
time.Sleep(30 * time.Second)
}
log.Printf("finished downloading torrent %s", id)

View File

@ -13,3 +13,7 @@ type TorrentStatus struct {
func (status TorrentStatus) IsDone() bool {
return status.Status == "downloaded"
}
func (status TorrentStatus) IsError() bool {
return status.Status == "magnet_error" || status.Status == "virus" || status.Status == "dead" || status.Status == "error"
}