diff --git a/youtube_dl/extractor/npr.py b/youtube_dl/extractor/npr.py index d389e30ba..0e4146c05 100644 --- a/youtube_dl/extractor/npr.py +++ b/youtube_dl/extractor/npr.py @@ -27,45 +27,45 @@ class NprIE(InfoExtractor): webpage = self._download_webpage(webpage_url, video_id) key = 'MDAzMzQ2MjAyMDEyMzk4MTU1MDg3ZmM3MQ010' xml_url = 'http://api.npr.org/query?id=%s&apiKey=%s' % (video_id, key) + json_url = 'http://api.npr.org/query?id=%s&apiKey=%s&format=json' % (video_id, key) - config = self._download_xml(xml_url,video_id, note='Downloading XML') - - audio = config.findall('./list/story/audio[@type="standard"]') - if not audio: - # audio type is primary - audio = config.findall('./list/story/audio[@type="primary"]') - - regex = ('.//*[@type="mp3"]','.//*[@type="m3u"]','.//format/wm','.//format/threegp','.//format/mp4','.//format/hls','.//format/mediastream') - album_title = config.find('.//albumTitle') - - if not album_title: - album_title = config.find('./list/story/title').text - else: - album_title = album_title.text - - print(album_title) - format = [] + formats = [] entries = [] - for song in audio: - song_title = song.find('title').text - song_id = song.get('id') - song_duration = song.find('duration').text - for r in regex: - t = song.find(r) - if t is not None: - format.append({'format': t.get('type', t.tag), - 'url' : t.text}) + config = self._download_json(json_url, video_id) - entries.append({ "title":song_title, - "id":song_id, - "duration": str(int(song_duration) / 60) +":"+ str(int(song_duration) % 60) , - "formats":format}) - format = [] + content = config["list"]["story"] - return { - '_type': 'playlist', - 'id' : video_id, - 'title' : album_title, - 'entries': entries - } \ No newline at end of file + album_title = config["list"]["story"][0]['song'][0]['album']['albumTitle'] + print album_title['$text'] + + for key in content: + if "audio" in key: + for x in key['audio']: + if x['type'] == 'standard': + playlist = True + song_duration = x["duration"]['$text'] + song_title = x["title"]["$text"] + song_id = x["id"] + + for k in x["format"]: + if type(x["format"][k]) is list: + for z in x["format"][k]: + formats.append({ 'format': z['type'], + 'url' : z['$text'] + }) + else: + formats.append({ 'format': k, + 'url' : x["format"][k]['$text'] + }) + + entries.append({ "title":song_title, + "id":song_id, + "duration": song_duration , + "formats":formats}) + formats = [] + + return { '_type': 'playlist', + 'id' : video_id, + 'title' : album_title, + 'entries': entries } \ No newline at end of file