Skip to content

Commit

Permalink
Add support for youtube live format
Browse files Browse the repository at this point in the history
  • Loading branch information
micohasanen committed Nov 6, 2023
1 parent 65c082c commit 1382c10
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions __tests__/youtube.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ describe('Youtube', () => {
expect(fn('http://www.youtube.com/attribution_link?u=/watch?v=ABC12302&feature=share&list=UUsnCjinFcybOuyJU1NFOJmg&a=LjnCygXKl21WkJdyKu9O-w').service).toBe('youtube');
});

test('handles youtube /live/ formats', () => {
expect(fn('https://www.youtube.com/live/ABC1230').id).toBe('ABC1230');
expect(fn('www.youtube-nocookie.com/live/ABC12301?feature=share').id).toBe('ABC12301');
expect(fn('http://www.youtube.com/live/ABC12302?feature=share').id).toBe('ABC12302');

expect(fn('http://www.youtube.com/live/ABC12302?feature=share').service).toBe('youtube');
});

test('youtube links returns undefined id if id missing', () => {
const object = fn('https://www.youtube.com');
expect(object.id).toBe(undefined);
Expand Down
8 changes: 8 additions & 0 deletions src/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,13 @@ export default function youtube(youtubeString) {
return stripParameters(string_.match(attrreg)[1]);
}

// Live
const livereg = /\/live\//g;

if (livereg.test(string_)) {
const liveid = string_.split(livereg)[1];
return stripParameters(liveid);
}

return undefined;
}

0 comments on commit 1382c10

Please sign in to comment.