From a0fb4e579e4bba080da1d56edea99f85c14bd733 Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Thu, 17 Jun 2021 19:13:44 +0200 Subject: [PATCH] fix progressbar fix videos with leading dash --- downloader/downloader.go | 2 +- manager/ytsync.go | 16 ++++++++++------ sources/youtubeVideo.go | 8 ++++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/downloader/downloader.go b/downloader/downloader.go index ff79863..7eed7bd 100644 --- a/downloader/downloader.go +++ b/downloader/downloader.go @@ -50,7 +50,7 @@ func GetVideoInformation(config *sdk.APIConfig, videoID string, stopChan stop.Ch args := []string{ "--skip-download", "--write-info-json", - videoID, + fmt.Sprintf("https://www.youtube.com/watch?v=%s", videoID), "--cookies", "cookies.txt", "-o", diff --git a/manager/ytsync.go b/manager/ytsync.go index f5ac4f0..33bd1a3 100644 --- a/manager/ytsync.go +++ b/manager/ytsync.go @@ -55,6 +55,9 @@ type Sync struct { queue chan ytapi.Video defaultAccountID string hardVideoFailure hardVideoFailure + + progressBarWg *sync.WaitGroup + progressBar *mpb.Progress } type hardVideoFailure struct { @@ -177,7 +180,12 @@ func (s *Sync) FullCycle() (e error) { return err } + s.progressBarWg = &sync.WaitGroup{} + s.progressBar = mpb.New(mpb.WithWaitGroup(s.progressBarWg)) + err = s.doSync() + // Waiting for passed &wg and for all bars to complete and flush + s.progressBar.Wait() if err != nil { return err } @@ -814,6 +822,7 @@ func (s *Sync) startWorker(workerNum int) { default: } tryCount++ + err := s.processVideo(v) if err != nil { logUtils.SendErrorToSlack("error processing video %s: %s", v.ID(), err.Error()) @@ -986,13 +995,8 @@ func (s *Sync) processVideo(v ytapi.Video) (err error) { Fee: s.DbChannelData.Fee, DefaultAccount: da, } - var pbWg sync.WaitGroup - // passed &wg will be accounted at p.Wait() call - p := mpb.New(mpb.WithWaitGroup(&pbWg)) - summary, err := v.Sync(s.daemon, sp, &sv, videoRequiresUpgrade, s.walletMux, &pbWg, p) - // Waiting for passed &wg and for all bars to complete and flush - p.Wait() + summary, err := v.Sync(s.daemon, sp, &sv, videoRequiresUpgrade, s.walletMux, s.progressBarWg, s.progressBar) if err != nil { return err } diff --git a/sources/youtubeVideo.go b/sources/youtubeVideo.go index 080c377..930adef 100644 --- a/sources/youtubeVideo.go +++ b/sources/youtubeVideo.go @@ -316,7 +316,7 @@ func (v *YoutubeVideo) download() error { ytdlArgs = append(ytdlArgs, "--source-address", sourceAddress, - v.ID(), + fmt.Sprintf("https://www.youtube.com/watch?v=%s", v.id), ) for i := 0; i < len(qualities); i++ { @@ -382,9 +382,6 @@ func (v *YoutubeVideo) download() error { audioSize = f.Filesize } } - if audioSize+videoSize == 0 { - videoSize = 50 * 1024 * 1024 - } log.Debugf("(%s) - videoSize: %d (%s), audiosize: %d (%s)", v.id, videoSize, videoFormat, audioSize, audioFormat) bar := v.progressBars.AddBar(int64(videoSize+audioSize), mpb.PrependDecorators( @@ -414,6 +411,9 @@ func (v *YoutubeVideo) download() error { return } bar.SetCurrent(size) + if size > int64(videoSize+audioSize) { + bar.SetTotal(size+2048, false) + } bar.DecoratorEwmaUpdate(400 * time.Millisecond) } }