mirror of
https://codeberg.org/lucida/lucida.git
synced 2026-11-20 02:27:27 -05:00
add the arl login work
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "lucida",
|
"name": "lucida",
|
||||||
"version": "2.0.0-17",
|
"version": "2.0.0-18",
|
||||||
"description": "A modular music downloader tool",
|
"description": "A modular music downloader tool",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -30,11 +30,11 @@ class Lucida {
|
|||||||
}
|
}
|
||||||
async login() {
|
async login() {
|
||||||
if (!this.logins) throw new Error('No logins specified')
|
if (!this.logins) throw new Error('No logins specified')
|
||||||
for (const i in this.logins) {
|
for (const i in this.modules) {
|
||||||
const credentials = this.logins[i]
|
const credentials = this.logins[i]
|
||||||
const module = this.modules[i]
|
const module = this.modules[i]
|
||||||
if (module && 'login' in module) {
|
if (module && 'login' in module) {
|
||||||
await module.login?.(credentials.username, credentials.password)
|
await module.login?.(credentials?.username, credentials?.password)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export default class Deezer implements StreamerWithLogin {
|
|||||||
availableFormats: Set<DeezerFormat> = new Set()
|
availableFormats: Set<DeezerFormat> = new Set()
|
||||||
|
|
||||||
constructor(options?: DeezerOptions) {
|
constructor(options?: DeezerOptions) {
|
||||||
if (options?.arl) this.#loginViaArl(options.arl)
|
if (options?.arl) this.arl = options.arl
|
||||||
}
|
}
|
||||||
|
|
||||||
async #apiCall<T extends keyof APIMethod>(
|
async #apiCall<T extends keyof APIMethod>(
|
||||||
@@ -106,6 +106,7 @@ export default class Deezer implements StreamerWithLogin {
|
|||||||
|
|
||||||
if (error.constructor.name == 'Object') {
|
if (error.constructor.name == 'Object') {
|
||||||
const [type, msg] = Object.entries(error)[0]
|
const [type, msg] = Object.entries(error)[0]
|
||||||
|
if (type == 'VALID_TOKEN_REQUIRED') throw new Error('Invalid ARL')
|
||||||
throw new Error(`API Error: ${type}\n${msg}`)
|
throw new Error(`API Error: ${type}\n${msg}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,9 +153,8 @@ export default class Deezer implements StreamerWithLogin {
|
|||||||
|
|
||||||
async login(username: string, password: string): Promise<void> {
|
async login(username: string, password: string): Promise<void> {
|
||||||
if (this.arl) {
|
if (this.arl) {
|
||||||
return
|
await this.#loginViaArl(this.arl)
|
||||||
}
|
} else {
|
||||||
|
|
||||||
const resp = await fetch('https://www.deezer.com/', { headers: this.headers })
|
const resp = await fetch('https://www.deezer.com/', { headers: this.headers })
|
||||||
const setCookie = resp.headers.get('Set-Cookie') ?? ''
|
const setCookie = resp.headers.get('Set-Cookie') ?? ''
|
||||||
const sid = setCookie.match(/sid=(fr[0-9a-f]+)/)![1]
|
const sid = setCookie.match(/sid=(fr[0-9a-f]+)/)![1]
|
||||||
@@ -176,9 +176,9 @@ export default class Deezer implements StreamerWithLogin {
|
|||||||
if (error) throw new Error('Error while getting access token, check your credentials')
|
if (error) throw new Error('Error while getting access token, check your credentials')
|
||||||
|
|
||||||
const arl = await this.#apiCall('user.getArl')
|
const arl = await this.#apiCall('user.getArl')
|
||||||
|
|
||||||
await this.#loginViaArl(arl)
|
await this.#loginViaArl(arl)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ---------- SEARCH ---------- */
|
/* ---------- SEARCH ---------- */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user