]>
Commit | Line | Data |
---|---|---|
3793090b | 1 | from .common import InfoExtractor |
2 | from ..utils import ( | |
ab49d7a9 | 3 | determine_ext, |
8abc7dca | 4 | ExtractorError, |
3052a30d S |
5 | int_or_none, |
6 | mimetype2ext, | |
7 | parse_iso8601, | |
2181983a | 8 | unified_timestamp, |
3052a30d | 9 | url_or_none, |
3793090b | 10 | ) |
11 | ||
12 | ||
6368e2e6 | 13 | class AMPIE(InfoExtractor): # XXX: Conventionally, base classes should end with BaseIE/InfoExtractor |
3793090b | 14 | # parse Akamai Adaptive Media Player feed |
15 | def _extract_feed_info(self, url): | |
8abc7dca | 16 | feed = self._download_json( |
c7fa5fa4 | 17 | url, None, 'Downloading Akamai AMP feed', |
8abc7dca RA |
18 | 'Unable to download Akamai AMP feed') |
19 | item = feed.get('channel', {}).get('item') | |
20 | if not item: | |
21 | raise ExtractorError('%s said: %s' % (self.IE_NAME, feed['error'])) | |
3793090b | 22 | |
23 | video_id = item['guid'] | |
c7fa5fa4 | 24 | |
25 | def get_media_node(name, default=None): | |
26 | media_name = 'media-%s' % name | |
27 | media_group = item.get('media-group') or item | |
28 | return media_group.get(media_name) or item.get(media_name) or item.get(name, default) | |
29 | ||
3793090b | 30 | thumbnails = [] |
c7fa5fa4 | 31 | media_thumbnail = get_media_node('thumbnail') |
3793090b | 32 | if media_thumbnail: |
33 | if isinstance(media_thumbnail, dict): | |
34 | media_thumbnail = [media_thumbnail] | |
35 | for thumbnail_data in media_thumbnail: | |
7fc87519 | 36 | thumbnail = thumbnail_data.get('@attributes', {}) |
3052a30d | 37 | thumbnail_url = url_or_none(thumbnail.get('url')) |
7fc87519 RA |
38 | if not thumbnail_url: |
39 | continue | |
3793090b | 40 | thumbnails.append({ |
7fc87519 | 41 | 'url': self._proto_relative_url(thumbnail_url, 'http:'), |
3793090b | 42 | 'width': int_or_none(thumbnail.get('width')), |
43 | 'height': int_or_none(thumbnail.get('height')), | |
44 | }) | |
45 | ||
46 | subtitles = {} | |
c7fa5fa4 | 47 | media_subtitle = get_media_node('subTitle') |
3793090b | 48 | if media_subtitle: |
49 | if isinstance(media_subtitle, dict): | |
50 | media_subtitle = [media_subtitle] | |
51 | for subtitle_data in media_subtitle: | |
7fc87519 | 52 | subtitle = subtitle_data.get('@attributes', {}) |
3052a30d | 53 | subtitle_href = url_or_none(subtitle.get('href')) |
7fc87519 RA |
54 | if not subtitle_href: |
55 | continue | |
56 | subtitles.setdefault(subtitle.get('lang') or 'en', []).append({ | |
57 | 'url': subtitle_href, | |
58 | 'ext': mimetype2ext(subtitle.get('type')) or determine_ext(subtitle_href), | |
59 | }) | |
3793090b | 60 | |
61 | formats = [] | |
c7fa5fa4 | 62 | media_content = get_media_node('content') |
3793090b | 63 | if isinstance(media_content, dict): |
64 | media_content = [media_content] | |
65 | for media_data in media_content: | |
ab49d7a9 | 66 | media = media_data.get('@attributes', {}) |
3052a30d | 67 | media_url = url_or_none(media.get('url')) |
ab49d7a9 RA |
68 | if not media_url: |
69 | continue | |
54b0e909 | 70 | ext = mimetype2ext(media.get('type')) or determine_ext(media_url) |
ab49d7a9 | 71 | if ext == 'f4m': |
7e5edcfd | 72 | formats.extend(self._extract_f4m_formats( |
ab49d7a9 | 73 | media_url + '?hdcore=3.4.0&plugin=aasp-3.4.0.132.124', |
7e5edcfd | 74 | video_id, f4m_id='hds', fatal=False)) |
ab49d7a9 | 75 | elif ext == 'm3u8': |
7e5edcfd | 76 | formats.extend(self._extract_m3u8_formats( |
ab49d7a9 | 77 | media_url, video_id, 'mp4', m3u8_id='hls', fatal=False)) |
3793090b | 78 | else: |
79 | formats.append({ | |
055f0d3d | 80 | 'format_id': media_data.get('media-category', {}).get('@attributes', {}).get('label'), |
3052a30d | 81 | 'url': media_url, |
c7fa5fa4 | 82 | 'tbr': int_or_none(media.get('bitrate')), |
3793090b | 83 | 'filesize': int_or_none(media.get('fileSize')), |
ab49d7a9 | 84 | 'ext': ext, |
3793090b | 85 | }) |
86 | ||
2181983a | 87 | timestamp = unified_timestamp(item.get('pubDate'), ' ') or parse_iso8601(item.get('dc-date')) |
87d105ac | 88 | |
3793090b | 89 | return { |
90 | 'id': video_id, | |
c7fa5fa4 | 91 | 'title': get_media_node('title'), |
92 | 'description': get_media_node('description'), | |
3793090b | 93 | 'thumbnails': thumbnails, |
87d105ac | 94 | 'timestamp': timestamp, |
3793090b | 95 | 'duration': int_or_none(media_content[0].get('@attributes', {}).get('duration')), |
fff79f18 | 96 | 'subtitles': subtitles, |
3793090b | 97 | 'formats': formats, |
98 | } |