diff --git a/README.md b/README.md index f64d856..9316259 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,10 @@ concurrent_workers: 10 # the higher the number the faster zurg runs through your check_for_changes_every_secs: 15 # zurg polls real-debrid for changes in your library info_cache_time_hours: 12 # how long do we want to check if a torrent is still alive or dead? 12 to 24 hours is good enough -# repair fixes broken links, but it doesn't mean it will appear on the same location (especially if there's only 1 episode missing) +# zurg can repair broken links, but it doesn't mean it will appear on the same location (especially if there's only 1 episode missing) +# e.g. i was missing e06 of Better.Call.Saul.S03.2160p.NF.WEBRip.DD5.1.x264-ViSUM +# after zurg re-added the file, it appeared on a different directory: +# Better.Call.Saul.S03E06.2160p.NF.WEBRip.DD5.1.x264-ViSUM.mkv enable_repair: false # BEWARE! THERE CAN ONLY BE 1 INSTANCE OF ZURG THAT SHOULD REPAIR YOUR TORRENTS # List of directory definitions and their filtering rules diff --git a/internal/dav/getfile.go b/internal/dav/getfile.go index b42c7c5..1cf3651 100644 --- a/internal/dav/getfile.go +++ b/internal/dav/getfile.go @@ -1,7 +1,6 @@ package dav import ( - "fmt" "log" "net/http" "path" @@ -40,15 +39,15 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torrent torrents := t.FindAllTorrentsWithName(baseDirectory, torrentName) if torrents == nil { - log.Println("Cannot find torrent", torrentName) + log.Println("Cannot find torrent", requestPath) http.Error(w, "Cannot find file", http.StatusNotFound) return } filenameV2, linkFragment := davextra.ExtractLinkFragment(filename) - torrent, file := getFile(torrents, filenameV2, linkFragment) + _, file := getFile(torrents, filenameV2, linkFragment) if file == nil { - log.Println("Cannot find file", filename) + log.Println("Cannot find file", requestPath) http.Error(w, "Cannot find file", http.StatusNotFound) return } @@ -65,8 +64,8 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torrent resp := realdebrid.RetryUntilOk(unrestrictFn) if resp == nil { log.Println("Cannot unrestrict link", link, filenameV2) - t.MarkFileAsDeleted(torrent, file) - http.Error(w, "Cannot find file", http.StatusNotFound) + // t.HideTheFile(torrent, file) + http.Redirect(w, r, "https://send.nukes.wtf/tDeTd0", http.StatusFound) return } if resp.Filename != filenameV2 { @@ -87,7 +86,7 @@ func getFile(torrents []torrent.Torrent, filename, fragment string) (*torrent.To for t := range torrents { for f, file := range torrents[t].SelectedFiles { fname := filepath.Base(file.Path) - if filename == fname && strings.HasPrefix(file.Link, fmt.Sprintf("https://real-debrid.com/d/%s", fragment)) { + if filename == fname && strings.Contains(file.Link, fragment) { return &torrents[t], &torrents[t].SelectedFiles[f] } } diff --git a/internal/http/get.go b/internal/http/get.go index f86f1a4..5d1e8bd 100644 --- a/internal/http/get.go +++ b/internal/http/get.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "net/http" + "net/url" "path" "path/filepath" "strings" @@ -17,7 +18,7 @@ import ( func HandleHeadRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, c config.ConfigInterface, cache *expirable.LRU[string, string]) { requestPath := path.Clean(r.URL.Path) - requestPath = strings.Replace(requestPath, "/http", "/", 1) + requestPath = strings.Replace(requestPath, "/http", "", 1) if requestPath == "/favicon.ico" { return } @@ -46,7 +47,7 @@ func HandleHeadRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torren torrents := t.FindAllTorrentsWithName(baseDirectory, torrentName) if torrents == nil { - log.Println("Cannot find torrent", torrentName, segments) + log.Println("Cannot find torrent", requestPath) http.Error(w, "Cannot find file", http.StatusNotFound) return } @@ -54,12 +55,12 @@ func HandleHeadRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torren filenameV2, linkFragment := davextra.ExtractLinkFragment(filename) _, file := getFile(torrents, filenameV2, linkFragment) if file == nil { - log.Println("Cannot find file", filename, segments) + log.Println("Cannot find file (head)", requestPath) http.Error(w, "Cannot find file", http.StatusNotFound) return } if file.Link == "" { - log.Println("Link not found", filename) + log.Println("Link not found 222", filename) http.Error(w, "Cannot find file", http.StatusNotFound) return } @@ -117,20 +118,20 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torrent torrents := t.FindAllTorrentsWithName(baseDirectory, torrentName) if torrents == nil { - log.Println("Cannot find torrent", torrentName) + log.Println("Cannot find torrent", requestPath) http.Error(w, "Cannot find file", http.StatusNotFound) return } filenameV2, linkFragment := davextra.ExtractLinkFragment(filename) - torrent, file := getFile(torrents, filenameV2, linkFragment) + _, file := getFile(torrents, filenameV2, linkFragment) if file == nil { - log.Println("Cannot find file", filename) + log.Println("Cannot find file (get)", requestPath) http.Error(w, "Cannot find file", http.StatusNotFound) return } if file.Link == "" { - log.Println("Link not found", filename) + log.Println("Link not found 33", filename) http.Error(w, "Cannot find file", http.StatusNotFound) return } @@ -142,8 +143,9 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torrent resp := realdebrid.RetryUntilOk(unrestrictFn) if resp == nil { log.Println("Cannot unrestrict link", link, filenameV2) - t.MarkFileAsDeleted(torrent, file) - http.Error(w, "Cannot find file", http.StatusNotFound) + // t.HideTheFile(torrent, file) + // http.Error(w, "Cannot find file", http.StatusNotFound) + http.Redirect(w, r, "https://send.nukes.wtf/tDeTd0", http.StatusFound) return } if resp.Filename != filenameV2 { @@ -163,8 +165,12 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torrent func getFile(torrents []torrent.Torrent, filename, fragment string) (*torrent.Torrent, *torrent.File) { for t := range torrents { for f, file := range torrents[t].SelectedFiles { + // fmt.Println("~~~~~~~~~~~~~~", torrents[t].Version) + if torrents[t].ID == "ABUNEKZP3UPMU" || torrents[t].ID == "TAA5WUJ6BVEAE" { + fmt.Println("~~~~~~~~~~~~~~", torrents[t].ID, torrents[t].Version, len(torrents[t].Links), len(file.Link)) + } fname := filepath.Base(file.Path) - if filename == fname && strings.HasPrefix(file.Link, fmt.Sprintf("https://real-debrid.com/d/%s", fragment)) { + if filename == fname && strings.Contains(file.Link, fragment) { return &torrents[t], &torrents[t].SelectedFiles[f] } } @@ -219,7 +225,8 @@ func handleRoot(w http.ResponseWriter, r *http.Request, c config.ConfigInterface htmlDoc := "