- Since:
- 1.1.0
- Source:
Members
(static, readonly) BASIC_YOUTUBE_DOMAINS :Readonly.<Array.<string>>
A list containing YouTube domains that basically most used for downloading.
Type:
- Readonly.<Array.<string>>
- Source:
- See:
-
URLUtils.VALID_YOUTUBE_DOMAINS
(static, readonly) MAX_ID_LENGTH :number
Maximum length of YouTube video ID.
According to YouTube API documentation V3, the videoId
is a string but
does not specified about the length of video IDs was used. However, communities
says that YouTube video IDs have:
- Exactly 11 characters.
- Allowed characters and symbols:
[A-Za-z0-9_-]
More details: https://webapps.stackexchange.com/a/101153
Type:
- number
- Default Value:
- 11
- Source:
(static, readonly) VALID_YOUTUBE_DOMAINS :Readonly.<Array.<string>>
A list containing valid known YouTube domains.
Type:
- Readonly.<Array.<string>>
- Source:
(static, readonly) VIDEO_ID_REGEX :RegExp
A regular expression for matching the YouTube video ID.
This regular expression will match exactly 11 characters and can be more.
If you want strictly parse the YouTube video ID, use
instead.VIDEO_ID_STRICT_REGEX
Type:
- RegExp
- Source:
- See:
-
URLUtils.VIDEO_ID_STRICT_REGEX
URLUtils.MAX_ID_LENGTH
(static, readonly) VIDEO_ID_STRICT_REGEX :RegExp
A regular expression for strictly matching the YouTube video ID.
Type:
- RegExp
- Source:
- See:
-
URLUtils.VIDEO_ID_REGEX
URLUtils.MAX_ID_LENGTH
(static, readonly) YTURL_REGEX :RegExp
A regular expression for matching the YouTube video (excluding video ID).
Type:
- RegExp
- Source:
- See:
-
URLUtils.YTURL_WITH_ID_REGEX
URLUtils.BASIC_YOUTUBE_DOMAINS
(static, readonly) YTURL_WITH_ID_REGEX :RegExp
A regular expression for matching the YouTube video.
Type:
- RegExp
- Source:
- See:
-
URLUtils.YTURL_REGEX
URLUtils.BASIC_YOUTUBE_DOMAINS
Methods
(static) extractVideoId(url) → {string}
Extracts the YouTube video ID from given YouTube URL.
The YouTube video ID have exactly 11 characters with allowed
symbols are A-Z
, a-z
, 0-9
, _
, and -
.
Allowed YouTube domains to extract:
www.youtube.com
m.youtube.com
youtube.com
youtu.be
music.youtube.com
Parameters:
Name | Type | Description |
---|---|---|
url |
string | URL | The URL to evaluate. |
- Source:
Throws:
-
-
If a given URL is not a string or
URL
object. - Type
- TypeError
-
-
-
If the host name of given URL is invalid YouTube domain.
- Type
- URIError
-
-
-
If the extractor unable to extract the video ID, this can be happen due to incorrect YouTube URL.
- Type
- IDExtractorError
-
Returns:
A string with 11 characters representing the video ID.
- Type
- string
(static) validateId(id) → {boolean}
Validates the given YouTube video ID.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The video ID to validate. |
- Source:
Returns:
true
if the given ID correctly represents
the YouTube video ID; otherwise false
.
- Type
- boolean
(static) validateUrl(url, withIdopt) → {boolean}
Validates the given YouTube URL and optionally validates its video ID.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
url |
string | URL | The YouTube URL to validate. |
||
withId |
boolean |
<optional> |
true | Whether to also validate the video ID within the URL.
If |
- Source:
Returns:
true
if the given URL is a valid YouTube URL; otherwise false
.
- Type
- boolean