From ff0129d9dbce61207638c2c7ab69cd8c87376594 Mon Sep 17 00:00:00 2001 From: AtariTom <81930474+AtariTom@users.noreply.github.com> Date: Fri, 8 Apr 2022 11:20:06 -0400 Subject: [PATCH] Added URL to properties in music object (#280) * Added URL endpoints to licensed music object * Added URL info to properties in music object * Added URL to properties in music object * Added URL support for the Video Music properties with typings * Added URL to music properties in YoutubeVideo * Fixed Typings * Added footnote to music property --- play-dl/YouTube/classes/Video.ts | 16 ++++++++++++++-- play-dl/YouTube/utils/extractor.ts | 5 +++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/play-dl/YouTube/classes/Video.ts b/play-dl/YouTube/classes/Video.ts index c8c1ffb..2d6c3da 100644 --- a/play-dl/YouTube/classes/Video.ts +++ b/play-dl/YouTube/classes/Video.ts @@ -1,14 +1,24 @@ import { YouTubeChannel } from './Channel'; import { YouTubeThumbnail } from './Thumbnail'; +/** + * Licensed music in the video + * + * The property names change depending on your region's language. + */ interface VideoMusic { - song?: string; - artist?: string; + song?: string | MusicEntry; + artist?: string | MusicEntry; album?: string; writers?: string; license?: string; } +interface MusicEntry { + text?: string; + url?: string; +} + interface VideoOptions { /** * YouTube Video ID @@ -80,6 +90,8 @@ interface VideoOptions { discretionAdvised?: boolean; /** * Gives info about music content in that video. + * + * The property names of VideoMusic change depending on your region's language. */ music?: VideoMusic[]; /** diff --git a/play-dl/YouTube/utils/extractor.ts b/play-dl/YouTube/utils/extractor.ts index cb80dcc..67f6866 100644 --- a/play-dl/YouTube/utils/extractor.ts +++ b/play-dl/YouTube/utils/extractor.ts @@ -223,10 +223,11 @@ export async function video_basic_info(url: string, options: InfoOptions = {}): 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; if (music.length === 0) music.push({}); - music[music.length - 1][title.toLowerCase()] = contents; + music[music.length - 1][title.toLowerCase()] = url ? {text: contents, url: `https://www.youtube.com${url}`} : contents; if (row.hasDividerLine) music.push({}); }); @@ -854,4 +855,4 @@ function parseDuration(text: string): number { default: return 0; } -} +} \ No newline at end of file