Skip to content

Commit 80471b0

Browse files
committed
fix: use networkManager.fetch instead of fetch
1 parent 22fdfe3 commit 80471b0

File tree

6 files changed

+40
-26
lines changed

6 files changed

+40
-26
lines changed

src/plugins/music-together/queue/queue.ts

+20-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { t } from '@/i18n';
66
import type { ConnectionEventUnion } from '@/plugins/music-together/connection';
77
import type { Profile, VideoData } from '../types';
88
import type { QueueItem } from '@/types/datahost-get-state';
9-
import type { QueueElement } from '@/types/queue';
9+
import type { QueueElement, Store } from '@/types/queue';
1010

1111
const getHeaderPayload = (() => {
1212
let payload: {
@@ -266,7 +266,8 @@ export class Queue {
266266
}
267267

268268
if (this.originalDispatch)
269-
this.queue.queue.store.store.dispatch = this.originalDispatch;
269+
this.queue.queue.store.store.dispatch = this
270+
.originalDispatch as Store['dispatch'];
270271
}
271272

272273
injection() {
@@ -295,7 +296,11 @@ export class Queue {
295296
videoId: it!.videoId,
296297
ownerId: this.owner!.id,
297298
}) satisfies VideoData,
298-
event.payload!.items!,
299+
(
300+
event.payload! as {
301+
items: QueueItem[];
302+
}
303+
).items,
299304
);
300305
const index = this._videoList.length + videoList.length - 1;
301306

@@ -334,7 +339,11 @@ export class Queue {
334339
videoId: it!.videoId,
335340
ownerId: this.owner!.id,
336341
}) satisfies VideoData,
337-
event.payload!.items!,
342+
(
343+
event.payload! as {
344+
items: QueueItem[];
345+
}
346+
).items,
338347
),
339348
},
340349
});
@@ -407,7 +416,13 @@ export class Queue {
407416
},
408417
},
409418
};
410-
this.originalDispatch?.call(fakeContext, event);
419+
this.originalDispatch?.call(
420+
fakeContext,
421+
event as {
422+
type: string;
423+
payload?: { items?: QueueItem[] | undefined } | undefined;
424+
},
425+
);
411426
};
412427
}
413428

src/plugins/synced-lyrics/providers/YTMusic.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { LyricProvider, LyricResult, SearchSongInfo } from '../types';
2+
import type { YouTubeMusicAppElement } from '@/types/youtube-music-app-element';
23

34
const headers = {
45
'Accept': 'application/json',
@@ -102,19 +103,17 @@ export class YTMusic implements LyricProvider {
102103
.padStart(2, '0')}.${remaining.toString().padStart(2, '0')}`;
103104
}
104105

105-
private ENDPOINT = 'https://youtubei.googleapis.com/youtubei/v1/';
106106
// RATE LIMITED (2 req per sec)
107107
private PROXIED_ENDPOINT = 'https://ytmbrowseproxy.zvz.be/';
108108

109109
private fetchNext(videoId: string) {
110-
return fetch(this.ENDPOINT + 'next?prettyPrint=false', {
111-
headers,
112-
method: 'POST',
113-
body: JSON.stringify({
114-
videoId,
115-
context: { client },
116-
}),
117-
}).then((res) => res.json()) as Promise<NextData>;
110+
const app = document.querySelector<YouTubeMusicAppElement>('ytmusic-app');
111+
112+
if (!app) return null;
113+
114+
return app.networkManager.fetch('/next?prettyPrint=false', {
115+
videoId,
116+
}) as Promise<NextData>;
118117
}
119118

120119
private fetchBrowse(browseId: string) {

src/renderer.ts

+2-11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import type { PluginConfig } from '@/types/plugins';
2222
import type { YoutubePlayer } from '@/types/youtube-player';
2323
import type { QueueElement } from '@/types/queue';
2424
import type { QueueResponse } from '@/types/youtube-music-desktop-internal';
25+
import type { YouTubeMusicAppElement } from '@/types/youtube-music-app-element';
26+
import type { SearchBoxElement } from '@/types/search-box-element';
2527

2628
let api: (Element & YoutubePlayer) | null = null;
2729
let isPluginLoaded = false;
@@ -41,17 +43,6 @@ async function listenForApiLoad() {
4143
}
4244
}
4345

44-
interface YouTubeMusicAppElement extends HTMLElement {
45-
navigate(page: string): void;
46-
networkManager: {
47-
fetch: (url: string, data: unknown) => Promise<unknown>;
48-
};
49-
}
50-
51-
interface SearchBoxElement extends HTMLElement {
52-
getSearchboxStats(): unknown;
53-
}
54-
5546
async function onApiLoaded() {
5647
// Workaround for #2459
5748
document

src/types/queue.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { YoutubePlayer } from '@/types/youtube-player';
22
import type { GetState, QueueItem } from '@/types/datahost-get-state';
33

44
type StoreState = GetState;
5-
type Store = {
5+
export type Store = {
66
dispatch: (obj: { type: string; payload?: unknown }) => void;
77

88
getState: () => StoreState;

src/types/search-box-element.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface SearchBoxElement extends HTMLElement {
2+
getSearchboxStats(): unknown;
3+
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface YouTubeMusicAppElement extends HTMLElement {
2+
navigate(page: string): void;
3+
networkManager: {
4+
fetch: (url: string, data: unknown) => Promise<unknown>;
5+
};
6+
}

0 commit comments

Comments
 (0)