]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/amp.py
   2 from __future__ 
import unicode_literals
 
   4 from .common 
import InfoExtractor
 
  15 class AMPIE(InfoExtractor
): 
  16     # parse Akamai Adaptive Media Player feed 
  17     def _extract_feed_info(self
, url
): 
  18         feed 
= self
._download
_json
( 
  19             url
, None, 'Downloading Akamai AMP feed', 
  20             'Unable to download Akamai AMP feed') 
  21         item 
= feed
.get('channel', {}).get('item') 
  23             raise ExtractorError('%s said: %s' % (self
.IE_NAME
, feed
['error'])) 
  25         video_id 
= item
['guid'] 
  27         def get_media_node(name
, default
=None): 
  28             media_name 
= 'media-%s' % name
 
  29             media_group 
= item
.get('media-group') or item
 
  30             return media_group
.get(media_name
) or item
.get(media_name
) or item
.get(name
, default
) 
  33         media_thumbnail 
= get_media_node('thumbnail') 
  35             if isinstance(media_thumbnail
, dict): 
  36                 media_thumbnail 
= [media_thumbnail
] 
  37             for thumbnail_data 
in media_thumbnail
: 
  38                 thumbnail 
= thumbnail_data
.get('@attributes', {}) 
  39                 thumbnail_url 
= url_or_none(thumbnail
.get('url')) 
  43                     'url': self
._proto
_relative
_url
(thumbnail_url
, 'http:'), 
  44                     'width': int_or_none(thumbnail
.get('width')), 
  45                     'height': int_or_none(thumbnail
.get('height')), 
  49         media_subtitle 
= get_media_node('subTitle') 
  51             if isinstance(media_subtitle
, dict): 
  52                 media_subtitle 
= [media_subtitle
] 
  53             for subtitle_data 
in media_subtitle
: 
  54                 subtitle 
= subtitle_data
.get('@attributes', {}) 
  55                 subtitle_href 
= url_or_none(subtitle
.get('href')) 
  58                 subtitles
.setdefault(subtitle
.get('lang') or 'en', []).append({ 
  60                     'ext': mimetype2ext(subtitle
.get('type')) or determine_ext(subtitle_href
), 
  64         media_content 
= get_media_node('content') 
  65         if isinstance(media_content
, dict): 
  66             media_content 
= [media_content
] 
  67         for media_data 
in media_content
: 
  68             media 
= media_data
.get('@attributes', {}) 
  69             media_url 
= url_or_none(media
.get('url')) 
  72             ext 
= mimetype2ext(media
.get('type')) or determine_ext(media_url
) 
  74                 formats
.extend(self
._extract
_f
4m
_formats
( 
  75                     media_url 
+ '?hdcore=3.4.0&plugin=aasp-3.4.0.132.124', 
  76                     video_id
, f4m_id
='hds', fatal
=False)) 
  78                 formats
.extend(self
._extract
_m
3u8_formats
( 
  79                     media_url
, video_id
, 'mp4', m3u8_id
='hls', fatal
=False)) 
  82                     'format_id': media_data
.get('media-category', {}).get('@attributes', {}).get('label'), 
  84                     'tbr': int_or_none(media
.get('bitrate')), 
  85                     'filesize': int_or_none(media
.get('fileSize')), 
  89         self
._sort
_formats
(formats
) 
  91         timestamp 
= parse_iso8601(item
.get('pubDate'), ' ') or parse_iso8601(item
.get('dc-date')) 
  95             'title': get_media_node('title'), 
  96             'description': get_media_node('description'), 
  97             'thumbnails': thumbnails
, 
  98             'timestamp': timestamp
, 
  99             'duration': int_or_none(media_content
[0].get('@attributes', {}).get('duration')), 
 100             'subtitles': subtitles
,