Skip to content

Commit

Permalink
feat: optimize regex to match more cases like shorts (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fahl-Design authored Aug 30, 2024
1 parent 19e6014 commit 4dff99b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions public/js/pimcore/object/tags/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,13 @@ pimcore.object.tags.video = Class.create(pimcore.object.tags.abstract, {
var match, regExp;

if (values["type"] == "youtube") {
regExp = /^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
match = values["data"].match(regExp);
if (match && match[2].length == 11) {
values["data"] = match[2];
// https://gist.github.com/afeld/1254889
const ytRegex = /^(?:https?:\/\/|\/\/)?(?:www\.|m\.|.+\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|shorts\/|feeds\/api\/videos\/|watch\?v=|watch\?.+&v=))(?<videoId>[\w-]{11})(?![\w-])/g;
match = values["data"].matchAll(ytRegex);
let matches = [...match]
let videoIds = Array.from(matches, m => m[1]);
if (videoIds && (videoIds[0] ?? null)) {
values["data"] = videoIds[0];
}
} else if (values["type"] == "vimeo") {
regExp = /vimeo.com\/(\d+)($|\/)/;
Expand Down

0 comments on commit 4dff99b

Please sign in to comment.