diff --git a/youtube_dl/extractor/deezer.py b/youtube_dl/extractor/deezer.py index 98ae6e4e3..b274dbf29 100644 --- a/youtube_dl/extractor/deezer.py +++ b/youtube_dl/extractor/deezer.py @@ -50,34 +50,78 @@ def getformat(song): return 1 +class Format: + def __init__(self, name, fmtid, ext, bitrate): + self.name = name + self.formatid = fmtid + self.extension = ext + self.bitrate = bitrate + + +_formatinfo = { + 'MP3_MISC': Format('MP3_MISC', 0, 'mp3', 128), + 'MP3_128': Format('MP3_128', 1, 'mp3', 128), + # 2 used to be MP3_192 + 'MP3_320': Format('MP3_320', 3, 'mp3', 320), + # 4 used to be AAC_96 + 'MP3_256': Format('MP3_256', 5, 'mp3', 256), + 'AAC_64': Format('AAC_64', 6, 'aac', 64), # used to be AAC_192 + 'MP3_192': Format('MP3_192', 7, 'mp3', 192), + 'AAC_96': Format('AAC_96', 8, 'aac', 96), + 'FLAC': Format('FLAC', 9, 'flac', 0), + 'MP3_64': Format('MP3_64', 10, 'mp3', 64), + 'MP3_32': Format('MP3_32', 11, 'mp3', 32), +} + + +def convert_to_int(x): + try: + return int(x) + except: + return 0 + + +def songformats(s): + """ + Enumerate all formats for a song + """ + for k, v in s.items(): + if k.startswith("FILESIZE_") and convert_to_int(v): + name = k[9:] + if name in _formatinfo: + yield _formatinfo[name] + + class DeezerPlaylistIE(InfoExtractor): - _VALID_URL = r'https?://(?:www\.)?deezer\.com/\w+/(?P[0-9]+)' + _VALID_URL = r'https?://(?:www\.)?deezer\.com/(?P\w+)/(?P[0-9]+)' _TEST = { 'url': 'http://www.deezer.com/playlist/176747451', 'info_dict': { 'id': '176747451', 'title': 'Best!', - 'uploader': 'Anonymous', - 'thumbnail': r're:^https?://cdn-images.deezer.com/images/cover/.*\.jpg$', + 'uploader': 'anonymous', + 'thumbnail': r're:^https?://\S*cdn-images.deezer.com/images/playlist/.*\.jpg$', }, 'playlist_count': 30, - 'skip': 'Only available in .de', } def _real_extract(self, url): mobj = re.match(self._VALID_URL, url) - playlist_id = mobj.group('id') + list_id = mobj.group('id') + list_type = mobj.group('type') - webpage = self._download_webpage(url, playlist_id) + webpage = self._download_webpage(url, list_id) geoblocking_msg = self._html_search_regex( - r'

(.*?)

', webpage, 'geoblocking message', + r'
', @@ -85,39 +129,48 @@ class DeezerPlaylistIE(InfoExtractor): webpage, 'data JSON') data = json.loads(data_json) - playlist_title = data.get('DATA', {}).get('TITLE') - playlist_uploader = data.get('DATA', {}).get('PARENT_USERNAME') - # playlist_thumbnail = self._search_regex( r'