2 from __future__ import unicode_literals
4 from .common import InfoExtractor
13 class AMPIE(InfoExtractor):
14 # parse Akamai Adaptive Media Player feed
15 def _extract_feed_info(self, url):
16 item = self._download_json(
17 url, None, 'Downloading Akamai AMP feed',
18 'Unable to download Akamai AMP feed')['channel']['item']
20 video_id = item['guid']
22 def get_media_node(name, default=None):
23 media_name = 'media-%s' % name
24 media_group = item.get('media-group') or item
25 return media_group.get(media_name) or item.get(media_name) or item.get(name, default)
28 media_thumbnail = get_media_node('thumbnail')
30 if isinstance(media_thumbnail, dict):
31 media_thumbnail = [media_thumbnail]
32 for thumbnail_data in media_thumbnail:
33 thumbnail = thumbnail_data['@attributes']
35 'url': self._proto_relative_url(thumbnail['url'], 'http:'),
36 'width': int_or_none(thumbnail.get('width')),
37 'height': int_or_none(thumbnail.get('height')),
41 media_subtitle = get_media_node('subTitle')
43 if isinstance(media_subtitle, dict):
44 media_subtitle = [media_subtitle]
45 for subtitle_data in media_subtitle:
46 subtitle = subtitle_data['@attributes']
47 lang = subtitle.get('lang') or 'en'
48 subtitles[lang] = [{'url': subtitle['href']}]
51 media_content = get_media_node('content')
52 if isinstance(media_content, dict):
53 media_content = [media_content]
54 for media_data in media_content:
55 media = media_data.get('@attributes', {})
56 media_url = media.get('url')
59 ext = mimetype2ext(media.get('type')) or determine_ext(media_url)
61 formats.extend(self._extract_f4m_formats(
62 media_url + '?hdcore=3.4.0&plugin=aasp-3.4.0.132.124',
63 video_id, f4m_id='hds', fatal=False))
65 formats.extend(self._extract_m3u8_formats(
66 media_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
69 'format_id': media_data.get('media-category', {}).get('@attributes', {}).get('label'),
71 'tbr': int_or_none(media.get('bitrate')),
72 'filesize': int_or_none(media.get('fileSize')),
76 self._sort_formats(formats)
78 timestamp = parse_iso8601(item.get('pubDate'), ' ') or parse_iso8601(item.get('dc-date'))
82 'title': get_media_node('title'),
83 'description': get_media_node('description'),
84 'thumbnails': thumbnails,
85 'timestamp': timestamp,
86 'duration': int_or_none(media_content[0].get('@attributes', {}).get('duration')),
87 'subtitles': subtitles,