From fcbff53a7a17e16adfd80cb0723273a17f473d2a Mon Sep 17 00:00:00 2001 From: Max Isom Date: Tue, 14 Sep 2021 09:42:45 -0400 Subject: [PATCH] Clean URL search params Closes #316 --- package.json | 2 +- src/services/get-songs.ts | 11 ++++++++++- yarn.lock | 11 ++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 2a0e0fc..d5f98f3 100644 --- a/package.json +++ b/package.json @@ -90,6 +90,6 @@ "spotify-web-api-node": "^5.0.2", "sqlite3": "^5.0.2", "youtube.ts": "^0.2.0", - "ytdl-core": "^4.8.3" + "ytdl-core": "^4.9.1" } } diff --git a/src/services/get-songs.ts b/src/services/get-songs.ts index c7d37ea..129f167 100644 --- a/src/services/get-songs.ts +++ b/src/services/get-songs.ts @@ -34,7 +34,16 @@ export default class { async youtubeVideo(url: string): Promise { try { - const videoDetails = await this.youtube.videos.get(url); + // Clean URL + const u = new URL(url); + + for (const [name] of u.searchParams) { + if (name !== 'v') { + u.searchParams.delete(name); + } + } + + const videoDetails = await this.youtube.videos.get(u.toString()); return { title: videoDetails.snippet.title, diff --git a/yarn.lock b/yarn.lock index d39518b..15fca20 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3295,7 +3295,7 @@ youtube.ts@^0.2.0: axios "^0.19.0" ytdl-core "^4.0.3" -ytdl-core@^4.0.3, ytdl-core@^4.8.3: +ytdl-core@^4.0.3: version "4.8.3" resolved "https://registry.yarnpkg.com/ytdl-core/-/ytdl-core-4.8.3.tgz#21570d1834db13dec7828cf87bbf4c83c0fe68d7" integrity sha512-cWCBeX4FCgjcKmuVK384MT582RIAakpUSeMF/NPVmhO8cWiG+LeQLnBordvLolb0iXYzfUvalgmycYAE5Sy6Xw== @@ -3303,3 +3303,12 @@ ytdl-core@^4.0.3, ytdl-core@^4.8.3: m3u8stream "^0.8.3" miniget "^4.0.0" sax "^1.1.3" + +ytdl-core@^4.9.1: + version "4.9.1" + resolved "https://registry.yarnpkg.com/ytdl-core/-/ytdl-core-4.9.1.tgz#f587e2bd8329b5133c0bac4ce5ee1f3c7a1175a9" + integrity sha512-6Jbp5RDhUEozlaJQAR+l8oV8AHsx3WUXxSyPxzE6wOIAaLql7Hjiy0ZM58wZoyj1YEenlEPjEqcJIjKYKxvHtQ== + dependencies: + m3u8stream "^0.8.3" + miniget "^4.0.0" + sax "^1.1.3"