From 5e5e337387925f13a8d708d58973407cc70f3ec8 Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Sun, 26 Nov 2023 15:08:02 +0100 Subject: [PATCH] Return errors instead of error videos --- internal/universal/get.go | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/internal/universal/get.go b/internal/universal/get.go index f640e29..ccddb0a 100644 --- a/internal/universal/get.go +++ b/internal/universal/get.go @@ -86,7 +86,7 @@ func (gf *GetFile) HandleGetRequest(w http.ResponseWriter, r *http.Request, t *i if !strings.HasPrefix(file.Link, "http") { // This is a dead file, serve an alternate file log.Warnf("File %s is not available", filename) - gf.playErrorVideo(file, "https://www.youtube.com/watch?v=bGTqwt6vdcY", w, r, t, c, log) + http.Error(w, "File is not available", http.StatusNotFound) return } link := file.Link @@ -99,7 +99,8 @@ func (gf *GetFile) HandleGetRequest(w http.ResponseWriter, r *http.Request, t *i log.Debugf("File %s is marked for repair", filepath.Base(file.Path)) t.SetChecksum("") // force a recheck } - gf.playErrorVideo(file, "https://www.youtube.com/watch?v=gea_FJrtFVA", w, r, t, c, log) + http.Error(w, "File is not available", http.StatusNotFound) + return } else { if resp.Filename != filename { // this is possible if there's only 1 streamable file in the torrent @@ -108,7 +109,7 @@ func (gf *GetFile) HandleGetRequest(w http.ResponseWriter, r *http.Request, t *i expectedExt := filepath.Ext(filename) if actualExt != expectedExt && resp.Streamable != 1 { log.Warnf("File was changed and is not streamable: %s and %s", filename, resp.Filename) - gf.playErrorVideo(file, "https://www.youtube.com/watch?v=t9VgOriBHwE", w, r, t, c, log) + http.Error(w, "File is not available", http.StatusNotFound) return } else { log.Warnf("Filename mismatch: %s and %s", filename, resp.Filename) @@ -131,7 +132,7 @@ func (gf *GetFile) streamFileToResponse(file *intTor.File, url string, w http.Re if file != nil { log.Errorf("Error creating new request for file %s: %v", file.Path, err) } - gf.playErrorVideo(file, "https://www.youtube.com/watch?v=H3NSrObyAxM", w, r, torMgr, cfg, log) + http.Error(w, "File is not available", http.StatusNotFound) return } @@ -150,7 +151,7 @@ func (gf *GetFile) streamFileToResponse(file *intTor.File, url string, w http.Re torMgr.SetChecksum("") // force a recheck } } - gf.playErrorVideo(file, "https://www.youtube.com/watch?v=FSSd8cponAA", w, r, torMgr, cfg, log) + http.Error(w, "File is not available", http.StatusNotFound) return } defer resp.Body.Close() @@ -164,7 +165,7 @@ func (gf *GetFile) streamFileToResponse(file *intTor.File, url string, w http.Re torMgr.SetChecksum("") // force a recheck } } - gf.playErrorVideo(file, "https://www.youtube.com/watch?v=BcseUxviVqE", w, r, torMgr, cfg, log) + http.Error(w, "File is not available", http.StatusNotFound) return } @@ -178,21 +179,6 @@ func (gf *GetFile) streamFileToResponse(file *intTor.File, url string, w http.Re io.CopyBuffer(w, resp.Body, buf) } -func (gf *GetFile) playErrorVideo(file *intTor.File, link string, w http.ResponseWriter, r *http.Request, t *intTor.TorrentManager, c config.ConfigInterface, log *zap.SugaredLogger) { - resp := t.UnrestrictUntilOk(link) - if resp == nil { - http.Error(w, "REAL-DEBRID IS DOWN", http.StatusInternalServerError) - return - } - log.Debugf("Serving error video %s for file %s", link, filepath.Base(file.Path)) - file.Bytes = resp.Filesize - if c.ShouldServeFromRclone() { - redirect(w, r, resp.Download, c) - } else { - gf.streamFileToResponse(nil, resp.Download, w, r, t, c, log) - } -} - func redirect(w http.ResponseWriter, r *http.Request, url string, c config.ConfigInterface) { prefHost := c.GetRandomPreferredHost() if prefHost != "" {