mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-02 17:22:31 +01:00
[funimation] Use mobile webpage for workaround hulu error
This commit is contained in:
parent
9c163950da
commit
b59623ef43
@ -18,7 +18,7 @@
|
|||||||
class FunimationIE(InfoExtractor):
|
class FunimationIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?funimation\.com/shows/[^/]+/videos/official/(?P<id>[^/?#&]+)'
|
_VALID_URL = r'https?://(?:www\.)?funimation\.com/shows/[^/]+/videos/official/(?P<id>[^/?#&]+)'
|
||||||
|
|
||||||
_TEST = {
|
_TESTS = [{
|
||||||
'url': 'http://www.funimation.com/shows/air/videos/official/breeze',
|
'url': 'http://www.funimation.com/shows/air/videos/official/breeze',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '658',
|
'id': '658',
|
||||||
@ -28,19 +28,17 @@ class FunimationIE(InfoExtractor):
|
|||||||
'description': 'md5:1769f43cd5fc130ace8fd87232207892',
|
'description': 'md5:1769f43cd5fc130ace8fd87232207892',
|
||||||
'thumbnail': 're:https?://.*\.jpg',
|
'thumbnail': 're:https?://.*\.jpg',
|
||||||
},
|
},
|
||||||
}
|
}, {
|
||||||
|
'url': 'http://www.funimation.com/shows/hacksign/videos/official/role-play',
|
||||||
def _download_webpage(self, url_or_request, video_id, note='Downloading webpage'):
|
'info_dict': {
|
||||||
HEADERS = {
|
'id': '31128',
|
||||||
'User-Agent': 'Mozilla/5.0 (Windows NT 5.2; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0',
|
'display_id': 'role-play',
|
||||||
}
|
'ext': 'mp4',
|
||||||
if isinstance(url_or_request, compat_urllib_request.Request):
|
'title': '.hack//SIGN - 1 - Role Play',
|
||||||
for header, value in HEADERS.items():
|
'description': 'md5:b602bdc15eef4c9bbb201bb6e6a4a2dd',
|
||||||
url_or_request.add_header(header, value)
|
'thumbnail': 're:https?://.*\.jpg',
|
||||||
else:
|
},
|
||||||
url_or_request = sanitized_Request(url_or_request, headers=HEADERS)
|
}]
|
||||||
response = super(FunimationIE, self)._download_webpage(url_or_request, video_id, note)
|
|
||||||
return response
|
|
||||||
|
|
||||||
def _login(self):
|
def _login(self):
|
||||||
(username, password) = self._get_login_info()
|
(username, password) = self._get_login_info()
|
||||||
@ -51,6 +49,7 @@ def _login(self):
|
|||||||
'password_field': password,
|
'password_field': password,
|
||||||
}))
|
}))
|
||||||
login_request = sanitized_Request('http://www.funimation.com/login', data, headers={
|
login_request = sanitized_Request('http://www.funimation.com/login', data, headers={
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Windows NT 5.2; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0',
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
})
|
})
|
||||||
login = self._download_webpage(
|
login = self._download_webpage(
|
||||||
@ -64,15 +63,8 @@ def _real_initialize(self):
|
|||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
display_id = self._match_id(url)
|
display_id = self._match_id(url)
|
||||||
|
|
||||||
webpage = self._download_webpage(url, display_id)
|
errors = []
|
||||||
|
formats = []
|
||||||
items = self._parse_json(
|
|
||||||
self._search_regex(
|
|
||||||
r'var\s+playersData\s*=\s*(\[.+?\]);\n',
|
|
||||||
webpage, 'players data'),
|
|
||||||
display_id)[0]['playlist'][0]['items']
|
|
||||||
|
|
||||||
item = next(item for item in items if item.get('itemAK') == display_id)
|
|
||||||
|
|
||||||
ERRORS_MAP = {
|
ERRORS_MAP = {
|
||||||
'ERROR_MATURE_CONTENT_LOGGED_IN': 'matureContentLoggedIn',
|
'ERROR_MATURE_CONTENT_LOGGED_IN': 'matureContentLoggedIn',
|
||||||
@ -87,48 +79,79 @@ def _real_extract(self, url):
|
|||||||
'ERROR_STREAM_NOT_FOUND': 'streamNotFound',
|
'ERROR_STREAM_NOT_FOUND': 'streamNotFound',
|
||||||
}
|
}
|
||||||
|
|
||||||
error_messages = {}
|
USER_AGENTS = (
|
||||||
video_error_messages = self._search_regex(
|
# PC UA is served with m3u8 that provides some bonus lower quality formats
|
||||||
r'var\s+videoErrorMessages\s*=\s*({.+?});\n',
|
('pc', 'Mozilla/5.0 (Windows NT 5.2; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0'),
|
||||||
webpage, 'error messages', default=None)
|
# Mobile UA allows to extract direct links and also does not fail when
|
||||||
if video_error_messages:
|
# PC UA fails with hulu error (e.g.
|
||||||
error_messages_json = self._parse_json(video_error_messages, display_id, fatal=False)
|
# http://www.funimation.com/shows/hacksign/videos/official/role-play)
|
||||||
if error_messages_json:
|
('mobile', 'Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.36'),
|
||||||
for _, error in error_messages_json.items():
|
)
|
||||||
type_ = error.get('type')
|
|
||||||
description = error.get('description')
|
|
||||||
content = error.get('content')
|
|
||||||
if type_ == 'text' and description and content:
|
|
||||||
error_message = ERRORS_MAP.get(description)
|
|
||||||
if error_message:
|
|
||||||
error_messages[error_message] = content
|
|
||||||
|
|
||||||
errors = []
|
for kind, user_agent in USER_AGENTS:
|
||||||
formats = []
|
request = sanitized_Request(url)
|
||||||
for video in item['videoSet']:
|
request.add_header('User-Agent', user_agent)
|
||||||
auth_token = video.get('authToken')
|
webpage = self._download_webpage(
|
||||||
if not auth_token:
|
request, display_id, 'Downloading %s webpage' % kind)
|
||||||
continue
|
|
||||||
funimation_id = video.get('FUNImationID') or video.get('videoId')
|
items = self._parse_json(
|
||||||
if not auth_token.startswith('?'):
|
self._search_regex(
|
||||||
auth_token = '?%s' % auth_token
|
r'var\s+playersData\s*=\s*(\[.+?\]);\n',
|
||||||
for quality in ('sd', 'hd', 'hd1080'):
|
webpage, 'players data'),
|
||||||
format_url = video.get('%sUrl' % quality)
|
display_id)[0]['playlist'][0]['items']
|
||||||
if not format_url:
|
|
||||||
|
item = next(item for item in items if item.get('itemAK') == display_id)
|
||||||
|
|
||||||
|
error_messages = {}
|
||||||
|
video_error_messages = self._search_regex(
|
||||||
|
r'var\s+videoErrorMessages\s*=\s*({.+?});\n',
|
||||||
|
webpage, 'error messages', default=None)
|
||||||
|
if video_error_messages:
|
||||||
|
error_messages_json = self._parse_json(video_error_messages, display_id, fatal=False)
|
||||||
|
if error_messages_json:
|
||||||
|
for _, error in error_messages_json.items():
|
||||||
|
type_ = error.get('type')
|
||||||
|
description = error.get('description')
|
||||||
|
content = error.get('content')
|
||||||
|
if type_ == 'text' and description and content:
|
||||||
|
error_message = ERRORS_MAP.get(description)
|
||||||
|
if error_message:
|
||||||
|
error_messages[error_message] = content
|
||||||
|
|
||||||
|
for video in item.get('videoSet', []):
|
||||||
|
auth_token = video.get('authToken')
|
||||||
|
if not auth_token:
|
||||||
continue
|
continue
|
||||||
if not format_url.startswith(('http', '//')):
|
funimation_id = video.get('FUNImationID') or video.get('videoId')
|
||||||
errors.append(format_url)
|
preference = 1 if video.get('languageMode') == 'dub' else 0
|
||||||
continue
|
if not auth_token.startswith('?'):
|
||||||
if determine_ext(format_url) == 'm3u8':
|
auth_token = '?%s' % auth_token
|
||||||
m3u8_formats = self._extract_m3u8_formats(
|
for quality in ('sd', 'hd', 'hd1080'):
|
||||||
format_url + auth_token, display_id, 'mp4', entry_protocol='m3u8_native',
|
format_url = video.get('%sUrl' % quality)
|
||||||
m3u8_id=funimation_id or 'hls', fatal=False)
|
if not format_url:
|
||||||
if m3u8_formats:
|
continue
|
||||||
formats.extend(m3u8_formats)
|
if not format_url.startswith(('http', '//')):
|
||||||
else:
|
errors.append(format_url)
|
||||||
formats.append({
|
continue
|
||||||
'url': format_url + auth_token,
|
if determine_ext(format_url) == 'm3u8':
|
||||||
})
|
m3u8_formats = self._extract_m3u8_formats(
|
||||||
|
format_url + auth_token, display_id, 'mp4', entry_protocol='m3u8_native',
|
||||||
|
preference=preference, m3u8_id=funimation_id or 'hls', fatal=False)
|
||||||
|
if m3u8_formats:
|
||||||
|
formats.extend(m3u8_formats)
|
||||||
|
else:
|
||||||
|
f = {
|
||||||
|
'url': format_url + auth_token,
|
||||||
|
'format_id': funimation_id,
|
||||||
|
'preference': preference,
|
||||||
|
}
|
||||||
|
mobj = re.search(r'(?P<height>\d+)-(?P<tbr>\d+)[Kk]', format_url)
|
||||||
|
if mobj:
|
||||||
|
f.update({
|
||||||
|
'height': int(mobj.group('height')),
|
||||||
|
'tbr': int(mobj.group('tbr')),
|
||||||
|
})
|
||||||
|
formats.append(f)
|
||||||
|
|
||||||
if not formats and errors:
|
if not formats and errors:
|
||||||
raise ExtractorError(
|
raise ExtractorError(
|
||||||
@ -136,6 +159,8 @@ def _real_extract(self, url):
|
|||||||
% (self.IE_NAME, clean_html(error_messages.get(errors[0], errors[0]))),
|
% (self.IE_NAME, clean_html(error_messages.get(errors[0], errors[0]))),
|
||||||
expected=True)
|
expected=True)
|
||||||
|
|
||||||
|
self._sort_formats(formats)
|
||||||
|
|
||||||
title = item['title']
|
title = item['title']
|
||||||
artist = item.get('artist')
|
artist = item.get('artist')
|
||||||
if artist:
|
if artist:
|
||||||
|
Loading…
Reference in New Issue
Block a user