- video_path = mobj.group('path')
-
- webpage = self._download_webpage(url, video_path)
- episode_id = self._html_search_regex(
- r'<link rel="video_src" href="http://i\.adultswim\.com/adultswim/adultswimtv/tools/swf/viralplayer.swf\?id=([0-9a-f]+?)"\s*/?\s*>',
- webpage, 'episode_id')
- title = self._og_search_title(webpage)
-
- index_url = 'http://asfix.adultswim.com/asfix-svc/episodeSearch/getEpisodesByIDs?networkName=AS&ids=%s' % episode_id
- idoc = self._download_xml(index_url, title, 'Downloading episode index', 'Unable to download episode index')
-
- episode_el = idoc.find('.//episode')
- show_title = episode_el.attrib.get('collectionTitle')
- episode_title = episode_el.attrib.get('title')
- thumbnail = episode_el.attrib.get('thumbnailUrl')
- description = episode_el.find('./description').text.strip()
+ show_path = mobj.group('show_path')
+ episode_path = mobj.group('episode_path')
+ is_playlist = True if mobj.group('is_playlist') else False
+
+ webpage = self._download_webpage(url, episode_path)
+
+ # Extract the value of `bootstrappedData` from the Javascript in the page.
+ bootstrapped_data = self._parse_json(self._search_regex(
+ r'var bootstrappedData = ({.*});', webpage, 'bootstraped data'), episode_path)
+
+ # Downloading videos from a /videos/playlist/ URL needs to be handled differently.
+ # NOTE: We are only downloading one video (the current one) not the playlist
+ if is_playlist:
+ collections = bootstrapped_data['playlists']['collections']
+ collection = self.find_collection_by_linkURL(collections, show_path)
+ video_info = self.find_video_info(collection, episode_path)
+
+ show_title = video_info['showTitle']
+ segment_ids = [video_info['videoPlaybackID']]
+ else:
+ collections = bootstrapped_data['show']['collections']
+ collection, video_info = self.find_collection_containing_video(collections, episode_path)
+ # Video wasn't found in the collections, let's try `slugged_video`.
+ if video_info is None:
+ if bootstrapped_data.get('slugged_video', {}).get('slug') == episode_path:
+ video_info = bootstrapped_data['slugged_video']
+ if not video_info:
+ video_info = bootstrapped_data.get(
+ 'heroMetadata', {}).get('trailer', {}).get('video')
+ if not video_info:
+ video_info = bootstrapped_data.get('onlineOriginals', [None])[0]
+ if not video_info:
+ raise ExtractorError('Unable to find video info')
+
+ show = bootstrapped_data['show']
+ show_title = show['title']
+ stream = video_info.get('stream')
+ if stream and stream.get('videoPlaybackID'):
+ segment_ids = [stream['videoPlaybackID']]
+ elif video_info.get('clips'):
+ segment_ids = [clip['videoPlaybackID'] for clip in video_info['clips']]
+ elif video_info.get('videoPlaybackID'):
+ segment_ids = [video_info['videoPlaybackID']]
+ elif video_info.get('id'):
+ segment_ids = [video_info['id']]
+ else:
+ if video_info.get('auth') is True:
+ raise ExtractorError(
+ 'This video is only available via cable service provider subscription that'
+ ' is not currently supported. You may want to use --cookies.', expected=True)
+ else:
+ raise ExtractorError('Unable to find stream or clips')
+
+ episode_id = video_info['id']
+ episode_title = video_info['title']
+ episode_description = video_info.get('description')
+ episode_duration = int_or_none(video_info.get('duration'))
+ view_count = int_or_none(video_info.get('views'))