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': '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
'naboo\.display\(\'[^
\']+\',\s
*(.*?
)\
);\n', webpage, 'data JSON
') 
  45         data = json.loads(data_json) 
  47         playlist_title = data.get('DATA
', {}).get('TITLE
') 
  48         playlist_uploader = data.get('DATA
', {}).get('PARENT_USERNAME
') 
  49         playlist_thumbnail = self._search_regex( 
  50             r'<img 
id="naboo_playlist_image".*?src
="([^"]+)"', webpage, 
  53         preview_pattern = self._search_regex( 
  54             r"var SOUND_PREVIEW_GATEWAY\s
*=\s
*'([^']+)';", webpage, 
  55             'preview URL pattern
', fatal=False) 
  57         for s in data['SONGS
']['data
']: 
  58             puid = s['MD5_ORIGIN
'] 
  59             preview_video_url = preview_pattern.\ 
  60                 replace('{0}
', puid[0]).\ 
  61                 replace('{1}
', puid).\ 
  62                 replace('{2}
', s['MEDIA_VERSION
']) 
  64                 'format_id
': 'preview
', 
  65                 'url
': preview_video_url, 
  66                 'preference
': -100,  # Only the first 30 seconds 
  69             self._sort_formats(formats) 
  71                 orderedSet(a['ART_NAME
'] for a in s['ARTISTS
'])) 
  74                 'duration
': int_or_none(s.get('DURATION
')), 
  75                 'title
': '%s - %s' % (artists, s['SNG_TITLE
']), 
  76                 'uploader
': s['ART_NAME
'], 
  77                 'uploader_id
': s['ART_ID
'], 
  78                 'age_limit
': 16 if s.get('EXPLICIT_LYRICS
') == '1' else 0, 
  85             'title
': playlist_title, 
  86             'uploader
': playlist_uploader, 
  87             'thumbnail
': playlist_thumbnail,