Add clear downloads and clear torrents command
This commit is contained in:
@@ -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 {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|||||||
54
internal/clear/downloads.go
Normal file
54
internal/clear/downloads.go
Normal file
@@ -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.")
|
||||||
|
}
|
||||||
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.")
|
||||||
|
}
|
||||||
46
internal/commands.go
Normal file
46
internal/commands.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package internal
|
|
||||||
|
|
||||||
import "github.com/debridmediamanager/zurg/pkg/realdebrid"
|
|
||||||
|
|
||||||
func NetworkTest() {
|
|
||||||
realdebrid.RunTest()
|
|
||||||
}
|
|
||||||
@@ -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())
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user