- 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 = {
- 'ERROR_MATURE_CONTENT_LOGGED_IN': 'matureContentLoggedIn',
- 'ERROR_MATURE_CONTENT_LOGGED_OUT': 'matureContentLoggedOut',
- 'ERROR_SUBSCRIPTION_LOGGED_OUT': 'subscriptionLoggedOut',
- 'ERROR_VIDEO_EXPIRED': 'videoExpired',
- 'ERROR_TERRITORY_UNAVAILABLE': 'territoryUnavailable',
- 'SVODBASIC_SUBSCRIPTION_IN_PLAYER': 'basicSubscription',
- 'SVODNON_SUBSCRIPTION_IN_PLAYER': 'nonSubscription',
- 'ERROR_PLAYER_NOT_RESPONDING': 'playerNotResponding',
- 'ERROR_UNABLE_TO_CONNECT_TO_CDN': 'unableToConnectToCDN',
- 'ERROR_STREAM_NOT_FOUND': 'streamNotFound',
- }
+ def _search_kane(name):
+ return self._search_regex(
+ r"KANE_customdimensions\.%s\s*=\s*'([^']+)';" % name,
+ webpage, name, default=None)
+
+ title_data = self._parse_json(self._search_regex(
+ r'TITLE_DATA\s*=\s*({[^}]+})',
+ webpage, 'title data', default=''),
+ display_id, js_to_json, fatal=False) or {}
+
+ video_id = title_data.get('id') or self._search_regex([
+ r"KANE_customdimensions.videoID\s*=\s*'(\d+)';",
+ r'<iframe[^>]+src="/player/(\d+)',
+ ], webpage, 'video_id', default=None)
+ if not video_id:
+ player_url = self._html_search_meta([
+ 'al:web:url',
+ 'og:video:url',
+ 'og:video:secure_url',
+ ], webpage, fatal=True)
+ video_id = self._search_regex(r'/player/(\d+)', player_url, 'video id')
+
+ title = episode = title_data.get('title') or _search_kane('videoTitle') or self._og_search_title(webpage)
+ series = _search_kane('showName')
+ if series:
+ title = '%s - %s' % (series, title)
+ description = self._html_search_meta(['description', 'og:description'], webpage, fatal=True)
+
+ try:
+ headers = {}
+ if self._TOKEN:
+ headers['Authorization'] = 'Token %s' % self._TOKEN
+ sources = self._download_json(
+ 'https://www.funimation.com/api/showexperience/%s/' % video_id,
+ video_id, headers=headers, query={
+ 'pinst_id': ''.join([random.choice(string.digits + string.ascii_letters) for _ in range(8)]),
+ })['items']
+ except ExtractorError as e:
+ if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
+ error = self._parse_json(e.cause.read(), video_id)['errors'][0]
+ raise ExtractorError('%s said: %s' % (
+ self.IE_NAME, error.get('detail') or error.get('title')), expected=True)
+ raise