Skip to content

Commit

Permalink
Fixes #37 by adding support for YouTube Music URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
tjrgg committed Jun 30, 2019
1 parent 00d60e1 commit 405b252
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"maintainers": [
Expand Down
7 changes: 6 additions & 1 deletion src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand All @@ -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 {};
Expand Down
7 changes: 7 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit 405b252

Please sign in to comment.