]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/deezer.py
3 from .common
import InfoExtractor
11 class DeezerBaseInfoExtractor(InfoExtractor
):
12 def get_data(self
, url
):
13 if not self
.get_param('test'):
14 self
.report_warning('For now, this extractor only supports the 30 second previews. Patches welcome!')
16 mobj
= self
._match
_valid
_url
(url
)
17 data_id
= mobj
.group('id')
19 webpage
= self
._download
_webpage
(url
, data_id
)
20 geoblocking_msg
= self
._html
_search
_regex
(
21 r
'<p class="soon-txt">(.*?)</p>', webpage
, 'geoblocking message',
23 if geoblocking_msg
is not None:
25 'Deezer said: %s' % geoblocking_msg
, expected
=True)
27 data_json
= self
._search
_regex
(
28 (r
'__DZR_APP_STATE__\s*=\s*({.+?})\s*</script>',
29 r
'naboo\.display\(\'[^
\']+\',\s
*(.*?
)\
);\n'),
31 data = json.loads(data_json)
32 return data_id, webpage, data
35 class DeezerPlaylistIE(DeezerBaseInfoExtractor):
36 _VALID_URL = r'https?
://(?
:www\
.)?deezer\
.com
/(../)?playlist
/(?P
<id>[0-9]+)'
38 'url
': 'http
://www
.deezer
.com
/playlist
/176747451',
42 'uploader
': 'anonymous
',
43 'thumbnail
': r're
:^https?
://(e
-)?cdns
-images\
.dzcdn\
.net
/images
/cover
/.*\
.jpg$
',
48 def _real_extract(self, url):
49 playlist_id, webpage, data = self.get_data(url)
51 playlist_title = data.get('DATA
', {}).get('TITLE
')
52 playlist_uploader = data.get('DATA
', {}).get('PARENT_USERNAME
')
53 playlist_thumbnail = self._search_regex(
54 r'<img
id="naboo_playlist_image".*?src
="([^"]+)"', webpage,
58 for s in data.get('SONGS', {}).get('data'):
60 'format_id': 'preview',
61 'url': s.get('MEDIA', [{}])[0].get('HREF'),
62 'preference': -100, # Only the first 30 seconds
65 self._sort_formats(formats)
67 orderedSet(a.get('ART_NAME') for a in s.get('ARTISTS')))
69 'id': s.get('SNG_ID'),
70 'duration': int_or_none(s.get('DURATION')),
71 'title': '%s - %s' % (artists, s.get('SNG_TITLE')),
72 'uploader': s.get('ART_NAME'),
73 'uploader_id': s.get('ART_ID'),
74 'age_limit': 16 if s.get('EXPLICIT_LYRICS') == '1' else 0,
81 'title': playlist_title,
82 'uploader': playlist_uploader,
83 'thumbnail': playlist_thumbnail,
88 class DeezerAlbumIE(DeezerBaseInfoExtractor):
89 _VALID_URL = r'https?://(?:www\.)?deezer\.com/(../)?album/(?P<id>[0-9]+)'
91 'url': 'https://www.deezer.com/fr/album/67505622',
95 'uploader': 'Home Brew',
96 'thumbnail': r're:^https?://(e-)?cdns-images\.dzcdn\.net/images/cover/.*\.jpg$',
101 def _real_extract(self, url):
102 album_id, webpage, data = self.get_data(url)
104 album_title = data.get('DATA', {}).get('ALB_TITLE')
105 album_uploader = data.get('DATA', {}).get('ART_NAME')
106 album_thumbnail = self._search_regex(
107 r'<img id="naboo_album_image
".*?src="([^
"]+)"', webpage,
111 for s in data.get('SONGS
', {}).get('data
'):
113 'format_id
': 'preview
',
114 'url
': s.get('MEDIA
', [{}])[0].get('HREF
'),
115 'preference
': -100, # Only the first 30 seconds
118 self._sort_formats(formats)
120 orderedSet(a.get('ART_NAME
') for a in s.get('ARTISTS
')))
122 'id': s.get('SNG_ID
'),
123 'duration
': int_or_none(s.get('DURATION
')),
124 'title
': '%s - %s' % (artists, s.get('SNG_TITLE
')),
125 'uploader
': s.get('ART_NAME
'),
126 'uploader_id
': s.get('ART_ID
'),
127 'age_limit
': 16 if s.get('EXPLICIT_LYRICS
') == '1' else 0,
129 'track
': s.get('SNG_TITLE
'),
130 'track_number
': int_or_none(s.get('TRACK_NUMBER
')),
131 'track_id
': s.get('SNG_ID
'),
132 'artist
': album_uploader,
133 'album
': album_title,
134 'album_artist
': album_uploader,
140 'title
': album_title,
141 'uploader
': album_uploader,
142 'thumbnail
': album_thumbnail,