-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,11 +69,14 @@ public String getURL() { | |
|
|
||
| @Override | ||
| public String renderHTML(HttpServletRequest httpServletRequest) { | ||
|
|
||
| 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>"); | ||
| } | ||
|
|
||
| }; | ||
|
|
@@ -110,6 +113,16 @@ private JSONObject _getEmbedJSONObject(String url) { | |
| } | ||
| } | ||
|
|
||
| private String _getSrcFromEmbedCode(String html) { | ||
| Matcher matcher = _srcHtmlPattern.matcher(html); | ||
|
|
||
| if (matcher.find()) { | ||
| return matcher.group(1); | ||
| } | ||
|
|
||
| return StringPool.BLANK; | ||
| } | ||
|
|
||
| private String _getVimeoVideoId(String url) { | ||
| for (Pattern urlPattern : _urlPatterns) { | ||
| Matcher matcher = urlPattern.matcher(url); | ||
|
|
@@ -125,6 +138,9 @@ private String _getVimeoVideoId(String url) { | |
| private static final Log _log = LogFactoryUtil.getLog( | ||
| VimeoDLVideoExternalShortcutProvider.class); | ||
|
|
||
| private static final Pattern _srcHtmlPattern = Pattern.compile( | ||
| "src\\s*=\\s*\"([^\"]*)\""); | ||
|
Comment on lines
+141
to
+142
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current regex only matches private static final Pattern _srcHtmlPattern = Pattern.compile(
"src\\s*=\\s*[\"']([^\"']*)["']"); |
||
|
|
||
| private static final List<Pattern> _urlPatterns = Arrays.asList( | ||
| Pattern.compile( | ||
| "https?:\\/\\/(?:www\\.)?vimeo\\.com\\/album\\/.*\\/video" + | ||
|
|
@@ -146,4 +162,4 @@ private String _getVimeoVideoId(String url) { | |
| @Reference | ||
| private JSONFactory _jsonFactory; | ||
|
|
||
| } | ||
| } | ||
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
_getSrcFromEmbedCodemethod 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 emptysrcattribute, causing a broken video embed. To make this more robust, you should add a fallback mechanism. If_getSrcFromEmbedCodereturns a blank string, you can revert to the previous behavior of constructing the URL manually usingvimeoVideoId. 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.