From fc6007b472625838b02631692297f9685b39a426 Mon Sep 17 00:00:00 2001 From: AtariTom Date: Sat, 29 Oct 2022 22:26:56 -0400 Subject: [PATCH] defaultIcon and music fix --- package-lock.json | 4 +-- package.json | 2 +- play-dl/YouTube/utils/extractor.ts | 39 +++++++++++++++--------------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9af8609..b880b0b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "play-dl", - "version": "1.9.5", + "version": "1.9.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "play-dl", - "version": "1.9.5", + "version": "1.9.6", "license": "GPL-3.0", "dependencies": { "play-audio": "^0.5.2" diff --git a/package.json b/package.json index d8a20eb..095a9ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "play-dl", - "version": "1.9.5", + "version": "1.9.6", "description": "YouTube, SoundCloud, Spotify, Deezer searching and streaming for discord-js bots", "main": "dist/index.js", "typings": "dist/index.d.ts", diff --git a/play-dl/YouTube/utils/extractor.ts b/play-dl/YouTube/utils/extractor.ts index 345ffb2..28255c4 100644 --- a/play-dl/YouTube/utils/extractor.ts +++ b/play-dl/YouTube/utils/extractor.ts @@ -212,24 +212,22 @@ export async function video_basic_info(url: string, options: InfoOptions = {}): } ); const microformat = player_response.microformat.playerMicroformatRenderer; - const musicInfo = - initial_response.contents.twoColumnWatchNextResults.results.results.contents?.[1]?.videoSecondaryInfoRenderer - ?.metadataRowContainer?.metadataRowContainerRenderer?.rows; + const musicInfo = initial_response.engagementPanels.find((item: any) => item?.engagementPanelSectionListRenderer?.panelIdentifier == 'engagement-panel-structured-description')?.engagementPanelSectionListRenderer.content.structuredDescriptionContentRenderer.items + .find((el: any) => el.videoDescriptionMusicSectionRenderer)?.videoDescriptionMusicSectionRenderer.carouselLockups; + const music: any[] = []; if (musicInfo) { musicInfo.forEach((x: any) => { - if (!x.metadataRowRenderer) return; - const row = x.metadataRowRenderer; + if (!x.carouselLockupRenderer) return; + const row = x.carouselLockupRenderer; - const title = row.title.simpleText ?? row.title.runs[0].text; - const contents = row.contents[0].simpleText ?? row.contents[0]?.runs?.[0]?.text; - const url = row.contents[0]?.runs?.[0]?.navigationEndpoint?.commandMetadata?.webCommandMetadata.url; + const song = row.videoLockup?.compactVideoRenderer.title.simpleText ?? row.videoLockup?.compactVideoRenderer.title.runs?.find((x:any) => x.text)?.text; + const metadata = row.infoRows?.map((info: any) => [info.infoRowRenderer.title.simpleText.toLowerCase(), ((info.infoRowRenderer.expandedMetadata ?? info.infoRowRenderer.defaultMetadata)?.runs?.map((i:any) => i.text).join("")) ?? info.infoRowRenderer.defaultMetadata?.simpleText ?? info.infoRowRenderer.expandedMetadata?.simpleText ?? ""]); + const contents = Object.fromEntries(metadata ?? {}); + const id = row.videoLockup?.compactVideoRenderer.navigationEndpoint?.watchEndpoint.videoId + ?? row.infoRows?.find((x: any) => x.infoRowRenderer.title.simpleText.toLowerCase() == "song")?.infoRowRenderer.defaultMetadata.runs?.find((x: any) => x.navigationEndpoint)?.navigationEndpoint.watchEndpoint?.videoId; - if (music.length === 0) music.push({}); - - music[music.length - 1][title.toLowerCase()] = url ? {text: contents, url: `https://www.youtube.com${url}`} : contents; - - if (row.hasDividerLine) music.push({}); + music.push({song, url: id ? `https://www.youtube.com/watch?v=${id}` : null, ...contents}) }); } const rawChapters = @@ -258,6 +256,13 @@ export async function video_basic_info(url: string, options: InfoOptions = {}): upcomingDate = new Date(parseInt(timestamp) * 1000); } } + + const likeRenderer = initial_response.contents.twoColumnWatchNextResults.results.results.contents + .find((content: any) => content.videoPrimaryInfoRenderer) + ?.videoPrimaryInfoRenderer.videoActions.menuRenderer.topLevelButtons?.find( + (button: any) => button.toggleButtonRenderer?.defaultIcon.iconType === 'LIKE' || button.segmentedLikeDislikeButtonRenderer?.likeButton.toggleButtonRenderer?.defaultIcon.iconType === 'LIKE' + ) + const video_details = new YouTubeVideo({ id: vid.videoId, title: vid.title, @@ -279,12 +284,8 @@ export async function video_basic_info(url: string, options: InfoOptions = {}): views: vid.viewCount, tags: vid.keywords, likes: parseInt( - initial_response.contents.twoColumnWatchNextResults.results.results.contents - .find((content: any) => content.videoPrimaryInfoRenderer) - ?.videoPrimaryInfoRenderer.videoActions.menuRenderer.topLevelButtons?.find( - (button: any) => button.toggleButtonRenderer.defaultIcon.iconType === 'LIKE' - ) - ?.toggleButtonRenderer.defaultText.accessibility?.accessibilityData.label.replace(/\D+/g, '') ?? 0 + likeRenderer?.toggleButtonRenderer?.defaultText.accessibility?.accessibilityData.label.replace(/\D+/g, '') ?? + likeRenderer?.segmentedLikeDislikeButtonRenderer?.likeButton.toggleButtonRenderer?.defaultText.accessibility?.accessibilityData.label.replace(/\D+/g, '') ?? 0 ), live: vid.isLiveContent, private: vid.isPrivate,