Skip to content

Commit

Permalink
Support dropping YouTube music links into a playlist (#3116)
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop authored Nov 15, 2024
1 parent 6b21581 commit a964d8a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/sources/youtube/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,22 @@ function getStartTime(url: URL) {
return seconds;
}

const SHORT_HOSTNAMES = new Set([
'youtu.be',
'www.youtu.be',
]);
const LONG_HOSTNAMES = new Set([
'youtube.com',
'www.youtube.com',
'music.youtube.com',
]);

function fromMediaUrl(url: URL) {
let sourceID;
if (url.hostname === 'youtu.be' || url.hostname === 'www.youtu.be') {
if (SHORT_HOSTNAMES.has(url.hostname)) {
sourceID = url.pathname;
}
if ((url.hostname === 'youtube.com' || url.hostname === 'www.youtube.com') && url.pathname === '/watch') {
if (LONG_HOSTNAMES.has(url.hostname) && url.pathname === '/watch') {
sourceID = url.searchParams.get('v');
}

Expand Down

0 comments on commit a964d8a

Please sign in to comment.