Skip to content

Commit

Permalink
fix progressbar
Browse files Browse the repository at this point in the history
fix videos with leading dash
  • Loading branch information
nikooo777 committed Jun 17, 2021
1 parent 519e1e4 commit a0fb4e5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 10 additions & 6 deletions manager/ytsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ type Sync struct {
queue chan ytapi.Video
defaultAccountID string
hardVideoFailure hardVideoFailure

progressBarWg *sync.WaitGroup
progressBar *mpb.Progress
}

type hardVideoFailure struct {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions sources/youtubeVideo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit a0fb4e5

Please sign in to comment.