diff --git a/pandora/archive/external.py b/pandora/archive/external.py index 510d3f707..1fbe33f32 100644 --- a/pandora/archive/external.py +++ b/pandora/archive/external.py @@ -57,6 +57,8 @@ def get_info(url): info[-1]['tags'] = [] if 'upload_date' in i and i['upload_date']: info[-1]['date'] = '-'.join([i['upload_date'][:4], i['upload_date'][4:6], i['upload_date'][6:]]) + if 'referer' not in info[-1]: + info[-1]['referer'] = url return info def add_subtitles(item, media, tmp): @@ -84,7 +86,7 @@ def add_subtitles(item, media, tmp): sub.selected = True sub.save() -def download(item_id, url): +def download(item_id, url, referer=None): item = Item.objects.get(public_id=item_id) info = get_info(url) if not len(info): @@ -96,6 +98,11 @@ def download(item_id, url): tmp = tmp.decode('utf-8') os.chdir(tmp) cmd = ['youtube-dl', '-q', media['url']] + if referer: + cmd += ['--referer', referer] + elif 'referer' in media: + cmd += ['--referer', media['referer']] + if settings.CONFIG['video'].get('reuseUload', False): max_resolution = max(settings.CONFIG['video']['resolutions']) format = settings.CONFIG['video']['formats'][0] diff --git a/pandora/archive/tasks.py b/pandora/archive/tasks.py index 022cd3776..a2aa3d8ea 100644 --- a/pandora/archive/tasks.py +++ b/pandora/archive/tasks.py @@ -200,8 +200,8 @@ def update_stream(id): c.save() @task(queue="encoding") -def download_media(item_id, url): - return external.download(item_id, url) +def download_media(item_id, url, referer=None): + return external.download(item_id, url, referer) @task(queue='default') def move_media(data, user): diff --git a/pandora/archive/views.py b/pandora/archive/views.py index fd026c1fc..308e7c109 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -745,6 +745,7 @@ def addMediaUrl(request, data): takes { url: string, // url + referer: string // optional referer url item: string // item } returns { @@ -757,7 +758,7 @@ def addMediaUrl(request, data): response = json_response() i = Item.objects.get(public_id=data['item']) Task.start(i, request.user) - t = tasks.download_media.delay(data['item'], data['url']) + t = tasks.download_media.delay(data['item'], data['url'], data.get('referer')) response['data']['taskId'] = t.task_id add_changelog(request, data, data['item']) return render_to_json_response(response) diff --git a/static/js/importMediaDialog.js b/static/js/importMediaDialog.js index 05bfff244..419aeb4e0 100644 --- a/static/js/importMediaDialog.js +++ b/static/js/importMediaDialog.js @@ -132,6 +132,7 @@ pandora.ui.importMediaDialog = function(options) { pandora.api.edit(edit, function(result) { pandora.api.addMediaUrl({ url: info.url, + referer: info.referer, item: edit.id }, function(result) { if (result.data.taskId) {