mirror of
https://gitlab.com/RemixDev/deemix-js.git
synced 2025-01-29 17:18:27 +00:00
Added deezer utils
This commit is contained in:
parent
648ad93a94
commit
919380a4e8
|
@ -1,24 +1,8 @@
|
|||
const crypto = require('crypto')
|
||||
const got = require('got')
|
||||
const {_md5, _ecbCrypt, _ecbDecrypt} = require('./utils/crypto.js')
|
||||
|
||||
const { USER_AGENT_HEADER, pipeline } = require('./utils/index.js')
|
||||
|
||||
function _md5 (data, type = 'binary') {
|
||||
let md5sum = crypto.createHash('md5')
|
||||
md5sum.update(Buffer.from(data, type))
|
||||
return md5sum.digest('hex')
|
||||
}
|
||||
|
||||
function _ecbCrypt (key, data) {
|
||||
let cipher = crypto.createCipheriv("aes-128-ecb", Buffer.from(key), Buffer.from(""));
|
||||
return Buffer.concat([cipher.update(data, 'binary'), cipher.final()]).toString("hex").toLowerCase();
|
||||
}
|
||||
|
||||
function _ecbDecrypt (key, data) {
|
||||
let cipher = crypto.createDecipheriv("aes-128-ecb", Buffer.from(key), Buffer.from(""));
|
||||
return Buffer.concat([cipher.update(data, 'binary'), cipher.final()]).toString("hex").toLowerCase();
|
||||
}
|
||||
|
||||
function generateStreamPath(sngID, md5, mediaVersion, format){
|
||||
let urlPart = md5+"¤"+format+"¤"+sngID+"¤"+mediaVersion
|
||||
let md5val = _md5(urlPart)
|
||||
|
@ -118,26 +102,10 @@ class DownloadCanceled extends Error {
|
|||
}
|
||||
|
||||
/*
|
||||
function generateBlowfishKey(trackId) {
|
||||
const SECRET = 'g4el58wc0zvf9na1';
|
||||
const idMd5 = _md5(trackId.toString(), 'ascii')
|
||||
let bfKey = ''
|
||||
for (let i = 0; i < 16; i++) {
|
||||
bfKey += String.fromCharCode(idMd5.charCodeAt(i) ^ idMd5.charCodeAt(i + 16) ^ SECRET.charCodeAt(i))
|
||||
}
|
||||
return bfKey;
|
||||
}
|
||||
|
||||
function generateCryptedStreamURL(sngID, md5, mediaVersion, format){
|
||||
let urlPart = generateStreamPath(sngID, md5, mediaVersion, format)
|
||||
return "https://e-cdns-proxy-" + md5[0] + ".dzcdn.net/mobile/1/" + urlPart
|
||||
}
|
||||
|
||||
function decryptChunk(chunk, blowFishKey){
|
||||
var cipher = crypto.createDecipheriv('bf-cbc', blowFishKey, Buffer.from([0, 1, 2, 3, 4, 5, 6, 7]))
|
||||
cipher.setAutoPadding(false)
|
||||
return cipher.update(chunk, 'binary', 'binary') + cipher.final()
|
||||
}
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -97,6 +97,7 @@ module.exports = {
|
|||
utils: {
|
||||
...require('./utils/index.js'),
|
||||
localpaths: require('./utils/localpaths.js'),
|
||||
pathtemplates: require('./utils/pathtemplates.js')
|
||||
pathtemplates: require('./utils/pathtemplates.js'),
|
||||
deezer: require('./utils/deezer.js')
|
||||
}
|
||||
}
|
||||
|
|
41
deemix/utils/crypto.js
Normal file
41
deemix/utils/crypto.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
const crypto = require('crypto')
|
||||
|
||||
function _md5 (data, type = 'binary') {
|
||||
let md5sum = crypto.createHash('md5')
|
||||
md5sum.update(Buffer.from(data, type))
|
||||
return md5sum.digest('hex')
|
||||
}
|
||||
|
||||
function _ecbCrypt (key, data) {
|
||||
let cipher = crypto.createCipheriv("aes-128-ecb", Buffer.from(key), Buffer.from(""));
|
||||
return Buffer.concat([cipher.update(data, 'binary'), cipher.final()]).toString("hex").toLowerCase();
|
||||
}
|
||||
|
||||
function _ecbDecrypt (key, data) {
|
||||
let cipher = crypto.createDecipheriv("aes-128-ecb", Buffer.from(key), Buffer.from(""));
|
||||
return Buffer.concat([cipher.update(data, 'binary'), cipher.final()]).toString("hex").toLowerCase();
|
||||
}
|
||||
|
||||
/*
|
||||
function generateBlowfishKey(trackId) {
|
||||
const SECRET = 'g4el58wc0zvf9na1';
|
||||
const idMd5 = _md5(trackId.toString(), 'ascii')
|
||||
let bfKey = ''
|
||||
for (let i = 0; i < 16; i++) {
|
||||
bfKey += String.fromCharCode(idMd5.charCodeAt(i) ^ idMd5.charCodeAt(i + 16) ^ SECRET.charCodeAt(i))
|
||||
}
|
||||
return bfKey;
|
||||
}
|
||||
|
||||
function decryptChunk(chunk, blowFishKey){
|
||||
var cipher = crypto.createDecipheriv('bf-cbc', blowFishKey, Buffer.from([0, 1, 2, 3, 4, 5, 6, 7]))
|
||||
cipher.setAutoPadding(false)
|
||||
return cipher.update(chunk, 'binary', 'binary') + cipher.final()
|
||||
}
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
_md5,
|
||||
_ecbCrypt,
|
||||
_ecbDecrypt
|
||||
}
|
31
deemix/utils/deezer.js
Normal file
31
deemix/utils/deezer.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
const got = require('got')
|
||||
const {CookieJar} = require('tough-cookie')
|
||||
const {_md5} = require('./crypto.js')
|
||||
const { USER_AGENT_HEADER } = require('./index.js')
|
||||
|
||||
async function getAccessToken(email, password){
|
||||
password = _md5(password, 'utf8')
|
||||
let response = await got.get(`https://tv.deezer.com/smarttv/8caf9315c1740316053348a24d25afc7/user_auth.php?login=${email}&password=${password}&device=panasonic&output=jsonp`,{
|
||||
headers: {"User-Agent": USER_AGENT_HEADER}
|
||||
}).json()
|
||||
console.log(response)
|
||||
return response.access_token
|
||||
}
|
||||
|
||||
async function getArlFromAccessToken(accessToken){
|
||||
let cookieJar = new CookieJar()
|
||||
await got.get("https://api.deezer.com/platform/generic/track/3135556", {
|
||||
headers: {"Authorization": `Bearer ${accessToken}`, "User-Agent": USER_AGENT_HEADER},
|
||||
cookieJar
|
||||
})
|
||||
let response = await got.get('https://www.deezer.com/ajax/gw-light.php?method=user.getArl&input=3&api_version=1.0&api_token=null', {
|
||||
headers: {"User-Agent": USER_AGENT_HEADER},
|
||||
cookieJar
|
||||
}).json()
|
||||
return response.results
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getAccessToken,
|
||||
getArlFromAccessToken
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "deemix",
|
||||
"version": "0.0.4",
|
||||
"version": "0.0.5",
|
||||
"description": "a barebones deezer downloader library",
|
||||
"main": "deemix/index.js",
|
||||
"scripts": {
|
||||
|
|
Loading…
Reference in a new issue