Skip to content

Commit

Permalink
Simplify downloads when less streams is required
Browse files Browse the repository at this point in the history
Workaround for #12
  • Loading branch information
zhuyifei1999 committed Mar 25, 2016
1 parent e83f385 commit 0b8cced
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions backend/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self, desc):
@app.task(bind=True, track_started=True)
def main(
self, url, ie_key, subtitles, filename, filedesc,
convertkey, username, oauth
downloadkey, convertkey, username, oauth
):
"""Main worker code."""
# Get a lock to prevent double-running with same task ID
Expand Down Expand Up @@ -101,7 +101,7 @@ def errorcallback(text):
try:
statuscallback('Downloading...', -1)
d = download.download(
url, ie_key, 'bestvideo+bestaudio/best', subtitles,
url, ie_key, downloadkey, subtitles,
outputdir, statuscallback, errorcallback
)
if not d:
Expand Down
22 changes: 19 additions & 3 deletions www/python/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def submit_task():


def relist_formats(id):
"""List the possible convert formats from a given audio/vidio pair."""
"""List the possible convert formats from a given audio/video pair."""
formats = []
prefer = ''
if not session['newtasks'][id]['video'] and \
Expand All @@ -457,8 +457,22 @@ def relist_formats(id):
session['newtasks'][id]['formats'] = formats


def get_download_key(format):
"""Get the youtube-dl download format key."""
return {
'ogv (Theora)': 'bestvideo/best',
'webm (VP8)': 'bestvideo/best',
'webm (VP9, experimental)': 'bestvideo/best',
'ogg (Vorbis)': 'bestaudio/best',
'opus (Opus, experimental)': 'bestaudio/best',
'ogv (Theora/Vorbis)': 'bestvideo+bestaudio/best',
'webm (VP8/Vorbis)': 'bestvideo+bestaudio/best',
'webm (VP9/Opus, experimental)': 'bestvideo+bestaudio/best',
}[format]


def get_convert_key(format):
"""Get the backnd convert key from human-readable convert format."""
"""Get the backend convert key from human-readable convert format."""
return {
'ogv (Theora)': 'an.ogv',
'webm (VP8)': 'an.webm',
Expand Down Expand Up @@ -586,12 +600,14 @@ def run_task(id):
subtitles = session['newtasks'][id]['subtitles']
filename = session['newtasks'][id]['filename']
filedesc = session['newtasks'][id]['filedesc']
downloadkey = get_download_key(session['newtasks'][id]['format'])
convertkey = get_convert_key(session['newtasks'][id]['format'])
username = session['username']
oauth = (session['access_token_key'], session['access_token_secret'])

taskid = run_task_internal(filename, (
url, ie_key, subtitles, filename, filedesc, convertkey, username, oauth
url, ie_key, subtitles, filename, filedesc,
downloadkey, convertkey, username, oauth
))

del session['newtasks'][id]
Expand Down

0 comments on commit 0b8cced

Please sign in to comment.