add the arl login work

This commit is contained in:
aria
2024-07-29 14:58:05 -04:00
parent 38a06fea80
commit d48482abac
3 changed files with 29 additions and 29 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "lucida",
"version": "2.0.0-17",
"version": "2.0.0-18",
"description": "A modular music downloader tool",
"main": "build/index.js",
"type": "module",

View File

@@ -30,11 +30,11 @@ class Lucida {
}
async login() {
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 module = this.modules[i]
if (module && 'login' in module) {
await module.login?.(credentials.username, credentials.password)
await module.login?.(credentials?.username, credentials?.password)
}
}
}

View File

@@ -77,7 +77,7 @@ export default class Deezer implements StreamerWithLogin {
availableFormats: Set<DeezerFormat> = new Set()
constructor(options?: DeezerOptions) {
if (options?.arl) this.#loginViaArl(options.arl)
if (options?.arl) this.arl = options.arl
}
async #apiCall<T extends keyof APIMethod>(
@@ -106,6 +106,7 @@ export default class Deezer implements StreamerWithLogin {
if (error.constructor.name == 'Object') {
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}`)
}
@@ -152,9 +153,8 @@ export default class Deezer implements StreamerWithLogin {
async login(username: string, password: string): Promise<void> {
if (this.arl) {
return
}
await this.#loginViaArl(this.arl)
} else {
const resp = await fetch('https://www.deezer.com/', { headers: this.headers })
const setCookie = resp.headers.get('Set-Cookie') ?? ''
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')
const arl = await this.#apiCall('user.getArl')
await this.#loginViaArl(arl)
}
}
/* ---------- SEARCH ---------- */