]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/npr.py
1 from __future__
import unicode_literals
3 from .common
import InfoExtractor
11 class NprIE(InfoExtractor
):
12 _VALID_URL
= r
'https?://(?:www\.)?npr\.org/(?:sections/[^/]+/)?\d{4}/\d{2}/\d{2}/(?P<id>\d+)'
14 'url': 'https://www.npr.org/sections/allsongs/2015/10/21/449974205/new-music-from-beach-house-chairlift-cmj-discoveries-and-more',
17 'title': 'New Music From Beach House, Chairlift, CMJ Discoveries And More'
21 'url': 'https://www.npr.org/sections/deceptivecadence/2015/10/09/446928052/music-from-the-shadows-ancient-armenian-hymns-and-piano-jazz',
24 'title': "Songs We Love: Tigran Hamasyan, 'Your Mercy is Boundless'"
27 'md5': '12fa60cb2d3ed932f53609d4aeceabf1',
31 'title': 'Your Mercy is Boundless (Bazum en Qo gtutyunqd)',
36 # mutlimedia, not media title
37 'url': 'https://www.npr.org/2017/06/19/533198237/tigers-jaw-tiny-desk-concert',
40 'title': 'Tigers Jaw: Tiny Desk Concert',
43 'md5': '12fa60cb2d3ed932f53609d4aeceabf1',
47 'title': 'Tigers Jaw: Tiny Desk Concert',
51 'expected_warnings': ['Failed to download m3u8 information'],
53 # multimedia, no formats, stream
54 'url': 'https://www.npr.org/2020/02/14/805476846/laura-stevenson-tiny-desk-concert',
55 'only_matching': True,
58 def _real_extract(self
, url
):
59 playlist_id
= self
._match
_id
(url
)
61 story
= self
._download
_json
(
62 'http://api.npr.org/query', playlist_id
, query
={
64 'fields': 'audio,multimedia,title',
66 'apiKey': 'MDAzMzQ2MjAyMDEyMzk4MTU1MDg3ZmM3MQ010',
67 })['list']['story'][0]
68 playlist_title
= story
.get('title', {}).get('$text')
70 KNOWN_FORMATS
= ('threegp', 'm3u8', 'smil', 'mp4', 'mp3')
71 quality
= qualities(KNOWN_FORMATS
)
74 for media
in story
.get('audio', []) + story
.get('multimedia', []):
75 media_id
= media
['id']
78 for format_id
, formats_entry
in media
.get('format', {}).items():
81 if isinstance(formats_entry
, list):
82 formats_entry
= formats_entry
[0]
83 format_url
= formats_entry
.get('$text')
86 if format_id
in KNOWN_FORMATS
:
87 if format_id
== 'm3u8':
88 formats
.extend(self
._extract
_m
3u8_formats
(
89 format_url
, media_id
, 'mp4', 'm3u8_native',
90 m3u8_id
='hls', fatal
=False))
91 elif format_id
== 'smil':
92 smil_formats
= self
._extract
_smil
_formats
(
93 format_url
, media_id
, transform_source
=lambda s
: s
.replace(
94 'rtmp://flash.npr.org/ondemand/', 'https://ondemand.npr.org/'))
95 self
._check
_formats
(smil_formats
, media_id
)
96 formats
.extend(smil_formats
)
100 'format_id': format_id
,
101 'quality': quality(format_id
),
103 for stream_id
, stream_entry
in media
.get('stream', {}).items():
104 if not isinstance(stream_entry
, dict):
106 if stream_id
!= 'hlsUrl':
108 stream_url
= url_or_none(stream_entry
.get('$text'))
111 formats
.extend(self
._extract
_m
3u8_formats
(
112 stream_url
, stream_id
, 'mp4', 'm3u8_native',
113 m3u8_id
='hls', fatal
=False))
114 self
._sort
_formats
(formats
)
118 'title': media
.get('title', {}).get('$text') or playlist_title
,
119 'thumbnail': media
.get('altImageUrl', {}).get('$text'),
120 'duration': int_or_none(media
.get('duration', {}).get('$text')),
124 return self
.playlist_result(entries
, playlist_id
, playlist_title
)