Skip to content

Commit a3b4baa

Browse files
authored
Merge pull request #90 from takker99/youtube-short
✨ youtube shortのサムネイル対応
2 parents 0e2b226 + 443eb95 commit a3b4baa

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

parseYoutube.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ export interface YoutubeProps {
77

88
const youtubeRegExp =
99
/https?:\/\/(?:www\.|)youtube\.com\/watch\?((?:[^\s]+&|)v=([a-zA-Z\d_-]+)(?:&[^\s]+|))/;
10-
const youtubeShortRegExp =
10+
const youtubeDotBeRegExp =
1111
/https?:\/\/youtu\.be\/([a-zA-Z\d_-]+)(?:\?([^\s]{0,100})|)/;
12+
const youtubeShortRegExp =
13+
/https?:\/\/(?:www\.|)youtube\.com\/shorts\/([a-zA-Z\d_-]+)(?:\?([^\s]+)|)/;
1214
const youtubeListRegExp =
1315
/https?:\/\/(?:www\.|)youtube\.com\/playlist\?((?:[^\s]+&|)list=([a-zA-Z\d_-]+)(?:&[^\s]+|))/;
1416

@@ -31,6 +33,16 @@ export const parseYoutube = (url: string): YoutubeProps | undefined => {
3133
};
3234
}
3335
}
36+
{
37+
const matches = url.match(youtubeDotBeRegExp);
38+
if (matches) {
39+
const [, videoId] = matches;
40+
return {
41+
videoId,
42+
params: new URLSearchParams("autoplay=0"),
43+
};
44+
}
45+
}
3446
{
3547
const matches = url.match(youtubeShortRegExp);
3648
if (matches) {

0 commit comments

Comments
 (0)