1 from __future__ import unicode_literals
3 from .common import InfoExtractor
10 class NprIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:www\.)?npr\.org/(?:sections/[^/]+/)?\d{4}/\d{2}/\d{2}/(?P<id>\d+)'
13 'url': 'https://www.npr.org/sections/allsongs/2015/10/21/449974205/new-music-from-beach-house-chairlift-cmj-discoveries-and-more',
16 'title': 'New Music From Beach House, Chairlift, CMJ Discoveries And More'
20 'url': 'https://www.npr.org/sections/deceptivecadence/2015/10/09/446928052/music-from-the-shadows-ancient-armenian-hymns-and-piano-jazz',
23 'title': "Songs We Love: Tigran Hamasyan, 'Your Mercy is Boundless'"
26 'md5': '12fa60cb2d3ed932f53609d4aeceabf1',
30 'title': 'Your Mercy is Boundless (Bazum en Qo gtutyunqd)',
35 # mutlimedia, not media title
36 'url': 'https://www.npr.org/2017/06/19/533198237/tigers-jaw-tiny-desk-concert',
39 'title': 'Tigers Jaw: Tiny Desk Concert',
42 'md5': '12fa60cb2d3ed932f53609d4aeceabf1',
46 'title': 'Tigers Jaw: Tiny Desk Concert',
50 'expected_warnings': ['Failed to download m3u8 information'],
53 def _real_extract(self, url):
54 playlist_id = self._match_id(url)
56 story = self._download_json(
57 'http://api.npr.org/query', playlist_id, query={
59 'fields': 'audio,multimedia,title',
61 'apiKey': 'MDAzMzQ2MjAyMDEyMzk4MTU1MDg3ZmM3MQ010',
62 })['list']['story'][0]
63 playlist_title = story.get('title', {}).get('$text')
65 KNOWN_FORMATS = ('threegp', 'm3u8', 'smil', 'mp4', 'mp3')
66 quality = qualities(KNOWN_FORMATS)
69 for media in story.get('audio', []) + story.get('multimedia', []):
70 media_id = media['id']
73 for format_id, formats_entry in media.get('format', {}).items():
76 if isinstance(formats_entry, list):
77 formats_entry = formats_entry[0]
78 format_url = formats_entry.get('$text')
81 if format_id in KNOWN_FORMATS:
82 if format_id == 'm3u8':
83 formats.extend(self._extract_m3u8_formats(
84 format_url, media_id, 'mp4', 'm3u8_native',
85 m3u8_id='hls', fatal=False))
86 elif format_id == 'smil':
87 smil_formats = self._extract_smil_formats(
88 format_url, media_id, transform_source=lambda s: s.replace(
89 'rtmp://flash.npr.org/ondemand/', 'https://ondemand.npr.org/'))
90 self._check_formats(smil_formats, media_id)
91 formats.extend(smil_formats)
95 'format_id': format_id,
96 'quality': quality(format_id),
98 self._sort_formats(formats)
102 'title': media.get('title', {}).get('$text') or playlist_title,
103 'thumbnail': media.get('altImageUrl', {}).get('$text'),
104 'duration': int_or_none(media.get('duration', {}).get('$text')),
108 return self.playlist_result(entries, playlist_id, playlist_title)