2015-11-07 07:54:35 -08:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
from ..utils import (
|
|
|
|
int_or_none,
|
|
|
|
parse_iso8601,
|
2016-07-06 01:11:46 -07:00
|
|
|
mimetype2ext,
|
|
|
|
determine_ext,
|
2017-04-19 21:16:41 -07:00
|
|
|
ExtractorError,
|
2015-11-07 07:54:35 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class AMPIE(InfoExtractor):
|
|
|
|
# parse Akamai Adaptive Media Player feed
|
|
|
|
def _extract_feed_info(self, url):
|
2017-04-19 21:16:41 -07:00
|
|
|
feed = self._download_json(
|
2015-12-21 02:12:58 -08:00
|
|
|
url, None, 'Downloading Akamai AMP feed',
|
2017-04-19 21:16:41 -07:00
|
|
|
'Unable to download Akamai AMP feed')
|
|
|
|
item = feed.get('channel', {}).get('item')
|
|
|
|
if not item:
|
|
|
|
raise ExtractorError('%s said: %s' % (self.IE_NAME, feed['error']))
|
2015-11-07 07:54:35 -08:00
|
|
|
|
|
|
|
video_id = item['guid']
|
2015-12-21 02:12:58 -08:00
|
|
|
|
|
|
|
def get_media_node(name, default=None):
|
|
|
|
media_name = 'media-%s' % name
|
|
|
|
media_group = item.get('media-group') or item
|
|
|
|
return media_group.get(media_name) or item.get(media_name) or item.get(name, default)
|
|
|
|
|
2015-11-07 07:54:35 -08:00
|
|
|
thumbnails = []
|
2015-12-21 02:12:58 -08:00
|
|
|
media_thumbnail = get_media_node('thumbnail')
|
2015-11-07 07:54:35 -08:00
|
|
|
if media_thumbnail:
|
|
|
|
if isinstance(media_thumbnail, dict):
|
|
|
|
media_thumbnail = [media_thumbnail]
|
|
|
|
for thumbnail_data in media_thumbnail:
|
|
|
|
thumbnail = thumbnail_data['@attributes']
|
|
|
|
thumbnails.append({
|
|
|
|
'url': self._proto_relative_url(thumbnail['url'], 'http:'),
|
|
|
|
'width': int_or_none(thumbnail.get('width')),
|
|
|
|
'height': int_or_none(thumbnail.get('height')),
|
|
|
|
})
|
|
|
|
|
|
|
|
subtitles = {}
|
2015-12-21 02:12:58 -08:00
|
|
|
media_subtitle = get_media_node('subTitle')
|
2015-11-07 07:54:35 -08:00
|
|
|
if media_subtitle:
|
|
|
|
if isinstance(media_subtitle, dict):
|
|
|
|
media_subtitle = [media_subtitle]
|
|
|
|
for subtitle_data in media_subtitle:
|
|
|
|
subtitle = subtitle_data['@attributes']
|
|
|
|
lang = subtitle.get('lang') or 'en'
|
|
|
|
subtitles[lang] = [{'url': subtitle['href']}]
|
|
|
|
|
|
|
|
formats = []
|
2015-12-21 02:12:58 -08:00
|
|
|
media_content = get_media_node('content')
|
2015-11-07 07:54:35 -08:00
|
|
|
if isinstance(media_content, dict):
|
|
|
|
media_content = [media_content]
|
|
|
|
for media_data in media_content:
|
2016-07-06 01:11:46 -07:00
|
|
|
media = media_data.get('@attributes', {})
|
|
|
|
media_url = media.get('url')
|
|
|
|
if not media_url:
|
|
|
|
continue
|
2016-07-06 05:10:47 -07:00
|
|
|
ext = mimetype2ext(media.get('type')) or determine_ext(media_url)
|
2016-07-06 01:11:46 -07:00
|
|
|
if ext == 'f4m':
|
2015-12-28 10:58:24 -08:00
|
|
|
formats.extend(self._extract_f4m_formats(
|
2016-07-06 01:11:46 -07:00
|
|
|
media_url + '?hdcore=3.4.0&plugin=aasp-3.4.0.132.124',
|
2015-12-28 10:58:24 -08:00
|
|
|
video_id, f4m_id='hds', fatal=False))
|
2016-07-06 01:11:46 -07:00
|
|
|
elif ext == 'm3u8':
|
2015-12-28 10:58:24 -08:00
|
|
|
formats.extend(self._extract_m3u8_formats(
|
2016-07-06 01:11:46 -07:00
|
|
|
media_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
|
2015-11-07 07:54:35 -08:00
|
|
|
else:
|
|
|
|
formats.append({
|
2016-05-17 00:38:57 -07:00
|
|
|
'format_id': media_data.get('media-category', {}).get('@attributes', {}).get('label'),
|
2015-11-07 07:54:35 -08:00
|
|
|
'url': media['url'],
|
2015-12-21 02:12:58 -08:00
|
|
|
'tbr': int_or_none(media.get('bitrate')),
|
2015-11-07 07:54:35 -08:00
|
|
|
'filesize': int_or_none(media.get('fileSize')),
|
2016-07-06 01:11:46 -07:00
|
|
|
'ext': ext,
|
2015-11-07 07:54:35 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
self._sort_formats(formats)
|
|
|
|
|
2016-03-27 12:13:47 -07:00
|
|
|
timestamp = parse_iso8601(item.get('pubDate'), ' ') or parse_iso8601(item.get('dc-date'))
|
|
|
|
|
2015-11-07 07:54:35 -08:00
|
|
|
return {
|
|
|
|
'id': video_id,
|
2015-12-21 02:12:58 -08:00
|
|
|
'title': get_media_node('title'),
|
|
|
|
'description': get_media_node('description'),
|
2015-11-07 07:54:35 -08:00
|
|
|
'thumbnails': thumbnails,
|
2016-03-27 12:13:47 -07:00
|
|
|
'timestamp': timestamp,
|
2015-11-07 07:54:35 -08:00
|
|
|
'duration': int_or_none(media_content[0].get('@attributes', {}).get('duration')),
|
2016-01-04 11:05:37 -08:00
|
|
|
'subtitles': subtitles,
|
2015-11-07 07:54:35 -08:00
|
|
|
'formats': formats,
|
|
|
|
}
|