1
0
Fork 0
mirror of https://gitlab.com/dstftw/youtube-dl.git synced 2020-11-16 09:42:26 +00:00

[funk] Fix extraction (closes #16918)

This commit is contained in:
Sergey M․ 2018-07-06 23:49:36 +07:00
parent 4e71dfd819
commit 4742150788
No known key found for this signature in database
GPG key ID: 2C393E0F18A9236D

View file

@ -5,6 +5,7 @@ import re
from .common import InfoExtractor from .common import InfoExtractor
from .nexx import NexxIE from .nexx import NexxIE
from ..compat import compat_str
from ..utils import ( from ..utils import (
int_or_none, int_or_none,
try_get, try_get,
@ -12,6 +13,19 @@ from ..utils import (
class FunkBaseIE(InfoExtractor): class FunkBaseIE(InfoExtractor):
_HEADERS = {
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.9,ru;q=0.8',
'authorization': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGllbnROYW1lIjoid2ViYXBwLXYzMSIsInNjb3BlIjoic3RhdGljLWNvbnRlbnQtYXBpLGN1cmF0aW9uLWFwaSxuZXh4LWNvbnRlbnQtYXBpLXYzMSx3ZWJhcHAtYXBpIn0.mbuG9wS9Yf5q6PqgR4fiaRFIagiHk9JhwoKES7ksVX4',
}
_AUTH = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGllbnROYW1lIjoid2ViYXBwLXYzMSIsInNjb3BlIjoic3RhdGljLWNvbnRlbnQtYXBpLGN1cmF0aW9uLWFwaSxuZXh4LWNvbnRlbnQtYXBpLXYzMSx3ZWJhcHAtYXBpIn0.mbuG9wS9Yf5q6PqgR4fiaRFIagiHk9JhwoKES7ksVX4'
@staticmethod
def _make_headers(referer):
headers = FunkBaseIE._HEADERS.copy()
headers['Referer'] = referer
return headers
def _make_url_result(self, video): def _make_url_result(self, video):
return { return {
'_type': 'url_transparent', '_type': 'url_transparent',
@ -48,19 +62,19 @@ class FunkMixIE(FunkBaseIE):
lists = self._download_json( lists = self._download_json(
'https://www.funk.net/api/v3.1/curation/curatedLists/', 'https://www.funk.net/api/v3.1/curation/curatedLists/',
mix_id, headers={ mix_id, headers=self._make_headers(url), query={
'authorization': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGllbnROYW1lIjoiY3VyYXRpb24tdG9vbC12Mi4wIiwic2NvcGUiOiJzdGF0aWMtY29udGVudC1hcGksY3VyYXRpb24tc2VydmljZSxzZWFyY2gtYXBpIn0.SGCC1IXHLtZYoo8PvRKlU2gXH1su8YSu47sB3S4iXBI',
'Referer': url,
}, query={
'size': 100, 'size': 100,
})['result']['lists'] })['_embedded']['curatedListList']
metas = next( metas = next(
l for l in lists l for l in lists
if mix_id in (l.get('entityId'), l.get('alias')))['videoMetas'] if mix_id in (l.get('entityId'), l.get('alias')))['videoMetas']
video = next( video = next(
meta['videoDataDelegate'] meta['videoDataDelegate']
for meta in metas if meta.get('alias') == alias) for meta in metas
if try_get(
meta, lambda x: x['videoDataDelegate']['alias'],
compat_str) == alias)
return self._make_url_result(video) return self._make_url_result(video)
@ -104,25 +118,39 @@ class FunkChannelIE(FunkBaseIE):
channel_id = mobj.group('id') channel_id = mobj.group('id')
alias = mobj.group('alias') alias = mobj.group('alias')
headers = { headers = self._make_headers(url)
'authorization': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGllbnROYW1lIjoiY3VyYXRpb24tdG9vbCIsInNjb3BlIjoic3RhdGljLWNvbnRlbnQtYXBpLGN1cmF0aW9uLWFwaSxzZWFyY2gtYXBpIn0.q4Y2xZG8PFHai24-4Pjx2gym9RmJejtmK6lMXP5wAgc',
'Referer': url,
}
video = None video = None
by_id_list = self._download_json( # Id-based channels are currently broken on their side: webplayer
'https://www.funk.net/api/v3.0/content/videos/byIdList', channel_id, # tries to process them via byChannelAlias endpoint and fails
headers=headers, query={ # predictably.
'ids': alias, by_channel_alias = self._download_json(
'https://www.funk.net/api/v3.1/webapp/videos/byChannelAlias/%s'
% channel_id,
'Downloading byChannelAlias JSON', headers=headers, query={
'size': 100,
}, fatal=False) }, fatal=False)
if by_id_list: if by_channel_alias:
video = try_get(by_id_list, lambda x: x['result'][0], dict) video_list = try_get(
by_channel_alias, lambda x: x['_embedded']['videoList'], list)
if video_list:
video = next(r for r in video_list if r.get('alias') == alias)
if not video:
by_id_list = self._download_json(
'https://www.funk.net/api/v3.0/content/videos/byIdList',
channel_id, 'Downloading byIdList JSON', headers=headers,
query={
'ids': alias,
}, fatal=False)
if by_id_list:
video = try_get(by_id_list, lambda x: x['result'][0], dict)
if not video: if not video:
results = self._download_json( results = self._download_json(
'https://www.funk.net/api/v3.0/content/videos/filter', channel_id, 'https://www.funk.net/api/v3.0/content/videos/filter',
headers=headers, query={ channel_id, 'Downloading filter JSON', headers=headers, query={
'channelId': channel_id, 'channelId': channel_id,
'size': 100, 'size': 100,
})['result'] })['result']