from __future__ import unicode_literals import json import re from .common import InfoExtractor from ..utils import ( ExtractorError, int_or_none, orderedSet, ) class DeezerBaseInfoExtractor(InfoExtractor): def get_data(self, url): if not self._downloader.params.get('test'): self._downloader.report_warning('For now, this extractor only supports the 30 second previews. Patches welcome!') mobj = re.match(self._VALID_URL, url) data_id = mobj.group('id') webpage = self._download_webpage(url, data_id) geoblocking_msg = self._html_search_regex( r'
(.*?)
', webpage, 'geoblocking message', default=None) if geoblocking_msg is not None: raise ExtractorError( 'Deezer said: %s' % geoblocking_msg, expected=True) data_json = self._search_regex( (r'__DZR_APP_STATE__\s*=\s*({.+?})\s*', r'naboo\.display\(\'[^\']+\',\s*(.*?)\);\n'), webpage, 'data JSON') data = json.loads(data_json) return data_id, webpage, data class DeezerPlaylistIE(DeezerBaseInfoExtractor): _VALID_URL = r'https?://(?:www\.)?deezer\.com/(../)?playlist/(?P