deemix-js/deemix/utils/deezer.js

54 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-05-16 19:40:14 +00:00
const got = require('got')
const {CookieJar} = require('tough-cookie')
const {_md5} = require('./crypto.js')
const { USER_AGENT_HEADER } = require('./index.js')
2021-05-24 22:02:12 +00:00
const CLIENT_ID = "172365"
const CLIENT_SECRET = "fb0bec7ccc063dab0417eb7b0d847f34"
2021-05-16 19:40:14 +00:00
async function getAccessToken(email, password){
2021-12-22 10:35:09 +00:00
let accessToken = null
2021-05-16 19:40:14 +00:00
password = _md5(password, 'utf8')
2021-05-24 22:02:12 +00:00
const hash = _md5([CLIENT_ID, email, password, CLIENT_SECRET].join(''), 'utf8')
2021-12-22 10:35:09 +00:00
try {
let response = await got.get("https://api.deezer.com/auth/token",{
searchParams: {
app_id: CLIENT_ID,
login: email,
password: password,
hash
},
https: {rejectUnauthorized: false},
headers: {"User-Agent": USER_AGENT_HEADER}
}).json()
accessToken = response.access_token
if (accessToken == "undefined") accessToken = null
} catch { /*empty*/ }
return accessToken
2021-05-16 19:40:14 +00:00
}
async function getArlFromAccessToken(accessToken){
2021-12-22 10:35:09 +00:00
if (!accessToken) return null
let arl = null
2021-05-16 19:40:14 +00:00
let cookieJar = new CookieJar()
2021-12-22 10:35:09 +00:00
try {
await got.get("https://api.deezer.com/platform/generic/track/3135556", {
headers: {"Authorization": `Bearer ${accessToken}`, "User-Agent": USER_AGENT_HEADER},
https: {rejectUnauthorized: false},
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},
https: {rejectUnauthorized: false},
cookieJar
}).json()
arl = response.results
} catch { /*empty*/ }
return arl
2021-05-16 19:40:14 +00:00
}
module.exports = {
getAccessToken,
getArlFromAccessToken
}