added youtube shorts support
This commit is contained in:
parent
7fe4e612db
commit
18b2e7d5f8
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue