diff --git a/cmd/zurg/main.go b/cmd/zurg/main.go index bfde2ba..b13c87d 100644 --- a/cmd/zurg/main.go +++ b/cmd/zurg/main.go @@ -37,7 +37,23 @@ func main() { }, } - rootCmd.AddCommand(versionCmd, networkTestCmd) + var clearDownloadsCmd = &cobra.Command{ + Use: "clear-downloads", + Short: "Clear all downloads (unrestricted links) in your account", + Run: func(cmd *cobra.Command, args []string) { + internal.ClearDownloads() + }, + } + + var clearTorrentsCmd = &cobra.Command{ + Use: "clear-torrents", + Short: "Clear all torrents in your account", + Run: func(cmd *cobra.Command, args []string) { + internal.ClearTorrents() + }, + } + + rootCmd.AddCommand(versionCmd, networkTestCmd, clearDownloadsCmd, clearTorrentsCmd) if err := rootCmd.Execute(); err != nil { fmt.Println(err) diff --git a/internal/clear/downloads.go b/internal/clear/downloads.go new file mode 100644 index 0000000..60a32f6 --- /dev/null +++ b/internal/clear/downloads.go @@ -0,0 +1,54 @@ +package clear + +import ( + "fmt" + "io" + "net/http" + "strings" + "time" +) + +func ClearDownloads(authCode string) { + for { + req, err := http.NewRequest("GET", "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.") +} diff --git a/internal/clear/torrents.go b/internal/clear/torrents.go new file mode 100644 index 0000000..f60c974 --- /dev/null +++ b/internal/clear/torrents.go @@ -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.") +} diff --git a/internal/commands.go b/internal/commands.go new file mode 100644 index 0000000..5250df3 --- /dev/null +++ b/internal/commands.go @@ -0,0 +1,46 @@ +package internal + +import ( + "bufio" + "fmt" + "os" + "strings" + + "github.com/debridmediamanager/zurg/internal/clear" + "github.com/debridmediamanager/zurg/internal/version" + "github.com/debridmediamanager/zurg/pkg/realdebrid" +) + +func ShowVersion() { + fmt.Printf("zurg\nBuilt At: %s\nCommit: %s\nVersion: %s\n", + version.GetBuiltAt(), version.GetGitCommit(), version.GetVersion()) +} + +func NetworkTest() { + realdebrid.RunTest() +} + +func ClearDownloads() { + authCode := getAuthCode() + clear.ClearDownloads(authCode) +} + +func ClearTorrents() { + authCode := getAuthCode() + clear.ClearTorrents(authCode) +} + +func getAuthCode() string { + fmt.Println("Warning: This will clear all downloads in your account. This cannot be undone.") + fmt.Println("To continue, please enter your auth code. You can find this by logging into your Real-Debrid account, opening the developer console, and running the following javascript code:") + fmt.Println() + fmt.Println(" alert(document.cookie.match(/auth=([^;]+)/)?.[1]||'')") + fmt.Println() + + reader := bufio.NewReader(os.Stdin) + fmt.Print("Enter auth code: ") + + authCode, _ := reader.ReadString('\n') + authCode = strings.TrimSpace(authCode) // Remove newline character + return authCode +} diff --git a/internal/network.go b/internal/network.go deleted file mode 100644 index 6f4b17f..0000000 --- a/internal/network.go +++ /dev/null @@ -1,7 +0,0 @@ -package internal - -import "github.com/debridmediamanager/zurg/pkg/realdebrid" - -func NetworkTest() { - realdebrid.RunTest() -} diff --git a/internal/version.go b/internal/version.go deleted file mode 100644 index 6c1c443..0000000 --- a/internal/version.go +++ /dev/null @@ -1,12 +0,0 @@ -package internal - -import ( - "fmt" - - "github.com/debridmediamanager/zurg/internal/version" -) - -func ShowVersion() { - fmt.Printf("zurg\nBuilt At: %s\nCommit: %s\nVersion: %s\n", - version.GetBuiltAt(), version.GetGitCommit(), version.GetVersion()) -}