mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
fix: use networkManager.fetch instead of fetch
This commit is contained in:
@ -6,7 +6,7 @@ import { t } from '@/i18n';
|
|||||||
import type { ConnectionEventUnion } from '@/plugins/music-together/connection';
|
import type { ConnectionEventUnion } from '@/plugins/music-together/connection';
|
||||||
import type { Profile, VideoData } from '../types';
|
import type { Profile, VideoData } from '../types';
|
||||||
import type { QueueItem } from '@/types/datahost-get-state';
|
import type { QueueItem } from '@/types/datahost-get-state';
|
||||||
import type { QueueElement } from '@/types/queue';
|
import type { QueueElement, Store } from '@/types/queue';
|
||||||
|
|
||||||
const getHeaderPayload = (() => {
|
const getHeaderPayload = (() => {
|
||||||
let payload: {
|
let payload: {
|
||||||
@ -266,7 +266,8 @@ export class Queue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.originalDispatch)
|
if (this.originalDispatch)
|
||||||
this.queue.queue.store.store.dispatch = this.originalDispatch;
|
this.queue.queue.store.store.dispatch = this
|
||||||
|
.originalDispatch as Store['dispatch'];
|
||||||
}
|
}
|
||||||
|
|
||||||
injection() {
|
injection() {
|
||||||
@ -295,7 +296,11 @@ export class Queue {
|
|||||||
videoId: it!.videoId,
|
videoId: it!.videoId,
|
||||||
ownerId: this.owner!.id,
|
ownerId: this.owner!.id,
|
||||||
}) satisfies VideoData,
|
}) satisfies VideoData,
|
||||||
event.payload!.items!,
|
(
|
||||||
|
event.payload! as {
|
||||||
|
items: QueueItem[];
|
||||||
|
}
|
||||||
|
).items,
|
||||||
);
|
);
|
||||||
const index = this._videoList.length + videoList.length - 1;
|
const index = this._videoList.length + videoList.length - 1;
|
||||||
|
|
||||||
@ -334,7 +339,11 @@ export class Queue {
|
|||||||
videoId: it!.videoId,
|
videoId: it!.videoId,
|
||||||
ownerId: this.owner!.id,
|
ownerId: this.owner!.id,
|
||||||
}) satisfies VideoData,
|
}) satisfies VideoData,
|
||||||
event.payload!.items!,
|
(
|
||||||
|
event.payload! as {
|
||||||
|
items: QueueItem[];
|
||||||
|
}
|
||||||
|
).items,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -407,7 +416,13 @@ export class Queue {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
this.originalDispatch?.call(fakeContext, event);
|
this.originalDispatch?.call(
|
||||||
|
fakeContext,
|
||||||
|
event as {
|
||||||
|
type: string;
|
||||||
|
payload?: { items?: QueueItem[] | undefined } | undefined;
|
||||||
|
},
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import type { LyricProvider, LyricResult, SearchSongInfo } from '../types';
|
import type { LyricProvider, LyricResult, SearchSongInfo } from '../types';
|
||||||
|
import type { YouTubeMusicAppElement } from '@/types/youtube-music-app-element';
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
@ -102,19 +103,17 @@ export class YTMusic implements LyricProvider {
|
|||||||
.padStart(2, '0')}.${remaining.toString().padStart(2, '0')}`;
|
.padStart(2, '0')}.${remaining.toString().padStart(2, '0')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ENDPOINT = 'https://youtubei.googleapis.com/youtubei/v1/';
|
|
||||||
// RATE LIMITED (2 req per sec)
|
// RATE LIMITED (2 req per sec)
|
||||||
private PROXIED_ENDPOINT = 'https://ytmbrowseproxy.zvz.be/';
|
private PROXIED_ENDPOINT = 'https://ytmbrowseproxy.zvz.be/';
|
||||||
|
|
||||||
private fetchNext(videoId: string) {
|
private fetchNext(videoId: string) {
|
||||||
return fetch(this.ENDPOINT + 'next?prettyPrint=false', {
|
const app = document.querySelector<YouTubeMusicAppElement>('ytmusic-app');
|
||||||
headers,
|
|
||||||
method: 'POST',
|
if (!app) return null;
|
||||||
body: JSON.stringify({
|
|
||||||
videoId,
|
return app.networkManager.fetch('/next?prettyPrint=false', {
|
||||||
context: { client },
|
videoId,
|
||||||
}),
|
}) as Promise<NextData>;
|
||||||
}).then((res) => res.json()) as Promise<NextData>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fetchBrowse(browseId: string) {
|
private fetchBrowse(browseId: string) {
|
||||||
|
|||||||
@ -22,6 +22,8 @@ import type { PluginConfig } from '@/types/plugins';
|
|||||||
import type { YoutubePlayer } from '@/types/youtube-player';
|
import type { YoutubePlayer } from '@/types/youtube-player';
|
||||||
import type { QueueElement } from '@/types/queue';
|
import type { QueueElement } from '@/types/queue';
|
||||||
import type { QueueResponse } from '@/types/youtube-music-desktop-internal';
|
import type { QueueResponse } from '@/types/youtube-music-desktop-internal';
|
||||||
|
import type { YouTubeMusicAppElement } from '@/types/youtube-music-app-element';
|
||||||
|
import type { SearchBoxElement } from '@/types/search-box-element';
|
||||||
|
|
||||||
let api: (Element & YoutubePlayer) | null = null;
|
let api: (Element & YoutubePlayer) | null = null;
|
||||||
let isPluginLoaded = false;
|
let isPluginLoaded = false;
|
||||||
@ -41,17 +43,6 @@ async function listenForApiLoad() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface YouTubeMusicAppElement extends HTMLElement {
|
|
||||||
navigate(page: string): void;
|
|
||||||
networkManager: {
|
|
||||||
fetch: (url: string, data: unknown) => Promise<unknown>;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SearchBoxElement extends HTMLElement {
|
|
||||||
getSearchboxStats(): unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function onApiLoaded() {
|
async function onApiLoaded() {
|
||||||
// Workaround for #2459
|
// Workaround for #2459
|
||||||
document
|
document
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import type { YoutubePlayer } from '@/types/youtube-player';
|
|||||||
import type { GetState, QueueItem } from '@/types/datahost-get-state';
|
import type { GetState, QueueItem } from '@/types/datahost-get-state';
|
||||||
|
|
||||||
type StoreState = GetState;
|
type StoreState = GetState;
|
||||||
type Store = {
|
export type Store = {
|
||||||
dispatch: (obj: { type: string; payload?: unknown }) => void;
|
dispatch: (obj: { type: string; payload?: unknown }) => void;
|
||||||
|
|
||||||
getState: () => StoreState;
|
getState: () => StoreState;
|
||||||
|
|||||||
3
src/types/search-box-element.ts
Normal file
3
src/types/search-box-element.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export interface SearchBoxElement extends HTMLElement {
|
||||||
|
getSearchboxStats(): unknown;
|
||||||
|
}
|
||||||
6
src/types/youtube-music-app-element.ts
Normal file
6
src/types/youtube-music-app-element.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export interface YouTubeMusicAppElement extends HTMLElement {
|
||||||
|
navigate(page: string): void;
|
||||||
|
networkManager: {
|
||||||
|
fetch: (url: string, data: unknown) => Promise<unknown>;
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user