[npr] Requested fixes
This commit is contained in:
parent
24ce9e5f51
commit
b97e947558
@ -710,7 +710,7 @@ from .npo import (
|
|||||||
WNLIE,
|
WNLIE,
|
||||||
)
|
)
|
||||||
from .npr import (
|
from .npr import (
|
||||||
NprPlaylistIE,
|
NprIE,
|
||||||
NprVideoIE,
|
NprVideoIE,
|
||||||
)
|
)
|
||||||
from .nrk import (
|
from .nrk import (
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import int_or_none
|
from ..utils import (
|
||||||
|
int_or_none,
|
||||||
|
ExtractorError
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class NprBaseIE(InfoExtractor):
|
class NprBaseIE(InfoExtractor):
|
||||||
def extract_info(self, id):
|
def _extract_info(self, id_):
|
||||||
json_data = self._download_json(
|
json_data = self._download_json(
|
||||||
'http://api.npr.org/query', id, query={
|
'http://api.npr.org/query', id_, query={
|
||||||
'id': id,
|
'id': id_,
|
||||||
'fields': 'titles,audio,show,multimedia,text',
|
'fields': 'titles,audio,show,multimedia,text',
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
'apiKey': 'MDAzMzQ2MjAyMDEyMzk4MTU1MDg3ZmM3MQ010',
|
'apiKey': 'MDAzMzQ2MjAyMDEyMzk4MTU1MDg3ZmM3MQ010',
|
||||||
@ -16,7 +21,7 @@ class NprBaseIE(InfoExtractor):
|
|||||||
|
|
||||||
return json_data['list']['story'][0]
|
return json_data['list']['story'][0]
|
||||||
|
|
||||||
def extract_formats(self, media_info):
|
def _extract_formats(self, media_info):
|
||||||
FORMATS_ = {
|
FORMATS_ = {
|
||||||
'hls': 'm3u8', 'hlsOnDemand': 'm3u8', 'mediastream': 'mp3',
|
'hls': 'm3u8', 'hlsOnDemand': 'm3u8', 'mediastream': 'mp3',
|
||||||
'mp3': 'mp3', 'mp4': 'mp4', 'wm': 'wm', 'threegp': '3gp'
|
'mp3': 'mp3', 'mp4': 'mp4', 'wm': 'wm', 'threegp': '3gp'
|
||||||
@ -39,9 +44,18 @@ class NprBaseIE(InfoExtractor):
|
|||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
elif format_id == 'm3u8':
|
elif format_id == 'm3u8':
|
||||||
# Error 404 for some reason
|
mobj = re.match(
|
||||||
|
r'(?P<baseurl>https?:.+?akamaihd.+?-n-)(?P<qualities>(?:,*\d+)+)',
|
||||||
|
format_url
|
||||||
|
)
|
||||||
|
if mobj is None:
|
||||||
|
continue
|
||||||
|
m3u8_base = mobj.group('baseurl')
|
||||||
|
qualities = re.findall(r'(\d+)', mobj.group('qualities'))
|
||||||
|
|
||||||
|
for quality in qualities:
|
||||||
formats += self._extract_m3u8_formats(
|
formats += self._extract_m3u8_formats(
|
||||||
format_url,
|
m3u8_base + '%s.mp4/master.m3u8' % quality,
|
||||||
media_info['id'],
|
media_info['id'],
|
||||||
fatal=False
|
fatal=False
|
||||||
)
|
)
|
||||||
@ -51,10 +65,11 @@ class NprBaseIE(InfoExtractor):
|
|||||||
'format_id': format_id,
|
'format_id': format_id,
|
||||||
'ext': FORMATS_.get(format_id),
|
'ext': FORMATS_.get(format_id),
|
||||||
})
|
})
|
||||||
|
self._sort_formats(formats)
|
||||||
return formats
|
return formats
|
||||||
|
|
||||||
|
|
||||||
class NprPlaylistIE(NprBaseIE):
|
class NprIE(NprBaseIE):
|
||||||
_VALID_URL = r'https?://(?:www\.)?npr\.org/(?:sections/\w+/\d+/\d+/\d+/|player/v2/mediaPlayer\.html\?.*\bid=)(?P<id>\d+)'
|
_VALID_URL = r'https?://(?:www\.)?npr\.org/(?:sections/\w+/\d+/\d+/\d+/|player/v2/mediaPlayer\.html\?.*\bid=)(?P<id>\d+)'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'http://www.npr.org/sections/allsongs/2015/10/21/449974205/new-music-from-beach-house-chairlift-cmj-discoveries-and-more',
|
'url': 'http://www.npr.org/sections/allsongs/2015/10/21/449974205/new-music-from-beach-house-chairlift-cmj-discoveries-and-more',
|
||||||
@ -73,7 +88,7 @@ class NprPlaylistIE(NprBaseIE):
|
|||||||
'md5': 'df2917b738fdd2358a9f0e7e49fcdf2e',
|
'md5': 'df2917b738fdd2358a9f0e7e49fcdf2e',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '446929930',
|
'id': '446929930',
|
||||||
# 'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Your Mercy is Boundless (Bazum en Qo gtutyunqd)',
|
'title': 'Your Mercy is Boundless (Bazum en Qo gtutyunqd)',
|
||||||
'duration': 402,
|
'duration': 402,
|
||||||
},
|
},
|
||||||
@ -82,7 +97,7 @@ class NprPlaylistIE(NprBaseIE):
|
|||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
playlist_id = self._match_id(url)
|
playlist_id = self._match_id(url)
|
||||||
story = self.extract_info(playlist_id)
|
story = self._extract_info(playlist_id)
|
||||||
|
|
||||||
entries = []
|
entries = []
|
||||||
for audio in story.get('audio', []):
|
for audio in story.get('audio', []):
|
||||||
@ -92,7 +107,7 @@ class NprPlaylistIE(NprBaseIE):
|
|||||||
'id': audio['id'],
|
'id': audio['id'],
|
||||||
'title': title,
|
'title': title,
|
||||||
'duration': duration,
|
'duration': duration,
|
||||||
'formats': self.extract_formats(audio),
|
'formats': self._extract_formats(audio),
|
||||||
})
|
})
|
||||||
|
|
||||||
playlist_title = story.get('title', {}).get('$text')
|
playlist_title = story.get('title', {}).get('$text')
|
||||||
@ -106,28 +121,30 @@ class NprVideoIE(NprBaseIE):
|
|||||||
'url': 'http://www.npr.org/event/music/533198237/tigers-jaw-tiny-desk-concert',
|
'url': 'http://www.npr.org/event/music/533198237/tigers-jaw-tiny-desk-concert',
|
||||||
'md5': '5b385e0e96c2731261df9a4ed1ff2cba',
|
'md5': '5b385e0e96c2731261df9a4ed1ff2cba',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '533201718',
|
'id': '533198237',
|
||||||
'display_id': '533198237',
|
|
||||||
'title': 'Tigers Jaw: Tiny Desk Concert',
|
'title': 'Tigers Jaw: Tiny Desk Concert',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'width': 624,
|
'width': 624,
|
||||||
'height': 351,
|
'height': 351,
|
||||||
}
|
},
|
||||||
|
'expected_warnings': ['HTTP Error 404'],
|
||||||
}
|
}
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
display_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
story = self.extract_info(display_id)
|
story = self._extract_info(video_id)
|
||||||
|
|
||||||
|
title = story.get('title', {}).get('$text')
|
||||||
|
if title is None:
|
||||||
|
ExtractorError('Fail extracting title')
|
||||||
|
|
||||||
video = story.get('multimedia')[0]
|
video = story.get('multimedia')[0]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'url': url,
|
'id': video_id,
|
||||||
'display_id': display_id,
|
'title': title,
|
||||||
'title': story.get('title', {}).get('$text'),
|
|
||||||
'id': video.get('id'),
|
|
||||||
'duration': int_or_none(video.get('duration', {}).get('$text')),
|
'duration': int_or_none(video.get('duration', {}).get('$text')),
|
||||||
'formats': self.extract_formats(video),
|
'formats': self._extract_formats(video),
|
||||||
'width': int_or_none(video.get('width', {}).get('$text')),
|
'width': int_or_none(video.get('width', {}).get('$text')),
|
||||||
'height': int_or_none(video.get('height', {}).get('$text')),
|
'height': int_or_none(video.get('height', {}).get('$text')),
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user