2015-11-07 15:54:35 +00:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
from ..utils import (
|
|
|
|
int_or_none,
|
|
|
|
parse_iso8601,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class AMPIE(InfoExtractor):
|
|
|
|
# parse Akamai Adaptive Media Player feed
|
|
|
|
def _extract_feed_info(self, url):
|
|
|
|
item = self._download_json(
|
2015-12-21 10:12:58 +00:00
|
|
|
url, None, 'Downloading Akamai AMP feed',
|
|
|
|
'Unable to download Akamai AMP feed')['channel']['item']
|
2015-11-07 15:54:35 +00:00
|
|
|
|
|
|
|
video_id = item['guid']
|
2015-12-21 10:12:58 +00: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 15:54:35 +00:00
|
|
|
thumbnails = []
|
2015-12-21 10:12:58 +00:00
|
|
|
media_thumbnail = get_media_node('thumbnail')
|
2015-11-07 15:54:35 +00: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 10:12:58 +00:00
|
|
|
media_subtitle = get_media_node('subTitle')
|
2015-11-07 15:54:35 +00: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 10:12:58 +00:00
|
|
|
media_content = get_media_node('content')
|
2015-11-07 15:54:35 +00:00
|
|
|
if isinstance(media_content, dict):
|
|
|
|
media_content = [media_content]
|
|
|
|
for media_data in media_content:
|
|
|
|
media = media_data['@attributes']
|
|
|
|
media_type = media['type']
|
2016-05-17 07:38:57 +00:00
|
|
|
if media_type in ('video/f4m', 'application/f4m+xml'):
|
2015-12-28 18:58:24 +00:00
|
|
|
formats.extend(self._extract_f4m_formats(
|
2015-12-21 10:12:58 +00:00
|
|
|
media['url'] + '?hdcore=3.4.0&plugin=aasp-3.4.0.132.124',
|
2015-12-28 18:58:24 +00:00
|
|
|
video_id, f4m_id='hds', fatal=False))
|
2015-11-07 15:54:35 +00:00
|
|
|
elif media_type == 'application/x-mpegURL':
|
2015-12-28 18:58:24 +00:00
|
|
|
formats.extend(self._extract_m3u8_formats(
|
|
|
|
media['url'], video_id, 'mp4', m3u8_id='hls', fatal=False))
|
2015-11-07 15:54:35 +00:00
|
|
|
else:
|
|
|
|
formats.append({
|
2016-05-17 07:38:57 +00:00
|
|
|
'format_id': media_data.get('media-category', {}).get('@attributes', {}).get('label'),
|
2015-11-07 15:54:35 +00:00
|
|
|
'url': media['url'],
|
2015-12-21 10:12:58 +00:00
|
|
|
'tbr': int_or_none(media.get('bitrate')),
|
2015-11-07 15:54:35 +00:00
|
|
|
'filesize': int_or_none(media.get('fileSize')),
|
|
|
|
})
|
|
|
|
|
|
|
|
self._sort_formats(formats)
|
|
|
|
|
2016-03-27 19:13:47 +00:00
|
|
|
timestamp = parse_iso8601(item.get('pubDate'), ' ') or parse_iso8601(item.get('dc-date'))
|
|
|
|
|
2015-11-07 15:54:35 +00:00
|
|
|
return {
|
|
|
|
'id': video_id,
|
2015-12-21 10:12:58 +00:00
|
|
|
'title': get_media_node('title'),
|
|
|
|
'description': get_media_node('description'),
|
2015-11-07 15:54:35 +00:00
|
|
|
'thumbnails': thumbnails,
|
2016-03-27 19:13:47 +00:00
|
|
|
'timestamp': timestamp,
|
2015-11-07 15:54:35 +00:00
|
|
|
'duration': int_or_none(media_content[0].get('@attributes', {}).get('duration')),
|
2016-01-04 19:05:37 +00:00
|
|
|
'subtitles': subtitles,
|
2015-11-07 15:54:35 +00:00
|
|
|
'formats': formats,
|
|
|
|
}
|