Merge pull request #178 from TamilKannanCV-personal/master

added youtube shorts support
This commit is contained in:
Mattia 2021-10-19 23:36:44 +02:00 committed by GitHub
commit f1c1d465c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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;
}
}