- if url.endswith('m3u8'):
- formats.extend(self._extract_m3u8_formats(url, media_id, m3u8_id='hls'))
- parsed_urls.append(url)
- elif url.endswith('f4m'):
- formats.extend(self._extract_f4m_formats(url, media_id, f4m_id='hds'))
- parsed_urls.append(url)
- else:
- if not fmt.tag.startswith('HTTP'):
- continue
- proto = compat_urllib_parse_urlparse(url).scheme
- width_str, height_str = fmt.get('resolution').split('x')
- tbr = int(fmt.get('bitrate', 0))
- formats.append({
- 'format_id': '%s-%d' % (proto, tbr),
- 'url': url,
- 'width': int(width_str),
- 'height': int(height_str),
- 'tbr': tbr,
- 'ext': url.rsplit('.', 1)[-1],
- 'live': True,
- 'protocol': proto,
- })
+ def extract_formats(node):
+ for child in node:
+ if child.tag.endswith('Files'):
+ extract_formats(child)
+ elif child.tag.endswith('File'):
+ video_url = child.text
+ if (not video_url or video_url in processed_urls or
+ any(p in video_url for p in ('NOT_USED', 'NOT-USED'))):
+ return
+ processed_urls.append(video_url)
+ ext = determine_ext(video_url)
+ if ext == 'm3u8':
+ m3u8_formats = self._extract_m3u8_formats(
+ video_url, video_id, 'mp4', m3u8_id='hls', fatal=False)
+ if m3u8_formats:
+ formats.extend(m3u8_formats)
+ elif ext == 'f4m':
+ f4m_formats = self._extract_f4m_formats(
+ video_url, video_id, f4m_id='hds', fatal=False)
+ if f4m_formats:
+ formats.extend(f4m_formats)
+ else:
+ proto = compat_urllib_parse_urlparse(video_url).scheme
+ if not child.tag.startswith('HTTP') and proto != 'rtmp':
+ continue
+ preference = -1 if proto == 'rtmp' else 1
+ label = child.get('label')
+ tbr = int_or_none(child.get('bitrate'))
+ width, height = [int_or_none(x) for x in child.get('resolution', 'x').split('x')[:2]]
+ formats.append({
+ 'format_id': '%s-%s' % (proto, label if label else tbr),
+ 'url': video_url,
+ 'width': width,
+ 'height': height,
+ 'tbr': tbr,
+ 'preference': preference,
+ })
+
+ extract_formats(video_xml.find('./Clip'))