Skip to content

Commit 4aa8397

Browse files
committed
fix(video): support YouTube short URLs (youtu.be)
Fixes #557, #554 YouTube share links (youtu.be/ID) were not recognized, only full URLs (youtube.com/watch?v=ID) worked. Changes: - Add youtu.be URL pattern matching - Improve video ID parsing to handle both formats - Strip query parameters from short URLs (e.g., ?si=...) - Also fixes parameter handling in full URLs (e.g., &feature=...) Now supports: - https://www.youtube.com/watch?v=VIDEO_ID - https://www.youtube.com/watch?v=VIDEO_ID&feature=share - https://youtu.be/VIDEO_ID - https://youtu.be/VIDEO_ID?si=XXXXX
1 parent 7d21718 commit 4aa8397

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

projects/angular-editor/src/lib/angular-editor.service.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export class AngularEditorService {
189189
}
190190

191191
insertVideo(videoUrl: string) {
192-
if (videoUrl.match('www.youtube.com')) {
192+
if (videoUrl.match('www.youtube.com') || videoUrl.match('youtu.be')) {
193193
this.insertYouTubeVideoTag(videoUrl);
194194
}
195195
if (videoUrl.match('vimeo.com')) {
@@ -198,7 +198,13 @@ export class AngularEditorService {
198198
}
199199

200200
private insertYouTubeVideoTag(videoUrl: string): void {
201-
const id = videoUrl.split('v=')[1];
201+
// Support both formats: youtube.com/watch?v=ID and youtu.be/ID
202+
let id: string;
203+
if (videoUrl.includes('youtu.be/')) {
204+
id = videoUrl.split('youtu.be/')[1].split('?')[0];
205+
} else {
206+
id = videoUrl.split('v=')[1].split('&')[0];
207+
}
202208
const imageUrl = `https://img.youtube.com/vi/${id}/0.jpg`;
203209
const thumbnail = `
204210
<div style='position: relative'>

0 commit comments

Comments
 (0)