Add clear downloads and clear torrents command
This commit is contained in:
54
internal/clear/torrents.go
Normal file
54
internal/clear/torrents.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package clear
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func ClearTorrents(authCode string) {
|
||||
for {
|
||||
req, err := http.NewRequest("GET", "https://real-debrid.com/torrents?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 torrents...")
|
||||
time.Sleep(time.Millisecond * 100) // Adding delay to avoid overwhelming the server
|
||||
}
|
||||
|
||||
fmt.Println("Torrents cleared.")
|
||||
}
|
||||
Reference in New Issue
Block a user