From 405b2524f9c01cbef557bae2a842f09e5ac825d0 Mon Sep 17 00:00:00 2001 From: Tyler Richards Date: Sat, 29 Jun 2019 19:45:08 -0500 Subject: [PATCH] Fixes #37 by adding support for YouTube Music URLs --- package.json | 2 +- src/util/index.js | 7 ++++++- test/index.js | 7 +++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d462a3a..e2001f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-youtube-api", - "version": "5.2.0", + "version": "5.2.1", "description": "A module to simplify the YouTube API.", "author": "Bryan Pikaard ", "maintainers": [ diff --git a/src/util/index.js b/src/util/index.js index 61b882e..282bde3 100644 --- a/src/util/index.js +++ b/src/util/index.js @@ -10,7 +10,8 @@ exports.parseURL = (url) => { switch (parsed.hostname) { case 'www.youtube.com': case 'youtube.com': - case 'm.youtube.com': { + case 'm.youtube.com': + case 'music.youtube.com': { const idRegex = /^[a-zA-Z0-9-_]+$/; if (parsed.pathname === '/watch') { if (!idRegex.test(parsed.query.v)) return {}; @@ -24,6 +25,10 @@ exports.parseURL = (url) => { const id = parsed.pathname.replace('/channel/', ''); if (!idRegex.test(id)) return {}; return { channel: id }; + } else if (parsed.pathname.startsWith('/browse/')) { + const id = parsed.pathname.replace('/browse/', ''); + if (!idRegex.test(id)) return {}; + return { channel: id }; } return {}; diff --git a/test/index.js b/test/index.js index e396f02..1fd6f26 100644 --- a/test/index.js +++ b/test/index.js @@ -21,6 +21,13 @@ describe('util', function() { }); }); + it('can parse a music video URL', function() { + const parsed = YouTube.util.parseURL('https://music.youtube.com/watch?v=zBBOfCRhEz4'); + assert.deepEqual(parsed, { + video: 'zBBOfCRhEz4', + }); + }); + it('can parse a video and playlist URL', function() { const parsed = YouTube.util.parseURL('https://www.youtube.com/watch?v=MLB8tSA2GFA&list=PLe8jmEHFkvsbeJL2QNucGv00eO8PKbSUn'); assert.deepEqual(parsed, {