X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2Fextractor%2Faudiomack.py;h=3eed91279fd7b6ead45bf3ee01486eab53b91d6a;hb=9f0ee2a3883ec6f6fdccba90085cb925aaa2f617;hp=73cde78d319e71a13c3b53ad096614001c21e689;hpb=ff0813313ac33b6abd03e9322b706dc83c5aeb14;p=youtube-dl diff --git a/youtube_dl/extractor/audiomack.py b/youtube_dl/extractor/audiomack.py index 73cde78d3..3eed91279 100644 --- a/youtube_dl/extractor/audiomack.py +++ b/youtube_dl/extractor/audiomack.py @@ -1,11 +1,15 @@ # coding: utf-8 from __future__ import unicode_literals +import itertools +import time + from .common import InfoExtractor from .soundcloud import SoundcloudIE -from ..utils import ExtractorError - -import time +from ..utils import ( + ExtractorError, + url_basename, +) class AudiomackIE(InfoExtractor): @@ -19,7 +23,7 @@ class AudiomackIE(InfoExtractor): { 'id': '310086', 'ext': 'mp3', - 'artist': 'Roosh Williams', + 'uploader': 'Roosh Williams', 'title': 'Extraordinary' } }, @@ -38,17 +42,6 @@ class AudiomackIE(InfoExtractor): }, ] - @staticmethod - def create_song_dictionary(api_response, album_url_tag, track_no=0): - # All keys are the same in audiomack api and InfoExtractor format - entry = {key: api_response[key] for key in ['title', 'artist', 'id', 'url'] if key in api_response} - # Fudge values in the face of missing metadata - if 'id' not in entry: - entry['id'] = track_no - if 'title' not in entry: - entry['title'] = album_url_tag - return entry - def _real_extract(self, url): # URLs end with [uploader name]/[uploader title] # this title is whatever the user types in, and is rarely @@ -63,14 +56,19 @@ class AudiomackIE(InfoExtractor): # API is inconsistent with errors if 'url' not in api_response or not api_response['url'] or 'error' in api_response: - raise ExtractorError('Invalid url %s', url) + raise ExtractorError('Invalid url %s' % url) # Audiomack wraps a lot of soundcloud tracks in their branded wrapper # if so, pass the work off to the soundcloud extractor if SoundcloudIE.suitable(api_response['url']): return {'_type': 'url', 'url': api_response['url'], 'ie_key': 'Soundcloud'} - return self.create_song_dictionary(api_response, album_url_tag) + return { + 'id': api_response.get('id', album_url_tag), + 'uploader': api_response.get('artist'), + 'title': api_response.get('title'), + 'url': api_response['url'], + } class AudiomackAlbumIE(InfoExtractor): @@ -90,7 +88,22 @@ class AudiomackAlbumIE(InfoExtractor): # Album playlist ripped from fakeshoredrive with no metadata { 'url': 'http://www.audiomack.com/album/fakeshoredrive/ppp-pistol-p-project', - 'playlist_count': 10 + 'info_dict': { + 'title': 'PPP (Pistol P Project)', + 'id': '837572', + }, + 'playlist': [{ + 'info_dict': { + 'title': 'PPP (Pistol P Project) - 9. Heaven or Hell (CHIMACA) ft Zuse (prod by DJ FU)', + 'id': '837577', + 'ext': 'mp3', + 'uploader': 'Lil Herb a.k.a. G Herbo', + } + }], + 'params': { + 'playliststart': 9, + 'playlistend': 9, + } } ] @@ -102,11 +115,12 @@ class AudiomackAlbumIE(InfoExtractor): result = {'_type': 'playlist', 'entries': []} # There is no one endpoint for album metadata - instead it is included/repeated in each song's metadata # Therefore we don't know how many songs the album has and must infi-loop until failure - track_no = 0 - while True: + for track_no in itertools.count(): # Get song's metadata - api_response = self._download_json('http://www.audiomack.com/api/music/url/album/%s/%d?extended=1&_=%d' - % (album_url_tag, track_no, time.time()), album_url_tag) + api_response = self._download_json( + 'http://www.audiomack.com/api/music/url/album/%s/%d?extended=1&_=%d' + % (album_url_tag, track_no, time.time()), album_url_tag, + note='Querying song information (%d)' % (track_no + 1)) # Total failure, only occurs when url is totally wrong # Won't happen in middle of valid playlist (next case) @@ -120,6 +134,11 @@ class AudiomackAlbumIE(InfoExtractor): for resultkey, apikey in [('id', 'album_id'), ('title', 'album_title')]: if apikey in api_response and resultkey not in result: result[resultkey] = api_response[apikey] - result['entries'].append(AudiomackIE.create_song_dictionary(api_response, album_url_tag, track_no)) - track_no += 1 + song_id = url_basename(api_response['url']).rpartition('.')[0] + result['entries'].append({ + 'id': api_response.get('id', song_id), + 'uploader': api_response.get('artist'), + 'title': api_response.get('title', song_id), + 'url': api_response['url'], + }) return result