diff --git a/main.go b/main.go index e1e668b..eac2ef1 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/realdebrid/struct.go b/realdebrid/struct.go index 8240c0f..8cec1e7 100644 --- a/realdebrid/struct.go +++ b/realdebrid/struct.go @@ -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" +}