Update deezer.py
This commit is contained in:
parent
d9fff7fc39
commit
c926483fc8
@ -10,9 +10,53 @@ from ..utils import (
|
|||||||
orderedSet,
|
orderedSet,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from hashlib import md5
|
||||||
|
from Crypto.Cipher import AES, Blowfish
|
||||||
|
from binascii import b2a_hex
|
||||||
|
|
||||||
|
############
|
||||||
|
|
||||||
|
def md5hex(data):
|
||||||
|
""" return hex string of md5 of the given string """
|
||||||
|
return md5(data).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
def hexaescrypt(data, key):
|
||||||
|
""" returns hex string of aes encrypted data """
|
||||||
|
c = AES.new(key, AES.MODE_ECB)
|
||||||
|
return b2a_hex(c.encrypt(data))
|
||||||
|
|
||||||
|
|
||||||
|
def calcurlkey(songid, md5origin, mediaver=4, fmt=1):
|
||||||
|
""" Calculate the deezer download url given the songid, origin and media+format """
|
||||||
|
data = b'\xa4'.join(_.encode("utf-8") for _ in [md5origin, str(fmt), str(songid), str(mediaver)])
|
||||||
|
data = b'\xa4'.join([md5hex(data), data])+b'\xa4'
|
||||||
|
if len(data)%16:
|
||||||
|
data += b'\x00' * (16-len(data)%16)
|
||||||
|
return hexaescrypt(data, "jo6aey6haid2Teih").decode('utf-8')
|
||||||
|
|
||||||
|
|
||||||
|
def calcblowfishkey(songid):
|
||||||
|
""" Calculate the Blowfish decrypt key for a given songid """
|
||||||
|
h = md5hex(b"%d" % songid)
|
||||||
|
key = b"g4el58wc0zvf9na1"
|
||||||
|
return "".join(chr(ord(h[i]) ^ ord(h[i+16]) ^ ord(key[i])) for i in range(16))
|
||||||
|
|
||||||
|
|
||||||
|
def getformat(song):
|
||||||
|
""" return format id for a song """
|
||||||
|
if song["FILESIZE_MP3_320"]:
|
||||||
|
return 3
|
||||||
|
if song["FILESIZE_MP3_256"]:
|
||||||
|
return 5
|
||||||
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
############
|
||||||
|
|
||||||
class DeezerPlaylistIE(InfoExtractor):
|
class DeezerPlaylistIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?deezer\.com/playlist/(?P<id>[0-9]+)'
|
_VALID_URL = r'https?://(?:www\.)?deezer\.com/\w+/(?P<id>[0-9]+)'
|
||||||
_TEST = {
|
_TEST = {
|
||||||
'url': 'http://www.deezer.com/playlist/176747451',
|
'url': 'http://www.deezer.com/playlist/176747451',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
@ -40,6 +84,11 @@ class DeezerPlaylistIE(InfoExtractor):
|
|||||||
raise ExtractorError(
|
raise ExtractorError(
|
||||||
'Deezer said: %s' % geoblocking_msg, expected=True)
|
'Deezer said: %s' % geoblocking_msg, expected=True)
|
||||||
|
|
||||||
|
host_stream_cdn = self._search_regex(
|
||||||
|
r'var HOST_STREAM_CDN = \'(.*?)\'', webpage, 'host stream cdn')
|
||||||
|
setting_domain_img = self._search_regex(
|
||||||
|
r'var SETTING_DOMAIN_IMG = \'(.*?)\'', webpage, 'setting domain img')
|
||||||
|
|
||||||
data_json = self._search_regex(
|
data_json = self._search_regex(
|
||||||
(r'__DZR_APP_STATE__\s*=\s*({.+?})\s*</script>',
|
(r'__DZR_APP_STATE__\s*=\s*({.+?})\s*</script>',
|
||||||
r'naboo\.display\(\'[^\']+\',\s*(.*?)\);\n'),
|
r'naboo\.display\(\'[^\']+\',\s*(.*?)\);\n'),
|
||||||
@ -47,6 +96,63 @@ class DeezerPlaylistIE(InfoExtractor):
|
|||||||
data = json.loads(data_json)
|
data = json.loads(data_json)
|
||||||
|
|
||||||
playlist_title = data.get('DATA', {}).get('TITLE')
|
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')
|
||||||
|
|
||||||
|
preview_pattern = self._search_regex(
|
||||||
|
r"var SOUND_PREVIEW_GATEWAY\s*=\s*'([^']+)';", webpage,
|
||||||
|
'preview URL pattern', fatal=False)
|
||||||
|
entries = []
|
||||||
|
|
||||||
|
if 'SONGS' in data:
|
||||||
|
# playlist, album
|
||||||
|
songlist = data['SONGS']['data']
|
||||||
|
elif 'MD5_ORIGIN' in data['DATA']:
|
||||||
|
# track
|
||||||
|
songlist = [ data['DATA'] ]
|
||||||
|
elif "ALBUMS" in data:
|
||||||
|
songlist = []
|
||||||
|
for album in data["ALBUMS"]["data"]:
|
||||||
|
songlist.extend(album['SONGS']['data'])
|
||||||
|
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 = [{
|
||||||
|
'format_id': 'preview',
|
||||||
|
'key': calcblowfishkey(int(s["SNG_ID"])),
|
||||||
|
'url': url,
|
||||||
|
'preference': -100, # Only the first 30 seconds
|
||||||
|
'ext': 'mp3',
|
||||||
|
'protocol': 'deezer',
|
||||||
|
}]
|
||||||
|
self._sort_formats(formats)
|
||||||
|
artists = ', '.join(
|
||||||
|
orderedSet(a['ART_NAME'] for a in s['ARTISTS']))
|
||||||
|
entries.append({
|
||||||
|
'id': s['SNG_ID'],
|
||||||
|
'duration': int_or_none(s.get('DURATION')),
|
||||||
|
'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,
|
||||||
|
'formats': formats,
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
'_type': 'playlist',
|
||||||
|
'id': playlist_id,
|
||||||
|
'title': playlist_title,
|
||||||
|
'uploader': playlist_uploader,
|
||||||
|
#'thumbnail': playlist_thumbnail,
|
||||||
|
'entries': entries,
|
||||||
|
}
|
||||||
|
|
||||||
playlist_uploader = data.get('DATA', {}).get('PARENT_USERNAME')
|
playlist_uploader = data.get('DATA', {}).get('PARENT_USERNAME')
|
||||||
playlist_thumbnail = self._search_regex(
|
playlist_thumbnail = self._search_regex(
|
||||||
r'<img id="naboo_playlist_image".*?src="([^"]+)"', webpage,
|
r'<img id="naboo_playlist_image".*?src="([^"]+)"', webpage,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user