Skip to content

Commit

Permalink
feat: support YouTube shorts
Browse files Browse the repository at this point in the history
  • Loading branch information
radiovisual committed Dec 28, 2021
1 parent 3210402 commit dd44528
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
10 changes: 10 additions & 0 deletions __tests__/youtube.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import fn from '../src/index.js';
* http://y2u.be/id
* youtube://
*
* // shorts
* https://youtube.com/shorts/*
* https://www.youtube.com/shorts/*
*
* // /v/ or /vi/
* http://www.youtube.com/v/id
* http://youtube.com/vi/id?
Expand Down Expand Up @@ -64,6 +68,12 @@ describe('Youtube', () => {
expect(actual).toMatchObject(expected);
});

test('gets id from youtube shorts', () => {
expect(fn('https://youtube.com/shorts/123?i=4').id).toBe('123');
expect(fn('https://www.youtube.com/shorts/1234?i=4').id).toBe('1234');
expect(fn('https://youtube.com/shorts/123').service).toBe('youtube');
});

test('gets metadata from youtube shortcode formats', () => {
expect(fn('youtube://1234').id).toBe('1234');
expect(fn('https://youtu.be/ABC12302').id).toBe('ABC12302');
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "get-video-id",
"version": "3.4.3",
"version": "3.5.3",
"description": "Get the YouTube, Vimeo, Vine, Microsoft Steam, Dailymotion, TikTok or VideoPress video id from a url or embed string.",
"license": "MIT",
"repository": "radiovisual/get-video-id",
Expand Down Expand Up @@ -42,6 +42,7 @@
"microsoft",
"dailymotion",
"tiktok",
"shorts",
"stream",
"from",
"string",
Expand Down
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ http://y2u.be/*
youtube://
```

*YouTube Shorts**
```
https://youtube.com/shorts/*
https://www.youtube.com/shorts/*
```

**YouTube `/v/` or `/vi/`**
```
http://www.youtube.com/v/*
Expand Down
6 changes: 6 additions & 0 deletions src/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export default function youtube(youtubeString) {
return stripParameters(shortcodeid);
}

// Shorts
const shortsUrl = /\/shorts\//g;
if (shortsUrl.test(string_)) {
return stripParameters(string_.split(shortsUrl)[1]);
}

// /v/ or /vi/
const inlinev = /\/v\/|\/vi\//g;

Expand Down

0 comments on commit dd44528

Please sign in to comment.