Proper logging and fixing for unavailable files
This commit is contained in:
@@ -85,18 +85,21 @@ 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 yet available, zurg is repairing the torrent", filename)
|
||||
gf.playErrorVideo("https://www.youtube.com/watch?v=bGTqwt6vdcY", w, r, t, c, log)
|
||||
log.Warnf("File %s is not available", filename)
|
||||
gf.playErrorVideo(file, "https://www.youtube.com/watch?v=bGTqwt6vdcY", w, r, t, c, log)
|
||||
return
|
||||
}
|
||||
link := file.Link
|
||||
|
||||
resp := t.UnrestrictUntilOk(link)
|
||||
if resp == nil {
|
||||
log.Warnf("File %s is no longer available, file is marked for repair", filepath.Base(file.Path))
|
||||
log.Warnf("File %s is no longer available", filepath.Base(file.Path))
|
||||
file.Link = "repair"
|
||||
t.SetChecksum("") // force a recheck
|
||||
gf.playErrorVideo("https://www.youtube.com/watch?v=gea_FJrtFVA", w, r, t, c, log)
|
||||
if c.EnableRepair() {
|
||||
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)
|
||||
} else {
|
||||
if resp.Filename != filename {
|
||||
// this is possible if there's only 1 streamable file in the torrent
|
||||
@@ -105,7 +108,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("https://www.youtube.com/watch?v=t9VgOriBHwE", w, r, t, c, log)
|
||||
gf.playErrorVideo(file, "https://www.youtube.com/watch?v=t9VgOriBHwE", w, r, t, c, log)
|
||||
return
|
||||
} else {
|
||||
log.Warnf("Filename mismatch: %s and %s", filename, resp.Filename)
|
||||
@@ -128,7 +131,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("https://www.youtube.com/watch?v=H3NSrObyAxM", w, r, torMgr, cfg, log)
|
||||
gf.playErrorVideo(file, "https://www.youtube.com/watch?v=H3NSrObyAxM", w, r, torMgr, cfg, log)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -140,22 +143,28 @@ func (gf *GetFile) streamFileToResponse(file *intTor.File, url string, w http.Re
|
||||
resp, err := gf.client.Do(req)
|
||||
if err != nil {
|
||||
if file != nil {
|
||||
log.Warnf("Cannot download file %s, file is marked for repair: %v", file.Path, err)
|
||||
log.Warnf("Cannot download file %s: %v", file.Path, err)
|
||||
file.Link = "repair"
|
||||
torMgr.SetChecksum("") // force a recheck
|
||||
if cfg.EnableRepair() {
|
||||
log.Debugf("File %s is marked for repair", filepath.Base(file.Path))
|
||||
torMgr.SetChecksum("") // force a recheck
|
||||
}
|
||||
}
|
||||
gf.playErrorVideo("https://www.youtube.com/watch?v=FSSd8cponAA", w, r, torMgr, cfg, log)
|
||||
gf.playErrorVideo(file, "https://www.youtube.com/watch?v=FSSd8cponAA", w, r, torMgr, cfg, log)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusPartialContent {
|
||||
if file != nil {
|
||||
log.Warnf("Received a %s status code for file %s, file is marked for repair", resp.Status, file.Path)
|
||||
log.Warnf("Received a %s status code for file %s", resp.Status, file.Path)
|
||||
file.Link = "repair"
|
||||
torMgr.SetChecksum("") // force a recheck
|
||||
if cfg.EnableRepair() {
|
||||
log.Debugf("File %s is marked for repair", filepath.Base(file.Path))
|
||||
torMgr.SetChecksum("") // force a recheck
|
||||
}
|
||||
}
|
||||
gf.playErrorVideo("https://www.youtube.com/watch?v=BcseUxviVqE", w, r, torMgr, cfg, log)
|
||||
gf.playErrorVideo(file, "https://www.youtube.com/watch?v=BcseUxviVqE", w, r, torMgr, cfg, log)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -169,13 +178,14 @@ func (gf *GetFile) streamFileToResponse(file *intTor.File, url string, w http.Re
|
||||
io.CopyBuffer(w, resp.Body, buf)
|
||||
}
|
||||
|
||||
func (gf *GetFile) playErrorVideo(link string, w http.ResponseWriter, r *http.Request, t *intTor.TorrentManager, c config.ConfigInterface, log *zap.SugaredLogger) {
|
||||
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", link)
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user