X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2Fextractor%2Ffunimation.py;h=1eb528f31f4b908b8d832cfe1fd4e1647ef74058;hb=494ab6db7394b39126d775efe03eb6dab428eff9;hp=8af2e907c915d1a24e2ef97b33235455159e9e06;hpb=b59623ef434cb7868faa4b5e6e0dd2a56449f369;p=youtube-dl diff --git a/youtube_dl/extractor/funimation.py b/youtube_dl/extractor/funimation.py index 8af2e907c..1eb528f31 100644 --- a/youtube_dl/extractor/funimation.py +++ b/youtube_dl/extractor/funimation.py @@ -1,14 +1,11 @@ # coding: utf-8 from __future__ import unicode_literals -import re - from .common import InfoExtractor -from ..compat import compat_urllib_request from ..utils import ( clean_html, determine_ext, - encode_dict, + int_or_none, sanitized_Request, ExtractorError, urlencode_postdata @@ -16,7 +13,9 @@ from ..utils import ( class FunimationIE(InfoExtractor): - _VALID_URL = r'https?://(?:www\.)?funimation\.com/shows/[^/]+/videos/official/(?P[^/?#&]+)' + _VALID_URL = r'https?://(?:www\.)?funimation\.com/shows/[^/]+/videos/(?:official|promotional)/(?P[^/?#&]+)' + + _NETRC_MACHINE = 'funimation' _TESTS = [{ 'url': 'http://www.funimation.com/shows/air/videos/official/breeze', @@ -38,24 +37,40 @@ class FunimationIE(InfoExtractor): 'description': 'md5:b602bdc15eef4c9bbb201bb6e6a4a2dd', 'thumbnail': 're:https?://.*\.jpg', }, + }, { + 'url': 'http://www.funimation.com/shows/attack-on-titan-junior-high/videos/promotional/broadcast-dub-preview', + 'info_dict': { + 'id': '9635', + 'display_id': 'broadcast-dub-preview', + 'ext': 'mp4', + 'title': 'Attack on Titan: Junior High - Broadcast Dub Preview', + 'description': 'md5:f8ec49c0aff702a7832cd81b8a44f803', + 'thumbnail': 're:https?://.*\.(?:jpg|png)', + }, }] def _login(self): (username, password) = self._get_login_info() if username is None: return - data = urlencode_postdata(encode_dict({ + data = urlencode_postdata({ 'email_field': username, 'password_field': password, - })) + }) 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' }) - login = self._download_webpage( + login_page = self._download_webpage( login_request, None, 'Logging in as %s' % username) - if re.search(r'', login) is not None: - raise ExtractorError('Unable to login, wrong username or password.', expected=True) + if any(p in login_page for p in ('funimation.com/logout', '>Log Out<')): + return + error = self._html_search_regex( + r'(?s)]+id=["\']errorMessages["\'][^>]*>(.+?)', + login_page, 'error messages', default=None) + if error: + raise ExtractorError('Unable to login: %s' % error, expected=True) + raise ExtractorError('Unable to log in') def _real_initialize(self): self._login() @@ -94,12 +109,13 @@ class FunimationIE(InfoExtractor): webpage = self._download_webpage( request, display_id, 'Downloading %s webpage' % kind) - items = self._parse_json( + playlist = self._parse_json( self._search_regex( r'var\s+playersData\s*=\s*(\[.+?\]);\n', webpage, 'players data'), - display_id)[0]['playlist'][0]['items'] + display_id)[0]['playlist'] + items = next(item['items'] for item in playlist if item.get('items')) item = next(item for item in items if item.get('itemAK') == display_id) error_messages = {} @@ -126,7 +142,7 @@ class FunimationIE(InfoExtractor): preference = 1 if video.get('languageMode') == 'dub' else 0 if not auth_token.startswith('?'): auth_token = '?%s' % auth_token - for quality in ('sd', 'hd', 'hd1080'): + for quality, height in (('sd', 480), ('hd', 720), ('hd1080', 1080)): format_url = video.get('%sUrl' % quality) if not format_url: continue @@ -134,24 +150,19 @@ class FunimationIE(InfoExtractor): errors.append(format_url) continue if determine_ext(format_url) == 'm3u8': - m3u8_formats = self._extract_m3u8_formats( + formats.extend(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) + preference=preference, m3u8_id='%s-hls' % funimation_id, fatal=False)) else: - f = { + tbr = int_or_none(self._search_regex( + r'-(\d+)[Kk]', format_url, 'tbr', default=None)) + formats.append({ 'url': format_url + auth_token, - 'format_id': funimation_id, + 'format_id': '%s-http-%dp' % (funimation_id, height), + 'height': height, + 'tbr': tbr, 'preference': preference, - } - mobj = re.search(r'(?P\d+)-(?P\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: raise ExtractorError(