mirror of
https://git.gay/lucida/lucida
synced 2025-12-11 20:15:14 +01:00
rewrite spotify stored creds login, bump librespot
This commit is contained in:
parent
6d0612a6eb
commit
c9918250c8
@ -36,7 +36,7 @@
|
||||
"dependencies": {
|
||||
"blowfish-cbc": "^1.0.1",
|
||||
"image-size": "^1.1.1",
|
||||
"librespot": "^0.2.15",
|
||||
"librespot": "^0.2.16",
|
||||
"undici": "^6.19.4",
|
||||
"xmldom-qsa": "^1.1.3"
|
||||
},
|
||||
|
||||
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
@ -15,8 +15,8 @@ importers:
|
||||
specifier: ^1.1.1
|
||||
version: 1.1.1
|
||||
librespot:
|
||||
specifier: ^0.2.15
|
||||
version: 0.2.15
|
||||
specifier: ^0.2.16
|
||||
version: 0.2.16
|
||||
undici:
|
||||
specifier: ^6.19.4
|
||||
version: 6.19.4
|
||||
@ -464,8 +464,8 @@ packages:
|
||||
resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==}
|
||||
engines: {node: '>= 0.8.0'}
|
||||
|
||||
librespot@0.2.15:
|
||||
resolution: {integrity: sha512-k8/qd7xWZ+eOGUmX4jevRS79+uMjisIeXzfeXc0roxUhJgRDzGYbGVblovy6378NR9OdoQtBhXts7k7uvgmF5g==}
|
||||
librespot@0.2.16:
|
||||
resolution: {integrity: sha512-fvVZO1bouQr3qtU7h+AHOrUqiEwKEUZkjH1LWp35MOnG193K+SVcFHx6y8QmcX7sxn9/ODKGT1XET/uJE5z4Mw==}
|
||||
|
||||
locate-path@6.0.0:
|
||||
resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==}
|
||||
@ -1138,7 +1138,7 @@ snapshots:
|
||||
prelude-ls: 1.2.1
|
||||
type-check: 0.4.0
|
||||
|
||||
librespot@0.2.15:
|
||||
librespot@0.2.16:
|
||||
dependencies:
|
||||
fast-xml-parser: 4.3.4
|
||||
protobufjs: 7.2.6
|
||||
|
||||
9
scripts/spotify-get-stored-creds.js
Normal file
9
scripts/spotify-get-stored-creds.js
Normal file
@ -0,0 +1,9 @@
|
||||
import Spotify from './../build/streamers/spotify/main.js'
|
||||
|
||||
const client = new Spotify({})
|
||||
await client.login(process.env.SPOTIFY_USERNAME, process.env.SPOTIFY_PASSWORD)
|
||||
|
||||
const storedCreds = client.getStoredCredentials()
|
||||
console.log('[spotify] New config:', storedCreds)
|
||||
|
||||
await client.disconnect()
|
||||
@ -17,7 +17,8 @@ import {
|
||||
} from '../../types.js'
|
||||
|
||||
interface SpotifyOptions extends LibrespotOptions {
|
||||
storedCredential?: boolean
|
||||
username?: string
|
||||
storedCredential?: string
|
||||
}
|
||||
|
||||
class Spotify implements StreamerWithLogin {
|
||||
@ -38,15 +39,26 @@ class Spotify implements StreamerWithLogin {
|
||||
}
|
||||
} as const
|
||||
|
||||
storedCredential: boolean
|
||||
loggedIn = false
|
||||
|
||||
constructor(options: SpotifyOptions) {
|
||||
this.client = new Librespot(options)
|
||||
this.storedCredential = options.storedCredential == true
|
||||
|
||||
const { username, storedCredential } = options
|
||||
if (username && storedCredential) {
|
||||
this.client.loginWithStoredCreds(username, storedCredential)
|
||||
this.loggedIn = true
|
||||
}
|
||||
}
|
||||
async login(username: string, password: string) {
|
||||
if (this.storedCredential) return await this.client.loginWithStoredCreds(username, password)
|
||||
else return await this.client.login(username, password)
|
||||
if (!this.loggedIn) {
|
||||
const result = await this.client.login(username, password)
|
||||
this.loggedIn = true
|
||||
return result
|
||||
}
|
||||
}
|
||||
getStoredCredentials() {
|
||||
return this.client.getStoredCredentials()
|
||||
}
|
||||
#getUrlParts(
|
||||
url: string
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user