File tree 6 files changed +40
-26
lines changed
6 files changed +40
-26
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import { t } from '@/i18n';
6
6
import type { ConnectionEventUnion } from '@/plugins/music-together/connection' ;
7
7
import type { Profile , VideoData } from '../types' ;
8
8
import type { QueueItem } from '@/types/datahost-get-state' ;
9
- import type { QueueElement } from '@/types/queue' ;
9
+ import type { QueueElement , Store } from '@/types/queue' ;
10
10
11
11
const getHeaderPayload = ( ( ) => {
12
12
let payload : {
@@ -266,7 +266,8 @@ export class Queue {
266
266
}
267
267
268
268
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' ] ;
270
271
}
271
272
272
273
injection ( ) {
@@ -295,7 +296,11 @@ export class Queue {
295
296
videoId : it ! . videoId ,
296
297
ownerId : this . owner ! . id ,
297
298
} ) satisfies VideoData ,
298
- event . payload ! . items ! ,
299
+ (
300
+ event . payload ! as {
301
+ items : QueueItem [ ] ;
302
+ }
303
+ ) . items ,
299
304
) ;
300
305
const index = this . _videoList . length + videoList . length - 1 ;
301
306
@@ -334,7 +339,11 @@ export class Queue {
334
339
videoId : it ! . videoId ,
335
340
ownerId : this . owner ! . id ,
336
341
} ) satisfies VideoData ,
337
- event . payload ! . items ! ,
342
+ (
343
+ event . payload ! as {
344
+ items : QueueItem [ ] ;
345
+ }
346
+ ) . items ,
338
347
) ,
339
348
} ,
340
349
} ) ;
@@ -407,7 +416,13 @@ export class Queue {
407
416
} ,
408
417
} ,
409
418
} ;
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
+ ) ;
411
426
} ;
412
427
}
413
428
Original file line number Diff line number Diff line change 1
1
import type { LyricProvider , LyricResult , SearchSongInfo } from '../types' ;
2
+ import type { YouTubeMusicAppElement } from '@/types/youtube-music-app-element' ;
2
3
3
4
const headers = {
4
5
'Accept' : 'application/json' ,
@@ -102,19 +103,17 @@ export class YTMusic implements LyricProvider {
102
103
. padStart ( 2 , '0' ) } .${ remaining . toString ( ) . padStart ( 2 , '0' ) } `;
103
104
}
104
105
105
- private ENDPOINT = 'https://youtubei.googleapis.com/youtubei/v1/' ;
106
106
// RATE LIMITED (2 req per sec)
107
107
private PROXIED_ENDPOINT = 'https://ytmbrowseproxy.zvz.be/' ;
108
108
109
109
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 > ;
118
117
}
119
118
120
119
private fetchBrowse ( browseId : string ) {
Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ import type { PluginConfig } from '@/types/plugins';
22
22
import type { YoutubePlayer } from '@/types/youtube-player' ;
23
23
import type { QueueElement } from '@/types/queue' ;
24
24
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' ;
25
27
26
28
let api : ( Element & YoutubePlayer ) | null = null ;
27
29
let isPluginLoaded = false ;
@@ -41,17 +43,6 @@ async function listenForApiLoad() {
41
43
}
42
44
}
43
45
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
-
55
46
async function onApiLoaded ( ) {
56
47
// Workaround for #2459
57
48
document
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import type { YoutubePlayer } from '@/types/youtube-player';
2
2
import type { GetState , QueueItem } from '@/types/datahost-get-state' ;
3
3
4
4
type StoreState = GetState ;
5
- type Store = {
5
+ export type Store = {
6
6
dispatch : ( obj : { type : string ; payload ?: unknown } ) => void ;
7
7
8
8
getState : ( ) => StoreState ;
Original file line number Diff line number Diff line change
1
+ export interface SearchBoxElement extends HTMLElement {
2
+ getSearchboxStats ( ) : unknown ;
3
+ }
Original file line number Diff line number Diff line change
1
+ export interface YouTubeMusicAppElement extends HTMLElement {
2
+ navigate ( page : string ) : void ;
3
+ networkManager : {
4
+ fetch : ( url : string , data : unknown ) => Promise < unknown > ;
5
+ } ;
6
+ }
You can’t perform that action at this time.
0 commit comments