parent
e7e3ec828b
commit
68867668cf
|
@ -1,7 +1,6 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..compat import compat_urllib_parse_urlencode
|
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
int_or_none,
|
int_or_none,
|
||||||
qualities,
|
qualities,
|
||||||
|
@ -9,16 +8,16 @@ from ..utils import (
|
||||||
|
|
||||||
|
|
||||||
class NprIE(InfoExtractor):
|
class NprIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?npr\.org/player/v2/mediaPlayer\.html\?.*\bid=(?P<id>\d+)'
|
_VALID_URL = r'https?://(?:www\.)?npr\.org/(?:sections/[^/]+/)?\d{4}/\d{2}/\d{2}/(?P<id>\d+)'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'http://www.npr.org/player/v2/mediaPlayer.html?id=449974205',
|
'url': 'https://www.npr.org/sections/allsongs/2015/10/21/449974205/new-music-from-beach-house-chairlift-cmj-discoveries-and-more',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '449974205',
|
'id': '449974205',
|
||||||
'title': 'New Music From Beach House, Chairlift, CMJ Discoveries And More'
|
'title': 'New Music From Beach House, Chairlift, CMJ Discoveries And More'
|
||||||
},
|
},
|
||||||
'playlist_count': 7,
|
'playlist_count': 7,
|
||||||
}, {
|
}, {
|
||||||
'url': 'http://www.npr.org/player/v2/mediaPlayer.html?action=1&t=1&islist=false&id=446928052&m=446929930&live=1',
|
'url': 'https://www.npr.org/sections/deceptivecadence/2015/10/09/446928052/music-from-the-shadows-ancient-armenian-hymns-and-piano-jazz',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '446928052',
|
'id': '446928052',
|
||||||
'title': "Songs We Love: Tigran Hamasyan, 'Your Mercy is Boundless'"
|
'title': "Songs We Love: Tigran Hamasyan, 'Your Mercy is Boundless'"
|
||||||
|
@ -32,30 +31,46 @@ class NprIE(InfoExtractor):
|
||||||
'duration': 402,
|
'duration': 402,
|
||||||
},
|
},
|
||||||
}],
|
}],
|
||||||
|
}, {
|
||||||
|
# mutlimedia, not media title
|
||||||
|
'url': 'https://www.npr.org/2017/06/19/533198237/tigers-jaw-tiny-desk-concert',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '533198237',
|
||||||
|
'title': 'Tigers Jaw: Tiny Desk Concert',
|
||||||
|
},
|
||||||
|
'playlist': [{
|
||||||
|
'md5': '12fa60cb2d3ed932f53609d4aeceabf1',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '533201718',
|
||||||
|
'ext': 'mp4',
|
||||||
|
'title': 'Tigers Jaw: Tiny Desk Concert',
|
||||||
|
'duration': 402,
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
'expected_warnings': ['Failed to download m3u8 information'],
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
playlist_id = self._match_id(url)
|
playlist_id = self._match_id(url)
|
||||||
|
|
||||||
config = self._download_json(
|
story = self._download_json(
|
||||||
'http://api.npr.org/query?%s' % compat_urllib_parse_urlencode({
|
'http://api.npr.org/query', playlist_id, query={
|
||||||
'id': playlist_id,
|
'id': playlist_id,
|
||||||
'fields': 'titles,audio,show',
|
'fields': 'audio,multimedia,title',
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
'apiKey': 'MDAzMzQ2MjAyMDEyMzk4MTU1MDg3ZmM3MQ010',
|
'apiKey': 'MDAzMzQ2MjAyMDEyMzk4MTU1MDg3ZmM3MQ010',
|
||||||
}), playlist_id)
|
})['list']['story'][0]
|
||||||
|
playlist_title = story.get('title', {}).get('$text')
|
||||||
|
|
||||||
story = config['list']['story'][0]
|
KNOWN_FORMATS = ('threegp', 'm3u8', 'smil', 'mp4', 'mp3')
|
||||||
|
|
||||||
KNOWN_FORMATS = ('threegp', 'mp4', 'mp3')
|
|
||||||
quality = qualities(KNOWN_FORMATS)
|
quality = qualities(KNOWN_FORMATS)
|
||||||
|
|
||||||
entries = []
|
entries = []
|
||||||
for audio in story.get('audio', []):
|
for media in story.get('audio', []) + story.get('multimedia', []):
|
||||||
title = audio.get('title', {}).get('$text')
|
media_id = media['id']
|
||||||
duration = int_or_none(audio.get('duration', {}).get('$text'))
|
|
||||||
formats = []
|
formats = []
|
||||||
for format_id, formats_entry in audio.get('format', {}).items():
|
for format_id, formats_entry in media.get('format', {}).items():
|
||||||
if not formats_entry:
|
if not formats_entry:
|
||||||
continue
|
continue
|
||||||
if isinstance(formats_entry, list):
|
if isinstance(formats_entry, list):
|
||||||
|
@ -64,19 +79,30 @@ class NprIE(InfoExtractor):
|
||||||
if not format_url:
|
if not format_url:
|
||||||
continue
|
continue
|
||||||
if format_id in KNOWN_FORMATS:
|
if format_id in KNOWN_FORMATS:
|
||||||
formats.append({
|
if format_id == 'm3u8':
|
||||||
'url': format_url,
|
formats.extend(self._extract_m3u8_formats(
|
||||||
'format_id': format_id,
|
format_url, media_id, 'mp4', 'm3u8_native',
|
||||||
'ext': formats_entry.get('type'),
|
m3u8_id='hls', fatal=False))
|
||||||
'quality': quality(format_id),
|
elif format_id == 'smil':
|
||||||
})
|
smil_formats = self._extract_smil_formats(
|
||||||
|
format_url, media_id, transform_source=lambda s: s.replace(
|
||||||
|
'rtmp://flash.npr.org/ondemand/', 'https://ondemand.npr.org/'))
|
||||||
|
self._check_formats(smil_formats, media_id)
|
||||||
|
formats.extend(smil_formats)
|
||||||
|
else:
|
||||||
|
formats.append({
|
||||||
|
'url': format_url,
|
||||||
|
'format_id': format_id,
|
||||||
|
'quality': quality(format_id),
|
||||||
|
})
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
entries.append({
|
entries.append({
|
||||||
'id': audio['id'],
|
'id': media_id,
|
||||||
'title': title,
|
'title': media.get('title', {}).get('$text') or playlist_title,
|
||||||
'duration': duration,
|
'thumbnail': media.get('altImageUrl', {}).get('$text'),
|
||||||
|
'duration': int_or_none(media.get('duration', {}).get('$text')),
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
})
|
})
|
||||||
|
|
||||||
playlist_title = story.get('title', {}).get('$text')
|
|
||||||
return self.playlist_result(entries, playlist_id, playlist_title)
|
return self.playlist_result(entries, playlist_id, playlist_title)
|
||||||
|
|
Loading…
Reference in New Issue