blob: 95d30310483cada613166bd28cd8f2614303bbac (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package utils;
class YoutubeUtils {
static final matchId = ~/youtube\.com.*v=([A-z0-9_-]+)/;
static final matchShort = ~/youtu\.be\/([A-z0-9_-]+)/;
static final matchShorts = ~/youtube\.com\/shorts\/([A-z0-9_-]+)/;
static final matchEmbed = ~/youtube\.com\/embed\/([A-z0-9_-]+)/;
static final matchPlaylist = ~/youtube\.com.*list=([A-z0-9_-]+)/;
public static function extractVideoId(url:String):String {
if (matchId.match(url)) {
return matchId.matched(1);
}
if (matchShort.match(url)) {
return matchShort.matched(1);
}
if (matchShorts.match(url)) {
return matchShorts.matched(1);
}
if (matchEmbed.match(url)) {
return matchEmbed.matched(1);
}
return "";
}
public static function extractPlaylistId(url:String):String {
if (!matchPlaylist.match(url)) return "";
return matchPlaylist.matched(1);
}
}
|