- for format_el in urls.findall('EncodingOptions/EncodingOption'):
- domain = format_el.find('Domain').text
- uri = format_el.find('uri').text
- f = {
- 'url': compat_urlparse.urljoin(domain, uri),
- 'ext': 'mp4',
- 'width': int(format_el.find('width').text),
- 'height': int(format_el.find('height').text),
- }
- if domain.startswith('rtmp'):
- # urlparse does not support custom schemes
- # https://bugs.python.org/issue18828
- f.update({
- 'url': domain + uri,
- 'ext': 'flv',
- 'rtmp_protocol': '1', # rtmpt
+
+ def extract_formats(streams, stream_type, query={}):
+ for stream in streams:
+ stream_url = stream.get('source')
+ if not stream_url:
+ continue
+ stream_url = update_url_query(stream_url, query)
+ encoding_option = stream.get('encodingOption', {})
+ bitrate = stream.get('bitrate', {})
+ formats.append({
+ 'format_id': '%s_%s' % (stream.get('type') or stream_type, encoding_option.get('id') or encoding_option.get('name')),
+ 'url': stream_url,
+ 'width': int_or_none(encoding_option.get('width')),
+ 'height': int_or_none(encoding_option.get('height')),
+ 'vbr': int_or_none(bitrate.get('video')),
+ 'abr': int_or_none(bitrate.get('audio')),
+ 'filesize': int_or_none(stream.get('size')),
+ 'protocol': 'm3u8_native' if stream_type == 'HLS' else None,