@@ -10,7 +10,7 @@ import {
10
10
transcribe ,
11
11
} from "./plugin" ;
12
12
import { async } from "@amadeus-music/core" ;
13
- import { Innertube } from "youtubei.js" ;
13
+ import { ClientType , Innertube , YTNodes } from "youtubei.js" ;
14
14
import { convert } from "./types" ;
15
15
16
16
init ( function * ( ) {
@@ -19,9 +19,10 @@ init(function* () {
19
19
1000 ,
20
20
) ;
21
21
22
- const youtube = yield * async ( Innertube . create ( ) ) ;
22
+ const youtube = yield * async ( Innertube . create ( { client_type : ClientType . IOS } ) ) ;
23
23
this . youtube . player = youtube . session . player ;
24
24
this . youtube . music = youtube . music ;
25
+ this . youtube . instance = youtube ;
25
26
info ( "Player initialized successfully." ) ;
26
27
clearTimeout ( loadMessage ) ;
27
28
} ) ;
@@ -44,8 +45,8 @@ desource(function* (track) {
44
45
if ( ! id ) return ;
45
46
46
47
yield yield * async < string > (
47
- this . youtube . music
48
- . getInfo ( id )
48
+ this . youtube . instance
49
+ . getBasicInfo ( id , 'IOS' )
49
50
. then ( ( x ) => x . chooseFormat ( { type : "audio" , quality : "best" } ) )
50
51
. then ( ( x ) => x . decipher ( this . youtube . player ) ) ,
51
52
) ;
@@ -58,15 +59,15 @@ expand(function* (type, what, _) {
58
59
const playlist = yield * async (
59
60
type === "artist"
60
61
? this . youtube . music
61
- . getArtist ( id )
62
- . then ( ( x ) => x . sections ?. filter ( ( x ) => x . type === " MusicShelf" ) )
63
- . then ( ( x ) => x . find ( ( x : any ) => x . title . toString ( ) === "Songs" ) )
64
- . then < string | undefined > ( ( x : any ) => x ?. endpoint ?. payload ?. browseId )
65
- . catch ( ( ) => undefined )
62
+ . getArtist ( id )
63
+ . then ( ( x ) => x . sections ?. filter ( ( x ) => x . is ( YTNodes . MusicShelf ) ) )
64
+ . then ( ( x ) => x . find ( ( x ) => x . title . toString ( ) === "Songs" ) )
65
+ . then < string | undefined > ( ( x ) => x ?. endpoint ?. payload ?. browseId )
66
+ . catch ( ( ) => undefined )
66
67
: this . youtube . music
67
- . getAlbum ( id )
68
- . then ( ( x ) => x . url ?. match ( / l i s t = ( [ ^ & ] + ) / ) ?. [ 1 ] )
69
- . catch ( ( ) => undefined ) ,
68
+ . getAlbum ( id )
69
+ . then ( ( x ) => x . url ?. match ( / l i s t = ( [ ^ & ] + ) / ) ?. [ 1 ] )
70
+ . catch ( ( ) => undefined ) ,
70
71
) ;
71
72
if ( ! playlist ) return ;
72
73
@@ -100,8 +101,8 @@ relate(function* (type, to, _) {
100
101
const items = yield * async (
101
102
this . youtube . music
102
103
. getRelated ( id )
103
- . then ( ( x ) => x . find ( ( x ) => x . type === " MusicCarouselShelf" ) )
104
- . then ( ( x : any ) => x ? .contents )
104
+ . then ( ( x ) => 'contents' in x && x . contents . find ( ( x ) => x . is ( YTNodes . MusicCarouselShelf ) ) )
105
+ . then ( ( x ) => x ? x . contents . filter ( ( x ) => x . is ( YTNodes . MusicResponsiveListItem ) ) : undefined )
105
106
. catch ( ( ) => undefined ) ,
106
107
) ;
107
108
yield * convert ( items , type ) ;
@@ -111,7 +112,7 @@ scrape(function* (url) {
111
112
const id = url . match ( / y o u t u ( b e .c o m | .b e ) \/ ( w a t c h \? v = ) ? ( [ a - z A - Z 0 - 9 _ - ] + ) / ) ?. [ 3 ] ;
112
113
if ( ! id ) return ;
113
114
114
- const info = yield * async ( this . youtube . music . getInfo ( id ) ) ;
115
+ const info = yield * async ( this . youtube . instance . getBasicInfo ( id , 'IOS' ) ) ;
115
116
yield * convert ( [ info [ "basic_info" ] ] , "track" ) ;
116
117
} ) ;
117
118
0 commit comments