Skip to content

Commit

Permalink
Add support for timestamped youtube links
Browse files Browse the repository at this point in the history
  • Loading branch information
reda777 committed May 21, 2024
1 parent df5fbf3 commit c70e7bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
11 changes: 6 additions & 5 deletions assets/chat/js/hashlinkconverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ class HashLinkConverter {
case 'www.youtube.com':
case 'youtube.com':
match = pathname.match(this.youtubeRegex);
if (match) {
return `#youtube/${match[1]}`;
}
videoId = url.searchParams.get('v');
timestamp = url.searchParams.get('t');
videoId = url.searchParams.get('v');
if (!videoId) {
throw new Error(MISSING_VIDEO_ID_ERROR);
if (match) {
videoId = match[1];
} else {
throw new Error(MISSING_VIDEO_ID_ERROR);
}
}
return timestamp
? `#youtube/${videoId}?t=${timestamp}`
Expand Down
15 changes: 15 additions & 0 deletions assets/chat/js/hashlinkconverter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,31 @@ describe('Valid embeds', () => {
'https://www.youtube.com/live/EHs-_2ddcUQ?feature=share',
'#youtube/EHs-_2ddcUQ',
],
[
'Youtube live stream link with timestamp',
'https://www.youtube.com/live/XstSLjhzKX8?t=11447',
'#youtube/XstSLjhzKX8?t=11447',
],
[
'Youtube shorts link',
'https://youtube.com/shorts/Bg1JpTqc0iA?si=7pzY1RnY2fEe9A8_',
'#youtube/Bg1JpTqc0iA',
],
[
'Youtube shorts link with timestamp',
'https://www.youtube.com/shorts/Bg1JpTqc0iA?t=4&feature=share',
'#youtube/Bg1JpTqc0iA?t=4',
],
[
'Youtube embed link',
'https://www.youtube.com/embed/Akala8bkIu8',
'#youtube/Akala8bkIu8',
],
[
'Youtube embed link timestamp',
'https://www.youtube.com/embed/Akala8bkIu8?t=5',
'#youtube/Akala8bkIu8?t=5',
],
[
'Rumble embed',
'https://rumble.com/embed/v26pcdc/?pub=4',
Expand Down

0 comments on commit c70e7bf

Please sign in to comment.