feat: handle torrent downloading errors
This commit is contained in:
parent
347b85eb17
commit
cf5019db40
12
main.go
12
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)
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue