diff --git a/__tests__/youtube.test.js b/__tests__/youtube.test.js index b911574..769f98f 100644 --- a/__tests__/youtube.test.js +++ b/__tests__/youtube.test.js @@ -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? @@ -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'); diff --git a/package.json b/package.json index 0874115..f408d28 100644 --- a/package.json +++ b/package.json @@ -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", @@ -42,6 +42,7 @@ "microsoft", "dailymotion", "tiktok", + "shorts", "stream", "from", "string", diff --git a/readme.md b/readme.md index 56f8683..084340f 100644 --- a/readme.md +++ b/readme.md @@ -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/* diff --git a/src/youtube.js b/src/youtube.js index 7854250..30beb32 100644 --- a/src/youtube.js +++ b/src/youtube.js @@ -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;