From f4a3b266fb94181ef4a1fd0026115aa1d328f3c4 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Sat, 2 Apr 2016 15:33:20 -0700 Subject: [PATCH] more updates to new progress bar UI thanks again @kevinmarks, this is shaping up great! --- app.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/app.py b/app.py index 8253cb5..f9825f6 100755 --- a/app.py +++ b/app.py @@ -26,6 +26,10 @@ def read(filename): S3_BUCKET = 'huffduff-video' S3_BASE = 'https://%s.s3-us-west-2.amazonaws.com/' % S3_BUCKET +# ffmpeg on Ryan's laptop is installed in /usr/local/bin, so add it to PATH. +if '/usr/local/bin' not in os.environ['PATH']: + os.environ['PATH'] += ':/usr/local/bin' + def application(environ, start_response): """Hand-rolled WSGI application so I can stream output. @@ -62,9 +66,6 @@ def run(): -

huffduff-video

@@ -73,17 +74,22 @@ def run(): # function to print out status while downloading def download_progress_hook(progress): status = progress.get('status') - if status in ('finished', 'error'): + if status == 'finished': + msg = '
Extracting audio (this can take a while)...\n' + elif status == 'error': # we always get an 'error' progress when the video finishes downloading. # not sure why. ignore it. return elif status == 'downloading': p = lambda field: progress.get(field) or '' - msg = ' of %s at %s in %s...' % ( - p('_percent_str'), p('_total_bytes_str') or p('_total_bytes_estimate_str'), - p('_speed_str'), p('_eta_str')) + percent = float(p('_percent_str').strip('%') or '0') + msg = ('
' + '%s of %s at %s in %s...
\n' % ( + percent, p('_downloaded_bytes_str'), + p('_total_bytes_str') or p('_total_bytes_estimate_str'), + p('_speed_str'), p('_eta_str'))) else: - msg = status+ '
\n' + msg = status + '
\n' write(msg) # fetch video info (resolves URL) to see if we've already downloaded it @@ -127,7 +133,7 @@ def download_progress_hook(progress): yield 'Already downloaded!
\n' else: # download video and extract mp3 - yield 'Downloading and extracting audio...
\n' + yield 'Downloading...
\n' with handle_errors(write): youtube_dl.YoutubeDL(options).download([url]) @@ -136,7 +142,9 @@ def download_progress_hook(progress): yield 'Uploading to S3...
\n' def upload_callback(sent, total): - write(' \n' % (sent * 100 / total)) + write('
' + '%.2fMB of %.2fMB
\n' % ( + (sent * 100 / total), float(sent) / 1000000, float(total) / 1000000)) key.set_contents_from_filename(filename, cb=upload_callback) key.make_public() @@ -159,7 +167,7 @@ def upload_callback(sent, total): description += footer # open 'Huffduff it' page - yield """Opening Huffduffer dialog... + yield """\n
Opening Huffduffer dialog...