added youtube shorts support

This commit is contained in:
TamilKannan-personal 2021-10-17 12:12:14 +05:30
parent 7fe4e612db
commit 18b2e7d5f8
1 changed files with 8 additions and 0 deletions

View File

@ -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;
}
}