Skip to content

Conversation

@maucel89
Copy link
Contributor

@maucel89 maucel89 commented Jul 1, 2025

Fix VimeoDLVideoExternalShortcutProvider because of some vimeo viedos don't work

In some case Vimeo share video has h parameter that is required to show the video.

So we get the correct URL from src attribute in HTML embed code.

… don't work

In some case Vimeo share video has h parameter that is required to show the video.
@ipeychev
Copy link
Contributor

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes an issue where some Vimeo videos would not work by extracting the full video URL from the embed code provided by the Vimeo API. This is a good approach to handle cases where extra parameters like h are required.

My review includes two suggestions for improvement:

  1. Add a fallback mechanism in renderHTML to handle cases where the video URL cannot be extracted from the embed code. This prevents a broken iframe from being rendered.
  2. Improve the regular expression for parsing the src attribute to make it more robust by handling both single and double quotes.

Overall, the change is a good fix, and with these improvements, it will be more robust.

Comment on lines +73 to +79
String src = _getSrcFromEmbedCode(
jsonObject.getString("html"));

return StringBundler.concat(
"<iframe allowfullscreen frameborder=\"0\" height=\"315\" ",
"mozallowfullscreen src=\"https://player.vimeo.com/video/",
vimeoVideoId, "\" webkitallowfullscreen ",
"width=\"560\"></iframe>");
"mozallowfullscreen src=\"", src,
"\" webkitallowfullscreen width=\"560\"></iframe>");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The _getSrcFromEmbedCode method can return an empty string if the regex fails to find a match in the HTML embed code from Vimeo. This would result in an <iframe> with an empty src attribute, causing a broken video embed. To make this more robust, you should add a fallback mechanism. If _getSrcFromEmbedCode returns a blank string, you can revert to the previous behavior of constructing the URL manually using vimeoVideoId. This ensures that a video is always displayed, even if parsing the embed code fails.

You will need to import com.liferay.portal.kernel.util.Validator.

                String src = _getSrcFromEmbedCode(
                    jsonObject.getString("html"));

                if (Validator.isBlank(src)) {
                    src = StringBundler.concat(
                        "https://player.vimeo.com/video/", vimeoVideoId);
                }

                return StringBundler.concat(
                    "<iframe allowfullscreen frameborder=\"0\" height=\"315\" ",
                    "mozallowfullscreen src=\"", src,
                    "\" webkitallowfullscreen width=\"560\"></iframe>");

Comment on lines +141 to +142
private static final Pattern _srcHtmlPattern = Pattern.compile(
"src\\s*=\\s*\"([^\"]*)\"");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current regex only matches src attributes with double quotes ("). While this might be sufficient for Vimeo's current API response, the HTML specification allows attributes to be enclosed in single quotes (') as well. To make the pattern more robust and future-proof, consider updating it to handle both single and double quotes.

	private static final Pattern _srcHtmlPattern = Pattern.compile(
		"src\\s*=\\s*[\"']([^\"']*)["']");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants