From f1784f3c2154f100bb6fba7f75d81e08fed8590b Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 7 Oct 2024 10:38:55 -0400 Subject: [PATCH] fix(ytmusic): Allow authUser to be number or string Fixes #199 --- config/ytmusic.json.example | 2 +- src/backend/common/infrastructure/config/source/ytmusic.ts | 2 +- src/backend/common/schema/aio-source.json | 5 ++++- src/backend/common/schema/aio.json | 5 ++++- src/backend/common/schema/source.json | 5 ++++- src/backend/sources/YTMusicSource.ts | 2 +- 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/config/ytmusic.json.example b/config/ytmusic.json.example index f052449a..758fb51a 100644 --- a/config/ytmusic.json.example +++ b/config/ytmusic.json.example @@ -5,7 +5,7 @@ "clients": [], "data": { "cookie": "VISITOR_INFO1_LIVE=jMDXz2_L8rY; __Secure-3PAPISID=3AxsXpSXGqOInSDn1jEKn; DEVICE_INFO=ChxOekU0TmTBpjek5EWZ0G; YSC=7gZdl3Zdl3; SID=TwhNsaZRXYTAtXxzGyu6rZdpg2HvGROeW8J4Ym_FhkhoZMUYEQ.; __Secure-1PSID=TwhNOsaZRXYTyRBe4rxAtXRIKsIEtk_Qot2VLBNfHQrQ.; __Secure-3PSID=ZRXYTAtXRIKsIEtk_Qot2yRBerZdpg2HvvZRXYTAtXRIKsIEtk_Qot2yRBerkuZICFQ.; HSID=A1UMmELW79; SSID=AKhomOs; APISID=IlHHmuzkPdQzZZDhHn3; SAPISID=3AxsXpy0u75Qb/n1jEKn; __Secure-1PAPISID=3AxsXpQb/AkSDn1jEKn; LOGIN_INFO=AFmP6vFpyVCZZAIgDwbkhWMBBhluaIWAPP:QUQ314UW5NWMjNmd2ZUJnYnJsakdIMjZoaE5zVVMjNmd2ZZUiHRlb3ZlV3ZIcUVyRVIMjNmdjNmd2ZZUivYlNqX2ZNZUiHdUNFNFdaYmJIW1NkJRX3hqdlU2YnFESkFuSS1uTldnZVRmLXNjWFc5OUJuR3dTd3JsZGZYa2EtZFQ2a0k2Ry1KQQ==; PREF=volume=26; SIDCC=AFvI_94PxXwls-ndqpGfPgFX3FWj80y_94PxXwls-ndqfSh15sP; __Secure-1PSIDCC=AFvIBnUbRr96I96UCIp2U4T8HRVk2B0HfKzhzxwsiP; __Secure-3PSIDCC=AFvIB3bINuUN0ETDR9gO91wpwWIVmpGki3BxT3bINuUN0ETDR9gO91wCH", - "authUser": "0" + "authUser": 0 } } ] diff --git a/src/backend/common/infrastructure/config/source/ytmusic.ts b/src/backend/common/infrastructure/config/source/ytmusic.ts index dd1af851..2e70513a 100644 --- a/src/backend/common/infrastructure/config/source/ytmusic.ts +++ b/src/backend/common/infrastructure/config/source/ytmusic.ts @@ -15,7 +15,7 @@ export interface YTMusicCredentials { * * @example [0] * */ - authUser?: number + authUser?: number | string } export interface YTMusicData extends YTMusicCredentials, CommonSourceData, PollingOptions { diff --git a/src/backend/common/schema/aio-source.json b/src/backend/common/schema/aio-source.json index 455b4478..997e3bd5 100644 --- a/src/backend/common/schema/aio-source.json +++ b/src/backend/common/schema/aio-source.json @@ -2734,7 +2734,10 @@ "authUser": { "description": "If the 'X-Goog-AuthUser' header is present in the Request Headers for music.youtube.com it must also be included", "title": "authUser", - "type": "number" + "type": [ + "string", + "number" + ] }, "cookie": { "description": "The cookie retrieved from the Request Headers of music.youtube.com after logging in.\n\nSee https://github.com/nickp10/youtube-music-ts-api/blob/master/DOCUMENTATION.md#authenticate and https://ytmusicapi.readthedocs.io/en/latest/setup.html#copy-authentication-headers for how to retrieve this value.", diff --git a/src/backend/common/schema/aio.json b/src/backend/common/schema/aio.json index e9ed40a2..2d15a1ae 100644 --- a/src/backend/common/schema/aio.json +++ b/src/backend/common/schema/aio.json @@ -3692,7 +3692,10 @@ "authUser": { "description": "If the 'X-Goog-AuthUser' header is present in the Request Headers for music.youtube.com it must also be included", "title": "authUser", - "type": "number" + "type": [ + "string", + "number" + ] }, "cookie": { "description": "The cookie retrieved from the Request Headers of music.youtube.com after logging in.\n\nSee https://github.com/nickp10/youtube-music-ts-api/blob/master/DOCUMENTATION.md#authenticate and https://ytmusicapi.readthedocs.io/en/latest/setup.html#copy-authentication-headers for how to retrieve this value.", diff --git a/src/backend/common/schema/source.json b/src/backend/common/schema/source.json index 3c149981..7252576a 100644 --- a/src/backend/common/schema/source.json +++ b/src/backend/common/schema/source.json @@ -2552,7 +2552,10 @@ "authUser": { "description": "If the 'X-Goog-AuthUser' header is present in the Request Headers for music.youtube.com it must also be included", "title": "authUser", - "type": "number" + "type": [ + "string", + "number" + ] }, "cookie": { "description": "The cookie retrieved from the Request Headers of music.youtube.com after logging in.\n\nSee https://github.com/nickp10/youtube-music-ts-api/blob/master/DOCUMENTATION.md#authenticate and https://ytmusicapi.readthedocs.io/en/latest/setup.html#copy-authentication-headers for how to retrieve this value.", diff --git a/src/backend/sources/YTMusicSource.ts b/src/backend/sources/YTMusicSource.ts index f8b308ac..621c8ce1 100644 --- a/src/backend/sources/YTMusicSource.ts +++ b/src/backend/sources/YTMusicSource.ts @@ -160,7 +160,7 @@ export default class YTMusicSource extends AbstractSource { // @ts-expect-error default does exist const ytm = new YouTubeMusic.default() as YouTubeMusic; try { - this.apiInstance = await ytm.authenticate(this.config.data.cookie, this.config.data.authUser, this.onAuthUpdate); + this.apiInstance = await ytm.authenticate(this.currentCreds.cookie, typeof this.config.data.authUser === 'string' ? Number.parseInt(this.config.data.authUser) : this.config.data.authUser, this.onAuthUpdate); } catch (e: any) { this.logger.error('Failed to authenticate', e); throw e;