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 f
'Deezer said: {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
66 orderedSet(a.get('ART_NAME') for a in s.get('ARTISTS')))
68 'id': s.get('SNG_ID'),
69 'duration': int_or_none(s.get('DURATION')),
70 'title': '{} - {}'.format(artists, s.get('SNG_TITLE')),
71 'uploader': s.get('ART_NAME'),
72 'uploader_id': s.get('ART_ID'),
73 'age_limit': 16 if s.get('EXPLICIT_LYRICS') == '1' else 0,
80 'title': playlist_title,
81 'uploader': playlist_uploader,
82 'thumbnail': playlist_thumbnail,
87 class DeezerAlbumIE(DeezerBaseInfoExtractor):
88 _VALID_URL = r'https?://(?:www\.)?deezer\.com/(../)?album/(?P<id>[0-9]+)'
90 'url': 'https://www.deezer.com/fr/album/67505622',
94 'uploader': 'Home Brew',
95 'thumbnail': r're:^https?://(e-)?cdns-images\.dzcdn\.net/images/cover/.*\.jpg$',
100 def _real_extract(self, url):
101 album_id, webpage, data = self.get_data(url)
103 album_title = data.get('DATA', {}).get('ALB_TITLE')
104 album_uploader = data.get('DATA', {}).get('ART_NAME')
105 album_thumbnail = self._search_regex(
106 r'<img id="naboo_album_image
".*?src="([^
"]+)"', webpage,
110 for s in data.get('SONGS
', {}).get('data
'):
112 'format_id
': 'preview
',
113 'url
': s.get('MEDIA
', [{}])[0].get('HREF
'),
114 'preference
': -100, # Only the first 30 seconds
118 orderedSet(a.get('ART_NAME
') for a in s.get('ARTISTS
')))
120 'id': s.get('SNG_ID
'),
121 'duration
': int_or_none(s.get('DURATION
')),
122 'title
': '{} - {}'.format(artists, s.get('SNG_TITLE
')),
123 'uploader
': s.get('ART_NAME
'),
124 'uploader_id
': s.get('ART_ID
'),
125 'age_limit
': 16 if s.get('EXPLICIT_LYRICS
') == '1' else 0,
127 'track
': s.get('SNG_TITLE
'),
128 'track_number
': int_or_none(s.get('TRACK_NUMBER
')),
129 'track_id
': s.get('SNG_ID
'),
130 'artist
': album_uploader,
131 'album
': album_title,
132 'album_artist
': album_uploader,
138 'title
': album_title,
139 'uploader
': album_uploader,
140 'thumbnail
': album_thumbnail,