fix progressbar

fix videos with leading dash
This commit is contained in:
Niko Storni 2021-06-17 19:13:44 +02:00
parent 519e1e4648
commit a0fb4e579e
3 changed files with 15 additions and 11 deletions

View file

@ -50,7 +50,7 @@ func GetVideoInformation(config *sdk.APIConfig, videoID string, stopChan stop.Ch
args := []string{ args := []string{
"--skip-download", "--skip-download",
"--write-info-json", "--write-info-json",
videoID, fmt.Sprintf("https://www.youtube.com/watch?v=%s", videoID),
"--cookies", "--cookies",
"cookies.txt", "cookies.txt",
"-o", "-o",

View file

@ -55,6 +55,9 @@ type Sync struct {
queue chan ytapi.Video queue chan ytapi.Video
defaultAccountID string defaultAccountID string
hardVideoFailure hardVideoFailure hardVideoFailure hardVideoFailure
progressBarWg *sync.WaitGroup
progressBar *mpb.Progress
} }
type hardVideoFailure struct { type hardVideoFailure struct {
@ -177,7 +180,12 @@ func (s *Sync) FullCycle() (e error) {
return err return err
} }
s.progressBarWg = &sync.WaitGroup{}
s.progressBar = mpb.New(mpb.WithWaitGroup(s.progressBarWg))
err = s.doSync() err = s.doSync()
// Waiting for passed &wg and for all bars to complete and flush
s.progressBar.Wait()
if err != nil { if err != nil {
return err return err
} }
@ -814,6 +822,7 @@ func (s *Sync) startWorker(workerNum int) {
default: default:
} }
tryCount++ tryCount++
err := s.processVideo(v) err := s.processVideo(v)
if err != nil { if err != nil {
logUtils.SendErrorToSlack("error processing video %s: %s", v.ID(), err.Error()) 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, Fee: s.DbChannelData.Fee,
DefaultAccount: da, 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) summary, err := v.Sync(s.daemon, sp, &sv, videoRequiresUpgrade, s.walletMux, s.progressBarWg, s.progressBar)
// Waiting for passed &wg and for all bars to complete and flush
p.Wait()
if err != nil { if err != nil {
return err return err
} }

View file

@ -316,7 +316,7 @@ func (v *YoutubeVideo) download() error {
ytdlArgs = append(ytdlArgs, ytdlArgs = append(ytdlArgs,
"--source-address", "--source-address",
sourceAddress, sourceAddress,
v.ID(), fmt.Sprintf("https://www.youtube.com/watch?v=%s", v.id),
) )
for i := 0; i < len(qualities); i++ { for i := 0; i < len(qualities); i++ {
@ -382,9 +382,6 @@ func (v *YoutubeVideo) download() error {
audioSize = f.Filesize 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) log.Debugf("(%s) - videoSize: %d (%s), audiosize: %d (%s)", v.id, videoSize, videoFormat, audioSize, audioFormat)
bar := v.progressBars.AddBar(int64(videoSize+audioSize), bar := v.progressBars.AddBar(int64(videoSize+audioSize),
mpb.PrependDecorators( mpb.PrependDecorators(
@ -414,6 +411,9 @@ func (v *YoutubeVideo) download() error {
return return
} }
bar.SetCurrent(size) bar.SetCurrent(size)
if size > int64(videoSize+audioSize) {
bar.SetTotal(size+2048, false)
}
bar.DecoratorEwmaUpdate(400 * time.Millisecond) bar.DecoratorEwmaUpdate(400 * time.Millisecond)
} }
} }