Proper logging and fixing for unavailable files
This commit is contained in:
@@ -72,7 +72,7 @@ func handleListTorrents(w http.ResponseWriter, requestPath string, t *torrent.To
|
|||||||
|
|
||||||
var allTorrents []*torrent.Torrent
|
var allTorrents []*torrent.Torrent
|
||||||
torrents.IterCb(func(_ string, tor *torrent.Torrent) {
|
torrents.IterCb(func(_ string, tor *torrent.Torrent) {
|
||||||
if tor.InProgress() {
|
if tor.AllInProgress() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
allTorrents = append(allTorrents, tor)
|
allTorrents = append(allTorrents, tor)
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ func handleListOfTorrents(requestPath string, t *torrent.TorrentManager) (*strin
|
|||||||
|
|
||||||
var allTorrents []*torrent.Torrent
|
var allTorrents []*torrent.Torrent
|
||||||
torrents.IterCb(func(_ string, tor *torrent.Torrent) {
|
torrents.IterCb(func(_ string, tor *torrent.Torrent) {
|
||||||
if tor.InProgress() {
|
if tor.AllInProgress() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
allTorrents = append(allTorrents, tor)
|
allTorrents = append(allTorrents, tor)
|
||||||
|
|||||||
@@ -538,7 +538,7 @@ func (t *TorrentManager) repairAll() {
|
|||||||
|
|
||||||
allTorrents, _ := t.DirectoryMap.Get(ALL_TORRENTS)
|
allTorrents, _ := t.DirectoryMap.Get(ALL_TORRENTS)
|
||||||
allTorrents.IterCb(func(_ string, torrent *Torrent) {
|
allTorrents.IterCb(func(_ string, torrent *Torrent) {
|
||||||
if torrent.InProgress() {
|
if torrent.AnyInProgress() {
|
||||||
t.log.Debugf("Skipping %s for repairs because it is in progress", torrent.AccessKey)
|
t.log.Debugf("Skipping %s for repairs because it is in progress", torrent.AccessKey)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -588,7 +588,7 @@ func (t *TorrentManager) Repair(accessKey string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if torrent.InProgress() {
|
if torrent.AnyInProgress() {
|
||||||
t.log.Infof("Torrent %s is in progress, cannot repair", torrent.AccessKey)
|
t.log.Infof("Torrent %s is in progress, cannot repair", torrent.AccessKey)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ type Torrent struct {
|
|||||||
Instances []realdebrid.TorrentInfo
|
Instances []realdebrid.TorrentInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Torrent) InProgress() bool {
|
func (t *Torrent) AnyInProgress() bool {
|
||||||
for _, instance := range t.Instances {
|
for _, instance := range t.Instances {
|
||||||
if instance.Progress < 100 {
|
if instance.Progress < 100 {
|
||||||
return true
|
return true
|
||||||
@@ -22,6 +22,16 @@ func (t *Torrent) InProgress() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Torrent) AllInProgress() bool {
|
||||||
|
count := 0
|
||||||
|
for _, instance := range t.Instances {
|
||||||
|
if instance.Progress < 100 {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count == len(t.Instances)
|
||||||
|
}
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
realdebrid.File
|
realdebrid.File
|
||||||
Added string
|
Added string
|
||||||
|
|||||||
@@ -85,18 +85,21 @@ 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 yet available, zurg is repairing the torrent", filename)
|
log.Warnf("File %s is not available", filename)
|
||||||
gf.playErrorVideo("https://www.youtube.com/watch?v=bGTqwt6vdcY", w, r, t, c, log)
|
gf.playErrorVideo(file, "https://www.youtube.com/watch?v=bGTqwt6vdcY", w, r, t, c, log)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
link := file.Link
|
link := file.Link
|
||||||
|
|
||||||
resp := t.UnrestrictUntilOk(link)
|
resp := t.UnrestrictUntilOk(link)
|
||||||
if resp == nil {
|
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"
|
file.Link = "repair"
|
||||||
|
if c.EnableRepair() {
|
||||||
|
log.Debugf("File %s is marked for repair", filepath.Base(file.Path))
|
||||||
t.SetChecksum("") // force a recheck
|
t.SetChecksum("") // force a recheck
|
||||||
gf.playErrorVideo("https://www.youtube.com/watch?v=gea_FJrtFVA", w, r, t, c, log)
|
}
|
||||||
|
gf.playErrorVideo(file, "https://www.youtube.com/watch?v=gea_FJrtFVA", w, r, t, c, log)
|
||||||
} 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
|
||||||
@@ -105,7 +108,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("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
|
return
|
||||||
} else {
|
} else {
|
||||||
log.Warnf("Filename mismatch: %s and %s", filename, resp.Filename)
|
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 {
|
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("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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,22 +143,28 @@ func (gf *GetFile) streamFileToResponse(file *intTor.File, url string, w http.Re
|
|||||||
resp, err := gf.client.Do(req)
|
resp, err := gf.client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if file != 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"
|
file.Link = "repair"
|
||||||
|
if cfg.EnableRepair() {
|
||||||
|
log.Debugf("File %s is marked for repair", filepath.Base(file.Path))
|
||||||
torMgr.SetChecksum("") // force a recheck
|
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
|
return
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusPartialContent {
|
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusPartialContent {
|
||||||
if file != nil {
|
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"
|
file.Link = "repair"
|
||||||
|
if cfg.EnableRepair() {
|
||||||
|
log.Debugf("File %s is marked for repair", filepath.Base(file.Path))
|
||||||
torMgr.SetChecksum("") // force a recheck
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,13 +178,14 @@ 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(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)
|
resp := t.UnrestrictUntilOk(link)
|
||||||
if resp == nil {
|
if resp == nil {
|
||||||
http.Error(w, "REAL-DEBRID IS DOWN", http.StatusInternalServerError)
|
http.Error(w, "REAL-DEBRID IS DOWN", http.StatusInternalServerError)
|
||||||
return
|
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() {
|
if c.ShouldServeFromRclone() {
|
||||||
redirect(w, r, resp.Download, c)
|
redirect(w, r, resp.Download, c)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user