Skip to content

Commit 03098b6

Browse files
committed
Fixed aggregation from youtube plugin
1 parent 495e3d7 commit 03098b6

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

plugins/youtube/index.ts

+16-15
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
transcribe,
1111
} from "./plugin";
1212
import { async } from "@amadeus-music/core";
13-
import { Innertube } from "youtubei.js";
13+
import { ClientType, Innertube, YTNodes } from "youtubei.js";
1414
import { convert } from "./types";
1515

1616
init(function* () {
@@ -19,9 +19,10 @@ init(function* () {
1919
1000,
2020
);
2121

22-
const youtube = yield* async(Innertube.create());
22+
const youtube = yield* async(Innertube.create({ client_type: ClientType.IOS }));
2323
this.youtube.player = youtube.session.player;
2424
this.youtube.music = youtube.music;
25+
this.youtube.instance = youtube;
2526
info("Player initialized successfully.");
2627
clearTimeout(loadMessage);
2728
});
@@ -44,8 +45,8 @@ desource(function* (track) {
4445
if (!id) return;
4546

4647
yield yield* async<string>(
47-
this.youtube.music
48-
.getInfo(id)
48+
this.youtube.instance
49+
.getBasicInfo(id, 'IOS')
4950
.then((x) => x.chooseFormat({ type: "audio", quality: "best" }))
5051
.then((x) => x.decipher(this.youtube.player)),
5152
);
@@ -58,15 +59,15 @@ expand(function* (type, what, _) {
5859
const playlist = yield* async(
5960
type === "artist"
6061
? 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)
6667
: this.youtube.music
67-
.getAlbum(id)
68-
.then((x) => x.url?.match(/list=([^&]+)/)?.[1])
69-
.catch(() => undefined),
68+
.getAlbum(id)
69+
.then((x) => x.url?.match(/list=([^&]+)/)?.[1])
70+
.catch(() => undefined),
7071
);
7172
if (!playlist) return;
7273

@@ -100,8 +101,8 @@ relate(function* (type, to, _) {
100101
const items = yield* async(
101102
this.youtube.music
102103
.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)
105106
.catch(() => undefined),
106107
);
107108
yield* convert(items, type);
@@ -111,7 +112,7 @@ scrape(function* (url) {
111112
const id = url.match(/youtu(be.com|.be)\/(watch\?v=)?([a-zA-Z0-9_-]+)/)?.[3];
112113
if (!id) return;
113114

114-
const info = yield* async(this.youtube.music.getInfo(id));
115+
const info = yield* async(this.youtube.instance.getBasicInfo(id, 'IOS'));
115116
yield* convert([info["basic_info"]], "track");
116117
});
117118

plugins/youtube/plugin.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const {
1717
version,
1818
context: {
1919
youtube: {
20+
instance: {} as never as Innertube,
2021
music: {} as never as Innertube["music"],
2122
player: {} as never as Innertube["session"]["player"],
2223
},

0 commit comments

Comments
 (0)