Files
zurg/internal/clear/downloads.go
Ben Adrian Sarmiento 3abf48514d Return an error for 503
2024-06-23 22:08:54 +02:00

55 lines
1.1 KiB
Go

package clear
import (
"fmt"
"io"
"net/http"
"strings"
"time"
)
func ClearDownloads(authCode string) {
for {
req, err := http.NewRequest(http.MethodGet, "https://real-debrid.com/downloads?del-all=1&p=1", nil)
if err != nil {
fmt.Println("Error creating request:", err)
return
}
// Set the necessary headers
req.Header.Set("Cookie", "auth="+authCode+"; lang=en; https=1")
req.Header.Set("TE", "trailers")
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println("Error sending request:", err)
return
}
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response body:", err)
return
}
resp.Body.Close()
responseBody := string(body)
// Check if "login.php" is in the response
if strings.Contains(responseBody, "login.php") {
fmt.Println("Error: The auth code is invalid.")
return
}
// Condition to break the loop
if !strings.Contains(responseBody, "p=1&del=") {
break
}
fmt.Println("Clearing downloads...")
time.Sleep(time.Millisecond * 100) // Adding delay to avoid overwhelming the server
}
fmt.Println("Downloads cleared.")
}