1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
13 class DeezerPlaylistIE(InfoExtractor
):
14 _VALID_URL
= r
'https?://(?:www\.)?deezer\.com/playlist/(?P<id>[0-9]+)'
16 'url': 'http://www.deezer.com/playlist/176747451',
20 'uploader': 'Anonymous',
21 'thumbnail': 're:^https?://cdn-images.deezer.com/images/cover/.*\.jpg$',
26 def _real_extract(self
, url
):
27 if 'test' not in self
._downloader
.params
:
28 self
._downloader
.report_warning('For now, this extractor only supports the 30 second previews. Patches welcome!')
30 mobj
= re
.match(self
._VALID
_URL
, url
)
31 playlist_id
= mobj
.group('id')
33 webpage
= self
._download
_webpage
(url
, playlist_id
)
34 data_json
= self
._search
_regex
(
35 r
'naboo\.display\(\'[^
\']+\',\s
*(.*?
)\
);\n', webpage, 'data JSON
')
36 data = json.loads(data_json)
38 playlist_title = data.get('DATA
', {}).get('TITLE
')
39 playlist_uploader = data.get('DATA
', {}).get('PARENT_USERNAME
')
40 playlist_thumbnail = self._search_regex(
41 r'<img
id="naboo_playlist_image".*?src
="([^"]+)"', webpage,
44 preview_pattern = self._search_regex(
45 r"var SOUND_PREVIEW_GATEWAY\s
*=\s
*'([^']+)';", webpage,
46 'preview URL pattern
', fatal=False)
48 for s in data['SONGS
']['data
']:
49 puid = s['MD5_ORIGIN
']
50 preview_video_url = preview_pattern.\
51 replace('{0}
', puid[0]).\
52 replace('{1}
', puid).\
53 replace('{2}
', s['MEDIA_VERSION
'])
55 'format_id
': 'preview
',
56 'url
': preview_video_url,
57 'preference
': -100, # Only the first 30 seconds
60 self._sort_formats(formats)
62 orderedSet(a['ART_NAME
'] for a in s['ARTISTS
']))
65 'duration
': int_or_none(s.get('DURATION
')),
66 'title
': '%s - %s' % (artists, s['SNG_TITLE
']),
67 'uploader
': s['ART_NAME
'],
68 'uploader_id
': s['ART_ID
'],
69 'age_limit
': 16 if s.get('EXPLICIT_LYRICS
') == '1' else 0,
76 'title
': playlist_title,
77 'uploader
': playlist_uploader,
78 'thumbnail
': playlist_thumbnail,