Specify format in get_track_url

This commit is contained in:
RemixDev 2021-07-25 13:06:06 +02:00
parent 20ca19516a
commit 554670d51a
2 changed files with 25 additions and 25 deletions

View file

@ -132,34 +132,34 @@ class Deezer{
return [this.current_user, this.selected_account] return [this.current_user, this.selected_account]
} }
async get_tracks_urls(track_tokens){ async get_track_url(track_token, format) {
return this.get_tracks_url([track_token, ], format)
}
async get_tracks_url(track_tokens, format){
if (!Array.isArray(track_tokens)) track_tokens = [track_tokens, ] if (!Array.isArray(track_tokens)) track_tokens = [track_tokens, ]
if (!this.current_user.license_token) return [] if (!this.current_user.license_token) return []
let response = await got.post("https://media.deezer.com/v1/get_url", { let response
try {
response = await got.post("https://media.deezer.com/v1/get_url", {
headers: this.http_headers, headers: this.http_headers,
cookieJar: this.cookie_jar, cookieJar: this.cookie_jar,
json: { json: {
license_token: this.current_user.license_token, license_token: this.current_user.license_token,
media: [{ media: [{
type: "FULL", type: "FULL",
formats: [ formats: [{ cipher: "BF_CBC_STRIPE", format: format }]
{ cipher: "BF_CBC_STRIPE", format: "FLAC" },
{ cipher: "BF_CBC_STRIPE", format: "MP3_320" },
{ cipher: "BF_CBC_STRIPE", format: "MP3_256" },
{ cipher: "BF_CBC_STRIPE", format: "MP3_128" },
{ cipher: "BF_CBC_STRIPE", format: "MP3_64" },
{ cipher: "BF_CBC_STRIPE", format: "MP3_MISC" },
{ cipher: "BF_CBC_STRIPE", format: "MP4_RA3" },
{ cipher: "BF_CBC_STRIPE", format: "MP4_RA2" },
{ cipher: "BF_CBC_STRIPE", format: "MP4_RA1" }
]
}], }],
track_tokens track_tokens
} }
}).json() }).json()
} catch (e){
return null
}
return response.data return response.data[0].media[0].sources[0].url
} }
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "deezer-js", "name": "deezer-js",
"version": "1.0.1", "version": "1.0.2",
"description": "A wrapper for all Deezer's APIs", "description": "A wrapper for all Deezer's APIs",
"main": "deezer/index.js", "main": "deezer/index.js",
"scripts": { "scripts": {