1 from .common
import InfoExtractor
14 class AMPIE(InfoExtractor
): # XXX: Conventionally, base classes should end with BaseIE/InfoExtractor
15 # parse Akamai Adaptive Media Player feed
16 def _extract_feed_info(self
, url
):
17 feed
= self
._download
_json
(
18 url
, None, 'Downloading Akamai AMP feed',
19 'Unable to download Akamai AMP feed', transform_source
=strip_jsonp
)
20 item
= feed
.get('channel', {}).get('item')
22 raise ExtractorError('{} said: {}'.format(self
.IE_NAME
, feed
['error']))
24 video_id
= item
['guid']
26 def get_media_node(name
, default
=None):
27 media_name
= f
'media-{name}'
28 media_group
= item
.get('media-group') or item
29 return media_group
.get(media_name
) or item
.get(media_name
) or item
.get(name
, default
)
32 media_thumbnail
= get_media_node('thumbnail')
34 if isinstance(media_thumbnail
, dict):
35 media_thumbnail
= [media_thumbnail
]
36 for thumbnail_data
in media_thumbnail
:
37 thumbnail
= thumbnail_data
.get('@attributes', {})
38 thumbnail_url
= url_or_none(thumbnail
.get('url'))
42 'url': self
._proto
_relative
_url
(thumbnail_url
, 'http:'),
43 'width': int_or_none(thumbnail
.get('width')),
44 'height': int_or_none(thumbnail
.get('height')),
48 media_subtitle
= get_media_node('subTitle')
50 if isinstance(media_subtitle
, dict):
51 media_subtitle
= [media_subtitle
]
52 for subtitle_data
in media_subtitle
:
53 subtitle
= subtitle_data
.get('@attributes', {})
54 subtitle_href
= url_or_none(subtitle
.get('href'))
57 subtitles
.setdefault(subtitle
.get('lang') or 'en', []).append({
59 'ext': mimetype2ext(subtitle
.get('type')) or determine_ext(subtitle_href
),
63 media_content
= get_media_node('content')
64 if isinstance(media_content
, dict):
65 media_content
= [media_content
]
66 for media_data
in media_content
:
67 media
= media_data
.get('@attributes', {})
68 media_url
= url_or_none(media
.get('url'))
71 ext
= mimetype2ext(media
.get('type')) or determine_ext(media_url
)
73 formats
.extend(self
._extract
_f
4m
_formats
(
74 media_url
+ '?hdcore=3.4.0&plugin=aasp-3.4.0.132.124',
75 video_id
, f4m_id
='hds', fatal
=False))
77 fmts
, subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
78 media_url
, video_id
, 'mp4', m3u8_id
='hls', fatal
=False)
80 self
._merge
_subtitles
(subs
, target
=subtitles
)
83 'format_id': media_data
.get('media-category', {}).get('@attributes', {}).get('label'),
85 'tbr': int_or_none(media
.get('bitrate')),
86 'filesize': int_or_none(media
.get('fileSize')),
90 timestamp
= unified_timestamp(item
.get('pubDate'), ' ') or parse_iso8601(item
.get('dc-date'))
94 'title': get_media_node('title'),
95 'description': get_media_node('description'),
96 'thumbnails': thumbnails
,
97 'timestamp': timestamp
,
98 'duration': int_or_none(media_content
[0].get('@attributes', {}).get('duration')),
99 'subtitles': subtitles
,