add deezer session renewal

This commit is contained in:
uh wot 2024-08-07 01:32:55 +02:00
parent b842872d0b
commit 847ba0ec30
No known key found for this signature in database
GPG Key ID: CB2454984587B781

View File

@ -100,6 +100,10 @@ export default class Deezer implements StreamerWithLogin {
method: T,
data: { [key: string]: string | number | string[] } = {}
): Promise<APIMethod[T]> {
// sid + checkForm renewal
if (method != 'deezer.getUserData' && method != 'user.getArl' && this.#isSessionExpired())
await this.#apiCall('deezer.getUserData')
let apiToken = this.apiToken
if (method == 'deezer.getUserData' || method == 'user.getArl') apiToken = ''
@ -168,6 +172,10 @@ export default class Deezer implements StreamerWithLogin {
return userData
}
#isSessionExpired() {
return Date.now() - (this.renewTimestamp ?? 0) >= 3600 * 1000
}
#md5(str: string) {
return createHash('md5').update(str).digest('hex')
}
@ -428,7 +436,7 @@ export default class Deezer implements StreamerWithLogin {
trackTokenExpiry: number,
format: DeezerFormat
): Promise<string> {
if (Date.now() - (this.renewTimestamp ?? 0) >= 3600 * 1000)
if (this.#isSessionExpired())
// renew license token
await this.#apiCall('deezer.getUserData')