improved thumbs, formats, test result.
* now returns all formats. * added support for all types of thumbnails. * downloadtest will now succeed. * updated geolocking check * removed 30 second preview notice.
This commit is contained in:
parent
e6414d00fc
commit
e3f0c6a2d9
@ -50,34 +50,78 @@ def getformat(song):
|
||||
return 1
|
||||
|
||||
|
||||
class Format:
|
||||
def __init__(self, name, fmtid, ext, bitrate):
|
||||
self.name = name
|
||||
self.formatid = fmtid
|
||||
self.extension = ext
|
||||
self.bitrate = bitrate
|
||||
|
||||
|
||||
_formatinfo = {
|
||||
'MP3_MISC': Format('MP3_MISC', 0, 'mp3', 128),
|
||||
'MP3_128': Format('MP3_128', 1, 'mp3', 128),
|
||||
# 2 used to be MP3_192
|
||||
'MP3_320': Format('MP3_320', 3, 'mp3', 320),
|
||||
# 4 used to be AAC_96
|
||||
'MP3_256': Format('MP3_256', 5, 'mp3', 256),
|
||||
'AAC_64': Format('AAC_64', 6, 'aac', 64), # used to be AAC_192
|
||||
'MP3_192': Format('MP3_192', 7, 'mp3', 192),
|
||||
'AAC_96': Format('AAC_96', 8, 'aac', 96),
|
||||
'FLAC': Format('FLAC', 9, 'flac', 0),
|
||||
'MP3_64': Format('MP3_64', 10, 'mp3', 64),
|
||||
'MP3_32': Format('MP3_32', 11, 'mp3', 32),
|
||||
}
|
||||
|
||||
|
||||
def convert_to_int(x):
|
||||
try:
|
||||
return int(x)
|
||||
except:
|
||||
return 0
|
||||
|
||||
|
||||
def songformats(s):
|
||||
"""
|
||||
Enumerate all formats for a song
|
||||
"""
|
||||
for k, v in s.items():
|
||||
if k.startswith("FILESIZE_") and convert_to_int(v):
|
||||
name = k[9:]
|
||||
if name in _formatinfo:
|
||||
yield _formatinfo[name]
|
||||
|
||||
|
||||
class DeezerPlaylistIE(InfoExtractor):
|
||||
_VALID_URL = r'https?://(?:www\.)?deezer\.com/\w+/(?P<id>[0-9]+)'
|
||||
_VALID_URL = r'https?://(?:www\.)?deezer\.com/(?P<type>\w+)/(?P<id>[0-9]+)'
|
||||
_TEST = {
|
||||
'url': 'http://www.deezer.com/playlist/176747451',
|
||||
'info_dict': {
|
||||
'id': '176747451',
|
||||
'title': 'Best!',
|
||||
'uploader': 'Anonymous',
|
||||
'thumbnail': r're:^https?://cdn-images.deezer.com/images/cover/.*\.jpg$',
|
||||
'uploader': 'anonymous',
|
||||
'thumbnail': r're:^https?://\S*cdn-images.deezer.com/images/playlist/.*\.jpg$',
|
||||
},
|
||||
'playlist_count': 30,
|
||||
'skip': 'Only available in .de',
|
||||
}
|
||||
|
||||
def _real_extract(self, url):
|
||||
mobj = re.match(self._VALID_URL, url)
|
||||
playlist_id = mobj.group('id')
|
||||
list_id = mobj.group('id')
|
||||
list_type = mobj.group('type')
|
||||
|
||||
webpage = self._download_webpage(url, playlist_id)
|
||||
webpage = self._download_webpage(url, list_id)
|
||||
geoblocking_msg = self._html_search_regex(
|
||||
r'<p class="soon-txt">(.*?)</p>', webpage, 'geoblocking message',
|
||||
r'<div class="page-soon.*<h2>(.*?)</h2>', webpage, 'geoblocking message',
|
||||
default=None)
|
||||
if geoblocking_msg is not None:
|
||||
raise ExtractorError(
|
||||
'Deezer said: %s' % geoblocking_msg, expected=True)
|
||||
|
||||
host_stream_cdn = self._search_regex(
|
||||
r'var HOST_STREAM_CDN = \'(.*?)\'', webpage, 'host stream cdn')
|
||||
r'var\s+HOST_STREAM_CDN\s*=\s*[\'"](.*?)[\'"]', webpage, 'host stream cdn')
|
||||
setting_domain_img = self._search_regex(
|
||||
r'var\s+SETTING_DOMAIN_IMG\s*=\s*[\'"](.*?)[\'"]', webpage, 'setting domain img')
|
||||
|
||||
data_json = self._search_regex(
|
||||
(r'__DZR_APP_STATE__\s*=\s*({.+?})\s*</script>',
|
||||
@ -85,39 +129,48 @@ class DeezerPlaylistIE(InfoExtractor):
|
||||
webpage, 'data JSON')
|
||||
data = json.loads(data_json)
|
||||
|
||||
playlist_title = data.get('DATA', {}).get('TITLE')
|
||||
playlist_uploader = data.get('DATA', {}).get('PARENT_USERNAME')
|
||||
# playlist_thumbnail = self._search_regex( r'<img id="naboo_playlist_image".*?src="([^"]+)"', webpage, 'playlist thumbnail')
|
||||
list_title = data.get('DATA', {}).get('TITLE')
|
||||
list_uploader = data.get('DATA', {}).get('PARENT_USERNAME')
|
||||
list_thumbnail = setting_domain_img + ("/playlist/" if list_type == 'playlist' else "/cover/")
|
||||
|
||||
entries = []
|
||||
|
||||
if 'SONGS' in data:
|
||||
# playlist, album
|
||||
songlist = data['SONGS']['data']
|
||||
if list_type == 'playlist':
|
||||
listimgid = data['DATA']['PLAYLIST_PICTURE']
|
||||
else:
|
||||
listimgid = data['DATA']['ALB_PICTURE']
|
||||
elif 'MD5_ORIGIN' in data['DATA']:
|
||||
# track
|
||||
songlist = [data['DATA']]
|
||||
listimgid = data['DATA']['ALB_PICTURE']
|
||||
elif "ALBUMS" in data:
|
||||
# artist
|
||||
songlist = []
|
||||
for album in data["ALBUMS"]["data"]:
|
||||
songlist.extend(album['SONGS']['data'])
|
||||
listimgid = data['DATA']['ART_PICTURE']
|
||||
else:
|
||||
raise ExtractorError('Could not find songs')
|
||||
|
||||
# album, playlist
|
||||
for s in songlist:
|
||||
|
||||
urlkey = calcurlkey(int(s["SNG_ID"]), str(s["MD5_ORIGIN"]), int(s["MEDIA_VERSION"]), getformat(s))
|
||||
url = host_stream_cdn.replace('{0}', str(s["MD5_ORIGIN"])[0]) + "/" + urlkey
|
||||
formats = []
|
||||
for fmt in songformats(s):
|
||||
urlkey = calcurlkey(int(s["SNG_ID"]), str(s["MD5_ORIGIN"]), int(s["MEDIA_VERSION"]), fmt.formatid)
|
||||
url = host_stream_cdn.replace('{0}', str(s["MD5_ORIGIN"])[0]) + "/" + urlkey
|
||||
|
||||
formats = [{
|
||||
'format_id': 'preview',
|
||||
'key': calcblowfishkey(int(s["SNG_ID"])),
|
||||
'url': url,
|
||||
'preference': -100, # Only the first 30 seconds
|
||||
'ext': 'mp3',
|
||||
'protocol': 'deezer',
|
||||
}]
|
||||
formats.append({
|
||||
'format_id': fmt.name,
|
||||
'key': calcblowfishkey(int(s["SNG_ID"])),
|
||||
'url': url,
|
||||
'preference': fmt.bitrate,
|
||||
'ext': fmt.extension,
|
||||
'protocol': 'deezer',
|
||||
'vcodec': 'none',
|
||||
})
|
||||
self._sort_formats(formats)
|
||||
artists = ', '.join(
|
||||
orderedSet(a['ART_NAME'] for a in s['ARTISTS']))
|
||||
@ -127,15 +180,16 @@ class DeezerPlaylistIE(InfoExtractor):
|
||||
'title': '%s - %s' % (artists, s['SNG_TITLE']),
|
||||
'uploader': s['ART_NAME'],
|
||||
'uploader_id': s['ART_ID'],
|
||||
'age_limit': 16 if s.get('EXPLICIT_LYRICS') == '1' else 0,
|
||||
'age_limit': 16 if convert_to_int(s.get('EXPLICIT_LYRICS')) else 0,
|
||||
'formats': formats,
|
||||
'thumbnail': setting_domain_img + '/cover/' + s['ALB_PICTURE'] + '/200x200.jpg'
|
||||
})
|
||||
|
||||
return {
|
||||
'_type': 'playlist',
|
||||
'id': playlist_id,
|
||||
'title': playlist_title,
|
||||
'uploader': playlist_uploader,
|
||||
# 'thumbnail': playlist_thumbnail,
|
||||
'id': list_id,
|
||||
'title': list_title,
|
||||
'uploader': list_uploader,
|
||||
'thumbnail': list_thumbnail + listimgid + '/200x200.jpg',
|
||||
'entries': entries,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user