diff --git a/src/plugins/music-together/queue/song.ts b/src/plugins/music-together/queue/song.ts index e791c942..1eac6f71 100644 --- a/src/plugins/music-together/queue/song.ts +++ b/src/plugins/music-together/queue/song.ts @@ -1,4 +1,5 @@ -import { extractToken, getAuthorizationHeader, getClient } from './client'; +import type { YouTubeMusicAppElement } from '@/types/youtube-music-app-element'; +import type { QueueElement } from '@/types/queue'; type QueueRendererResponse = { queueDatas: { @@ -11,40 +12,15 @@ type QueueRendererResponse = { export const getMusicQueueRenderer = async ( videoIds: string[], ): Promise => { - const token = extractToken(); - if (!token) return null; + const queue = document.querySelector('#queue'); + const app = document.querySelector('ytmusic-app'); + if (!app) return null; - const response = await fetch( - 'https://music.youtube.com/youtubei/v1/music/get_queue?key=AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30&prettyPrint=false', - { - method: 'POST', - credentials: 'include', - body: JSON.stringify({ - context: { - client: getClient(), - request: { - useSsl: true, - internalExperimentFlags: [], - consistencyTokenJars: [], - }, - user: { - lockedSafetyMode: false, - }, - }, - videoIds, - }), - headers: { - 'Content-Type': 'application/json', - 'Origin': 'https://music.youtube.com', - 'Authorization': await getAuthorizationHeader(token), - }, - }, - ); + const store = queue?.queue.store.store; + if (!store) return null; - const text = await response.text(); - try { - return JSON.parse(text) as QueueRendererResponse; - } catch {} - - return null; + return (await app.networkManager.fetch('/music/get_queue', { + queueContextParams: store.getState().queue.queueContextParams, + videoIds, + })) as QueueRendererResponse | null; };