From c7bab7c39fd51c0812f70020172766303191bc01 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 5 May 2024 19:37:42 +0200 Subject: Adding upstream version 2023.03.04. Signed-off-by: Daniel Baumann --- yt_dlp/extractor/deezer.py | 142 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 yt_dlp/extractor/deezer.py (limited to 'yt_dlp/extractor/deezer.py') diff --git a/yt_dlp/extractor/deezer.py b/yt_dlp/extractor/deezer.py new file mode 100644 index 0000000..f61f12a --- /dev/null +++ b/yt_dlp/extractor/deezer.py @@ -0,0 +1,142 @@ +import json + +from .common import InfoExtractor +from ..utils import ( + ExtractorError, + int_or_none, + orderedSet, +) + + +class DeezerBaseInfoExtractor(InfoExtractor): + def get_data(self, url): + if not self.get_param('test'): + self.report_warning('For now, this extractor only supports the 30 second previews. Patches welcome!') + + mobj = self._match_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[0-9]+)' + _TEST = { + 'url': 'http://www.deezer.com/playlist/176747451', + 'info_dict': { + 'id': '176747451', + 'title': 'Best!', + 'uploader': 'anonymous', + 'thumbnail': r're:^https?://(e-)?cdns-images\.dzcdn\.net/images/cover/.*\.jpg$', + }, + 'playlist_count': 29, + } + + def _real_extract(self, url): + playlist_id, webpage, data = self.get_data(url) + + playlist_title = data.get('DATA', {}).get('TITLE') + playlist_uploader = data.get('DATA', {}).get('PARENT_USERNAME') + playlist_thumbnail = self._search_regex( + r'[0-9]+)' + _TEST = { + 'url': 'https://www.deezer.com/fr/album/67505622', + 'info_dict': { + 'id': '67505622', + 'title': 'Last Week', + 'uploader': 'Home Brew', + 'thumbnail': r're:^https?://(e-)?cdns-images\.dzcdn\.net/images/cover/.*\.jpg$', + }, + 'playlist_count': 7, + } + + def _real_extract(self, url): + album_id, webpage, data = self.get_data(url) + + album_title = data.get('DATA', {}).get('ALB_TITLE') + album_uploader = data.get('DATA', {}).get('ART_NAME') + album_thumbnail = self._search_regex( + r'