Skip to content

Commit

Permalink
Update Youtube.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
MangoD33 committed Dec 24, 2024
1 parent a3a7907 commit c90cd39
Showing 1 changed file with 54 additions and 8 deletions.
62 changes: 54 additions & 8 deletions lib/Extractor/Youtube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,18 +368,64 @@ export class YoutubeiExtractor extends BaseExtractor<YoutubeiOptions> {
if (!query.includes("list=RD") && YoutubeiExtractor.validateURL(query))
context.type = QueryType.YOUTUBE_VIDEO;

if (context.type === QueryType.YOUTUBE_PLAYLIST) {
const url = new URL(query);

if (url.searchParams.has("v") && url.searchParams.has("list"))
context.type = QueryType.YOUTUBE_VIDEO;
}

switch (context.type) {
case QueryType.YOUTUBE_PLAYLIST: {
let playlist;
const playlistUrl = new URL(query);
const plId = playlistUrl.searchParams.get("list")!;
let playlist = await this.innerTube.getPlaylist(plId);
const videoId = playlistUrl.searchParams.get("v")!;

if (videoId && plId) {
const endpoint = new YTNodes.NavigationEndpoint({
continuationCommand: {
videoId: videoId,
playlistId: plId,
},
});
const mixVidInfo = await this.innerTube.getInfo(endpoint);
if (!mixVidInfo?.playlist)
throw new Error("Mix playlist not found or invalid");

playlist = {
info: {
title: mixVidInfo.playlist.title?.toString() ?? "UNKNOWN TITLE",
thumbnails:
(mixVidInfo.playlist.contents?.[0] as any)?.thumbnail ?? [],
description: "",
author: {
name:
mixVidInfo.playlist.author?.toString() ?? "UNKNOWN AUTHOR",
url: "",
},
},
channels: [
{
author: {
name:
mixVidInfo.playlist.author?.toString() ?? "UNKNOWN AUTHOR",
url: "",
},
},
],
videos: mixVidInfo.playlist.contents.map((item: any) => ({
type: "PlaylistVideo",
id: item.video_id,
title: { text: item.title?.toString() ?? "UNKNOWN TITLE" },
duration: { seconds: item.duration?.seconds ?? 0 },
thumbnails:
item.thumbnail?.map((t: { url: string }) => ({ url: t.url })) ??
[],
author: { name: item.author ?? "UNKNOWN AUTHOR", url: "" },
is_live: false,
})),
has_continuation: false,
async getContinuation() {
throw new Error("Mixes do not support continuation");
},
};
} else {
playlist = await this.innerTube.getPlaylist(plId);
}

const pl = new Playlist(this.context.player, {
title: playlist.info.title ?? "UNKNOWN PLAYLIST",
Expand Down

0 comments on commit c90cd39

Please sign in to comment.