1 from __future__ import unicode_literals
3 from .common import InfoExtractor
4 from ..compat import compat_urllib_parse_urlencode
11 class NprIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?npr\.org/player/v2/mediaPlayer\.html\?.*\bid=(?P<id>\d+)'
14 'url': 'http://www.npr.org/player/v2/mediaPlayer.html?id=449974205',
17 'title': 'New Music From Beach House, Chairlift, CMJ Discoveries And More'
21 'url': 'http://www.npr.org/player/v2/mediaPlayer.html?action=1&t=1&islist=false&id=446928052&m=446929930&live=1',
24 'title': "Songs We Love: Tigran Hamasyan, 'Your Mercy is Boundless'"
27 'md5': '12fa60cb2d3ed932f53609d4aeceabf1',
31 'title': 'Your Mercy is Boundless (Bazum en Qo gtutyunqd)',
37 def _real_extract(self, url):
38 playlist_id = self._match_id(url)
40 config = self._download_json(
41 'http://api.npr.org/query?%s' % compat_urllib_parse_urlencode({
43 'fields': 'titles,audio,show',
45 'apiKey': 'MDAzMzQ2MjAyMDEyMzk4MTU1MDg3ZmM3MQ010',
48 story = config['list']['story'][0]
50 KNOWN_FORMATS = ('threegp', 'mp4', 'mp3')
51 quality = qualities(KNOWN_FORMATS)
54 for audio in story.get('audio', []):
55 title = audio.get('title', {}).get('$text')
56 duration = int_or_none(audio.get('duration', {}).get('$text'))
58 for format_id, formats_entry in audio.get('format', {}).items():
61 if isinstance(formats_entry, list):
62 formats_entry = formats_entry[0]
63 format_url = formats_entry.get('$text')
66 if format_id in KNOWN_FORMATS:
69 'format_id': format_id,
70 'ext': formats_entry.get('type'),
71 'quality': quality(format_id),
73 self._sort_formats(formats)
81 playlist_title = story.get('title', {}).get('$text')
82 return self.playlist_result(entries, playlist_id, playlist_title)