Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(url-utils): Improve the YouTube URL regex
Browse files Browse the repository at this point in the history
mitsuki31 committed Aug 21, 2024
1 parent df963ae commit d72fc89
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/url-utils.js
Original file line number Diff line number Diff line change
@@ -115,11 +115,11 @@ URLUtils.VIDEO_ID_STRICT_REGEX = new RegExp(`^[A-Za-z0-9_-]{${URLUtils.MAX_ID_LE
* @see {@link module:url-utils~URLUtils.YTURL_WITH_ID_REGEX URLUtils.YTURL_WITH_ID_REGEX}
* @see {@link module:url-utils~URLUtils.BASIC_YOUTUBE_DOMAINS URLUtils.BASIC_YOUTUBE_DOMAINS}
*/
URLUtils.YTURL_REGEX = new RegExp(`https?:\\/\\/(${
URLUtils.YTURL_REGEX = new RegExp(`^https?:\\/\\/(${
URLUtils.BASIC_YOUTUBE_DOMAINS.reduce((acc, val) => {
val = val.replace(/\./g, '\\.');
acc += !(acc.length || 0) ? val : `|${val}`;
acc += (val !== 'youtu\\.be') ? '\\/watch\\?v=' : '\\/';
acc += (val !== 'youtu\\.be') ? '\\/watch\\?v=' : '\\/?';
return acc;
}, '')
})`);
@@ -134,7 +134,7 @@ URLUtils.YTURL_REGEX = new RegExp(`https?:\\/\\/(${
* @see {@link module:url-utils~URLUtils.BASIC_YOUTUBE_DOMAINS URLUtils.BASIC_YOUTUBE_DOMAINS}
*/
URLUtils.YTURL_WITH_ID_REGEX = new RegExp(
`${URLUtils.YTURL_REGEX.source}${URLUtils.VIDEO_ID_REGEX.source}`
`${URLUtils.YTURL_REGEX.source.replace(/\?\)$/, ')')}${URLUtils.VIDEO_ID_REGEX.source}`
);

/**

0 comments on commit d72fc89

Please sign in to comment.