Return errors instead of error videos
This commit is contained in:
@@ -86,7 +86,7 @@ func (gf *GetFile) HandleGetRequest(w http.ResponseWriter, r *http.Request, t *i
|
|||||||
if !strings.HasPrefix(file.Link, "http") {
|
if !strings.HasPrefix(file.Link, "http") {
|
||||||
// This is a dead file, serve an alternate file
|
// This is a dead file, serve an alternate file
|
||||||
log.Warnf("File %s is not available", filename)
|
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
|
return
|
||||||
}
|
}
|
||||||
link := file.Link
|
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))
|
log.Debugf("File %s is marked for repair", filepath.Base(file.Path))
|
||||||
t.SetChecksum("") // force a recheck
|
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 {
|
} else {
|
||||||
if resp.Filename != filename {
|
if resp.Filename != filename {
|
||||||
// this is possible if there's only 1 streamable file in the torrent
|
// 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)
|
expectedExt := filepath.Ext(filename)
|
||||||
if actualExt != expectedExt && resp.Streamable != 1 {
|
if actualExt != expectedExt && resp.Streamable != 1 {
|
||||||
log.Warnf("File was changed and is not streamable: %s and %s", filename, resp.Filename)
|
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
|
return
|
||||||
} else {
|
} else {
|
||||||
log.Warnf("Filename mismatch: %s and %s", filename, resp.Filename)
|
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 {
|
if file != nil {
|
||||||
log.Errorf("Error creating new request for file %s: %v", file.Path, err)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +151,7 @@ func (gf *GetFile) streamFileToResponse(file *intTor.File, url string, w http.Re
|
|||||||
torMgr.SetChecksum("") // force a recheck
|
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
|
return
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
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
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,21 +179,6 @@ func (gf *GetFile) streamFileToResponse(file *intTor.File, url string, w http.Re
|
|||||||
io.CopyBuffer(w, resp.Body, buf)
|
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) {
|
func redirect(w http.ResponseWriter, r *http.Request, url string, c config.ConfigInterface) {
|
||||||
prefHost := c.GetRandomPreferredHost()
|
prefHost := c.GetRandomPreferredHost()
|
||||||
if prefHost != "" {
|
if prefHost != "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user