]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/amp.py
2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
11 class AMPIE(InfoExtractor
):
12 # parse Akamai Adaptive Media Player feed
13 def _extract_feed_info(self
, url
):
14 item
= self
._download
_json
(
15 url
, None, 'Downloading Akamai AMP feed',
16 'Unable to download Akamai AMP feed')['channel']['item']
18 video_id
= item
['guid']
20 def get_media_node(name
, default
=None):
21 media_name
= 'media-%s' % name
22 media_group
= item
.get('media-group') or item
23 return media_group
.get(media_name
) or item
.get(media_name
) or item
.get(name
, default
)
26 media_thumbnail
= get_media_node('thumbnail')
28 if isinstance(media_thumbnail
, dict):
29 media_thumbnail
= [media_thumbnail
]
30 for thumbnail_data
in media_thumbnail
:
31 thumbnail
= thumbnail_data
['@attributes']
33 'url': self
._proto
_relative
_url
(thumbnail
['url'], 'http:'),
34 'width': int_or_none(thumbnail
.get('width')),
35 'height': int_or_none(thumbnail
.get('height')),
39 media_subtitle
= get_media_node('subTitle')
41 if isinstance(media_subtitle
, dict):
42 media_subtitle
= [media_subtitle
]
43 for subtitle_data
in media_subtitle
:
44 subtitle
= subtitle_data
['@attributes']
45 lang
= subtitle
.get('lang') or 'en'
46 subtitles
[lang
] = [{'url': subtitle
['href']}]
49 media_content
= get_media_node('content')
50 if isinstance(media_content
, dict):
51 media_content
= [media_content
]
52 for media_data
in media_content
:
53 media
= media_data
['@attributes']
54 media_type
= media
['type']
55 if media_type
== 'video/f4m':
56 formats
.extend(self
._extract
_f
4m
_formats
(
57 media
['url'] + '?hdcore=3.4.0&plugin=aasp-3.4.0.132.124',
58 video_id
, f4m_id
='hds', fatal
=False))
59 elif media_type
== 'application/x-mpegURL':
60 formats
.extend(self
._extract
_m
3u8_formats
(
61 media
['url'], video_id
, 'mp4', m3u8_id
='hls', fatal
=False))
64 'format_id': media_data
['media-category']['@attributes']['label'],
66 'tbr': int_or_none(media
.get('bitrate')),
67 'filesize': int_or_none(media
.get('fileSize')),
70 self
._sort
_formats
(formats
)
74 'title': get_media_node('title'),
75 'description': get_media_node('description'),
76 'thumbnails': thumbnails
,
77 'timestamp': parse_iso8601(item
.get('pubDate'), ' '),
78 'duration': int_or_none(media_content
[0].get('@attributes', {}).get('duration')),
79 'subtitles': subtitles
,