1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
14 class DeezerPlaylistIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://(?:www\.)?deezer\.com/playlist/(?P<id>[0-9]+)'
17 'url': 'http://www.deezer.com/playlist/176747451',
21 'uploader': 'Anonymous',
22 'thumbnail': r
're:^https?://cdn-images.deezer.com/images/cover/.*\.jpg$',
25 'skip': 'Only available in .de',
28 def _real_extract(self
, url
):
29 if 'test' not in self
._downloader
.params
:
30 self
._downloader
.report_warning('For now, this extractor only supports the 30 second previews. Patches welcome!')
32 mobj
= re
.match(self
._VALID
_URL
, url
)
33 playlist_id
= mobj
.group('id')
35 webpage
= self
._download
_webpage
(url
, playlist_id
)
36 geoblocking_msg
= self
._html
_search
_regex
(
37 r
'<p class="soon-txt">(.*?)</p>', webpage
, 'geoblocking message',
39 if geoblocking_msg
is not None:
41 'Deezer said: %s' % geoblocking_msg
, expected
=True)
43 data_json
= self
._search
_regex
(
44 (r
'__DZR_APP_STATE__\s*=\s*({.+?})\s*</script>',
45 r
'naboo\.display\(\'[^
\']+\',\s
*(.*?
)\
);\n'),
47 data = json.loads(data_json)
49 playlist_title = data.get('DATA
', {}).get('TITLE
')
50 playlist_uploader = data.get('DATA
', {}).get('PARENT_USERNAME
')
51 playlist_thumbnail = self._search_regex(
52 r'<img
id="naboo_playlist_image".*?src
="([^"]+)"', webpage,
55 preview_pattern = self._search_regex(
56 r"var SOUND_PREVIEW_GATEWAY\s
*=\s
*'([^']+)';", webpage,
57 'preview URL pattern
', fatal=False)
59 for s in data['SONGS
']['data
']:
60 puid = s['MD5_ORIGIN
']
61 preview_video_url = preview_pattern.\
62 replace('{0}
', puid[0]).\
63 replace('{1}
', puid).\
64 replace('{2}
', s['MEDIA_VERSION
'])
66 'format_id
': 'preview
',
67 'url
': preview_video_url,
68 'preference
': -100, # Only the first 30 seconds
71 self._sort_formats(formats)
73 orderedSet(a['ART_NAME
'] for a in s['ARTISTS
']))
76 'duration
': int_or_none(s.get('DURATION
')),
77 'title
': '%s - %s' % (artists, s['SNG_TITLE
']),
78 'uploader
': s['ART_NAME
'],
79 'uploader_id
': s['ART_ID
'],
80 'age_limit
': 16 if s.get('EXPLICIT_LYRICS
') == '1' else 0,
87 'title
': playlist_title,
88 'uploader
': playlist_uploader,
89 'thumbnail
': playlist_thumbnail,