patch youtube API lies

This commit is contained in:
Niko Storni 2019-01-11 20:15:17 +01:00
parent 94c9e91bc7
commit 9e102a3298
2 changed files with 11 additions and 5 deletions

View file

@ -108,7 +108,7 @@ func (v *YoutubeVideo) download() error {
_, err = os.Stat(videoPath) _, err = os.Stat(videoPath)
if err != nil && !os.IsNotExist(err) { if err != nil && !os.IsNotExist(err) {
return err return errors.Err(err)
} else if err == nil { } else if err == nil {
log.Debugln(v.id + " already exists at " + videoPath) log.Debugln(v.id + " already exists at " + videoPath)
return nil return nil
@ -117,7 +117,7 @@ func (v *YoutubeVideo) download() error {
videoUrl := "https://www.youtube.com/watch?v=" + v.id videoUrl := "https://www.youtube.com/watch?v=" + v.id
videoInfo, err := ytdl.GetVideoInfo(videoUrl) videoInfo, err := ytdl.GetVideoInfo(videoUrl)
if err != nil { if err != nil {
return err return errors.Err(err)
} }
codec := []string{"H.264"} codec := []string{"H.264"}
@ -153,7 +153,7 @@ func (v *YoutubeVideo) download() error {
var downloadedFile *os.File var downloadedFile *os.File
downloadedFile, err = os.Create(videoPath) downloadedFile, err = os.Create(videoPath)
if err != nil { if err != nil {
return err return errors.Err(err)
} }
err = videoInfo.Download(formats[formatIndex], downloadedFile) err = videoInfo.Download(formats[formatIndex], downloadedFile)
downloadedFile.Close() downloadedFile.Close()
@ -164,7 +164,7 @@ func (v *YoutubeVideo) download() error {
} }
fi, err := os.Stat(v.getFullPath()) fi, err := os.Stat(v.getFullPath())
if err != nil { if err != nil {
return err return errors.Err(err)
} }
videoSize := fi.Size() videoSize := fi.Size()
v.size = &videoSize v.size = &videoSize
@ -178,7 +178,7 @@ func (v *YoutubeVideo) download() error {
break break
} }
} }
return err return errors.Err(err)
} }
func (v *YoutubeVideo) videoDir() string { func (v *YoutubeVideo) videoDir() string {

View file

@ -672,6 +672,12 @@ func (s *Sync) enqueueYoutubeVideos() error {
} }
if len(playlistResponse.Items) < 1 { if len(playlistResponse.Items) < 1 {
// If there are 50+ videos in a playlist but less than 50 are actually returned by the API, youtube will still redirect
// clients to a next page. Such next page will however be empty. This logic prevents ytsync from failing.
youtubeIsLying := len(videos) > 0
if youtubeIsLying {
break
}
return errors.Err("playlist items not found") return errors.Err("playlist items not found")
} }