pass referer to video download

This commit is contained in:
j 2020-11-08 22:29:24 +01:00
parent 5d6e753b05
commit 4cf28434eb
4 changed files with 13 additions and 4 deletions

View file

@ -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]

View file

@ -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):

View file

@ -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)

View file

@ -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) {