-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Fix VimeoDLVideoExternalShortcutProvider some vimeo viedos don't work #6326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix VimeoDLVideoExternalShortcutProvider some vimeo viedos don't work #6326
Conversation
… don't work In some case Vimeo share video has h parameter that is required to show the video.
|
/gemini review |
There was a problem hiding this 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:
- Add a fallback mechanism in
renderHTMLto handle cases where the video URL cannot be extracted from the embed code. This prevents a broken iframe from being rendered. - Improve the regular expression for parsing the
srcattribute 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.
| 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>"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>");| private static final Pattern _srcHtmlPattern = Pattern.compile( | ||
| "src\\s*=\\s*\"([^\"]*)\""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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*[\"']([^\"']*)["']");
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.