- # Get the video URL
- m_playlist = re.search(r'so.addVariable\("playlist", ?"(?P<playlist>.+?)"\);', webpage)
- if m_playlist is not None:
- playlist_url = m_playlist.group('playlist')
- playlist_page = self._download_webpage(playlist_url, video_id,
- 'Downloading playlist page')
- m_levels = list(re.finditer(r'<level bitrate="(\d+?)" file="(.*?)"', playlist_page))
- if len(m_levels) == 0:
- raise ExtractorError('Unable to extract video url')
- videos = [(int(m.group(1)), m.group(2)) for m in m_levels]
- (_, video_url) = sorted(videos)[0]
- video_url = video_url.replace('%252F', '%2F')
+ encodings = self._parse_json(
+ self._search_regex(
+ r'[Ee]ncodings\s*=\s*(\[.+?\]);\n', webpage, 'encodings',
+ default='[]'),
+ video_id, fatal=False)
+ for encoding in encodings:
+ if not isinstance(encoding, dict):
+ continue
+ format_url = url_or_none(encoding.get('filename'))
+ if not format_url:
+ continue
+ if determine_ext(format_url) == 'm3u8':
+ formats.extend(self._extract_m3u8_formats(
+ format_url, video_id, 'mp4', entry_protocol='m3u8_native',
+ m3u8_id='hls', fatal=False))
+ else:
+ format_id = encoding.get('name') or encoding.get('quality')
+ height = int_or_none(self._search_regex(
+ r'^(\d+)[pP]', format_id, 'height', default=None))
+ formats.append({
+ 'url': format_url,
+ 'format_id': format_id,
+ 'height': height,
+ })
+
+ if formats:
+ info_dict = {
+ 'formats': formats,
+ }