From 18b2e7d5f800419375e227c089d331ed55b87e53 Mon Sep 17 00:00:00 2001 From: TamilKannan-personal Date: Sun, 17 Oct 2021 12:12:14 +0530 Subject: [PATCH] added youtube shorts support --- lib/src/videos/video_id.dart | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/src/videos/video_id.dart b/lib/src/videos/video_id.dart index 83b3fb2..5a7ba34 100644 --- a/lib/src/videos/video_id.dart +++ b/lib/src/videos/video_id.dart @@ -10,6 +10,8 @@ class VideoId with _$VideoId { static final _regMatchExp = RegExp(r'youtube\..+?/watch.*?v=(.*?)(?:&|/|$)'); static final _shortMatchExp = RegExp(r'youtu\.be/(.*?)(?:\?|&|/|$)'); static final _embedMatchExp = RegExp(r'youtube\..+?/embed/(.*?)(?:\?|&|/|$)'); + static final _shortsMatchExp = + RegExp(r'youtube\..+/shorts/([A-Za-z0-9-_]+$)'); /// Initializes an instance of [VideoId] with a url or video id. factory VideoId(String idOrUrl) { @@ -82,6 +84,12 @@ class VideoId with _$VideoId { if (!embedMatch.isNullOrWhiteSpace && validateVideoId(embedMatch!)) { return embedMatch; } + + // https://www.youtube.com/shorts/yIVRs6YSbOM + var shortsMatch = _shortsMatchExp.firstMatch(url)?.group(1); + if (!shortsMatch.isNullOrWhiteSpace && validateVideoId(shortsMatch!)) { + return shortsMatch; + } return null; } }