1 from .common
import InfoExtractor
13 class AMPIE(InfoExtractor
):
14 # parse Akamai Adaptive Media Player feed
15 def _extract_feed_info(self
, url
):
16 feed
= self
._download
_json
(
17 url
, None, 'Downloading Akamai AMP feed',
18 'Unable to download Akamai AMP feed')
19 item
= feed
.get('channel', {}).get('item')
21 raise ExtractorError('%s said: %s' % (self
.IE_NAME
, feed
['error']))
23 video_id
= item
['guid']
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
)
31 media_thumbnail
= get_media_node('thumbnail')
33 if isinstance(media_thumbnail
, dict):
34 media_thumbnail
= [media_thumbnail
]
35 for thumbnail_data
in media_thumbnail
:
36 thumbnail
= thumbnail_data
.get('@attributes', {})
37 thumbnail_url
= url_or_none(thumbnail
.get('url'))
41 'url': self
._proto
_relative
_url
(thumbnail_url
, 'http:'),
42 'width': int_or_none(thumbnail
.get('width')),
43 'height': int_or_none(thumbnail
.get('height')),
47 media_subtitle
= get_media_node('subTitle')
49 if isinstance(media_subtitle
, dict):
50 media_subtitle
= [media_subtitle
]
51 for subtitle_data
in media_subtitle
:
52 subtitle
= subtitle_data
.get('@attributes', {})
53 subtitle_href
= url_or_none(subtitle
.get('href'))
56 subtitles
.setdefault(subtitle
.get('lang') or 'en', []).append({
58 'ext': mimetype2ext(subtitle
.get('type')) or determine_ext(subtitle_href
),
62 media_content
= get_media_node('content')
63 if isinstance(media_content
, dict):
64 media_content
= [media_content
]
65 for media_data
in media_content
:
66 media
= media_data
.get('@attributes', {})
67 media_url
= url_or_none(media
.get('url'))
70 ext
= mimetype2ext(media
.get('type')) or determine_ext(media_url
)
72 formats
.extend(self
._extract
_f
4m
_formats
(
73 media_url
+ '?hdcore=3.4.0&plugin=aasp-3.4.0.132.124',
74 video_id
, f4m_id
='hds', fatal
=False))
76 formats
.extend(self
._extract
_m
3u8_formats
(
77 media_url
, video_id
, 'mp4', m3u8_id
='hls', fatal
=False))
80 'format_id': media_data
.get('media-category', {}).get('@attributes', {}
).get('label'),
82 'tbr': int_or_none(media
.get('bitrate')),
83 'filesize': int_or_none(media
.get('fileSize')),
87 self
._sort
_formats
(formats
)
89 timestamp
= unified_timestamp(item
.get('pubDate'), ' ') or parse_iso8601(item
.get('dc-date'))
93 'title': get_media_node('title'),
94 'description': get_media_node('description'),
95 'thumbnails': thumbnails
,
96 'timestamp': timestamp
,
97 'duration': int_or_none(media_content
[0].get('@attributes', {}).get('duration')),
98 'subtitles': subtitles
,