-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix to import Vimeo videos #8804
Changes from all commits
4faaa44
28512e4
7b5c594
4b3bc0d
b89810a
0b76c0e
f6e1983
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 | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -82,26 +82,54 @@ public ActionResult IndexPOST(string folderPath, string url, string type, string | |||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||
// <link rel="alternate" href="http://vimeo.com/api/oembed.xml?url=http%3A%2F%2Fvimeo.com%2F23608259" type="text/xml+oembed"> | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
var source = webClient.DownloadString(url); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// seek type="text/xml+oembed" or application/xml+oembed | ||||||||||||||||||||||||||||||||||||
var oembedSignature = source.IndexOf("type=\"text/xml+oembed\"", StringComparison.OrdinalIgnoreCase); | ||||||||||||||||||||||||||||||||||||
if (oembedSignature == -1) { | ||||||||||||||||||||||||||||||||||||
oembedSignature = source.IndexOf("type=\"application/xml+oembed\"", StringComparison.OrdinalIgnoreCase); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
if (oembedSignature != -1) { | ||||||||||||||||||||||||||||||||||||
var tagStart = source.Substring(0, oembedSignature).LastIndexOf('<'); | ||||||||||||||||||||||||||||||||||||
var tagEnd = source.IndexOf('>', oembedSignature); | ||||||||||||||||||||||||||||||||||||
var tag = source.Substring(tagStart, tagEnd - tagStart); | ||||||||||||||||||||||||||||||||||||
var matches = new Regex("href=\"([^\"]+)\"").Matches(tag); | ||||||||||||||||||||||||||||||||||||
if (matches.Count > 0) { | ||||||||||||||||||||||||||||||||||||
var href = matches[0].Groups[1].Value; | ||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||
var content = webClient.DownloadString(Server.HtmlDecode(href)); | ||||||||||||||||||||||||||||||||||||
viewModel.Content = XDocument.Parse(content); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
catch { | ||||||||||||||||||||||||||||||||||||
// bubble exception | ||||||||||||||||||||||||||||||||||||
var source = ""; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Get the proper uri the provider redirects to | ||||||||||||||||||||||||||||||||||||
var uri = GetRedirectUri(url); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Vimeo doesn't consent anymore the scraping of web pages, so the direct api call has to be enforced. | ||||||||||||||||||||||||||||||||||||
// In this case, the downloaded string is already the expected xml, in the format that needs to be parsed. | ||||||||||||||||||||||||||||||||||||
// Legacy process is done for non-Vimeo content. | ||||||||||||||||||||||||||||||||||||
// First of all, url domain is checked. | ||||||||||||||||||||||||||||||||||||
var vimeo = uri.Host.Equals("vimeo.com", StringComparison.OrdinalIgnoreCase); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Youtube changed the markup of the page of its videos, so the direct api call has to be enforced | ||||||||||||||||||||||||||||||||||||
// Api url is built based on the requested video | ||||||||||||||||||||||||||||||||||||
var youtube = uri.Host.Equals("www.youtube.com", StringComparison.OrdinalIgnoreCase); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
if (vimeo) { | ||||||||||||||||||||||||||||||||||||
// Add api url to original url provided as a parameter | ||||||||||||||||||||||||||||||||||||
url = "https://" + uri.Host + "/api/oembed.xml?url=" + url; | ||||||||||||||||||||||||||||||||||||
source = webClient.DownloadString(url); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
viewModel.Content = XDocument.Parse(source); | ||||||||||||||||||||||||||||||||||||
} else if (youtube) { | ||||||||||||||||||||||||||||||||||||
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||
// Add api url to original url provided as a parameter | ||||||||||||||||||||||||||||||||||||
url = "https://" + uri.Host + "/oembed?format=xml&url=" + url; | ||||||||||||||||||||||||||||||||||||
source = webClient.DownloadString(url); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
viewModel.Content = XDocument.Parse(source); | ||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||
source = webClient.DownloadString(url); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// seek type="text/xml+oembed" or application/xml+oembed | ||||||||||||||||||||||||||||||||||||
var oembedSignature = source.IndexOf("type=\"text/xml+oembed\"", StringComparison.OrdinalIgnoreCase); | ||||||||||||||||||||||||||||||||||||
if (oembedSignature == -1) { | ||||||||||||||||||||||||||||||||||||
oembedSignature = source.IndexOf("type=\"application/xml+oembed\"", StringComparison.OrdinalIgnoreCase); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
if (oembedSignature != -1) { | ||||||||||||||||||||||||||||||||||||
var tagStart = source.Substring(0, oembedSignature).LastIndexOf('<'); | ||||||||||||||||||||||||||||||||||||
var tagEnd = source.IndexOf('>', oembedSignature); | ||||||||||||||||||||||||||||||||||||
var tag = source.Substring(tagStart, tagEnd - tagStart); | ||||||||||||||||||||||||||||||||||||
var matches = new Regex("href=\"([^\"]+)\"").Matches(tag); | ||||||||||||||||||||||||||||||||||||
if (matches.Count > 0) { | ||||||||||||||||||||||||||||||||||||
var href = matches[0].Groups[1].Value; | ||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||
var content = webClient.DownloadString(Server.HtmlDecode(href)); | ||||||||||||||||||||||||||||||||||||
viewModel.Content = XDocument.Parse(content); | ||||||||||||||||||||||||||||||||||||
} catch { | ||||||||||||||||||||||||||||||||||||
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||
// bubble exception | ||||||||||||||||||||||||||||||||||||
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
@@ -137,8 +165,7 @@ public ActionResult IndexPOST(string folderPath, string url, string type, string | |||||||||||||||||||||||||||||||||||
root.El("description", description); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
Response.AddHeader("X-XSS-Protection", "0"); // Prevents Chrome from freaking out over embedded preview | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
catch { | ||||||||||||||||||||||||||||||||||||
} catch { | ||||||||||||||||||||||||||||||||||||
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||
return View(viewModel); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
@@ -167,8 +194,7 @@ public ActionResult Import(string folderPath, string url, string document) { | |||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
if (oembed.Element("title") != null) { | ||||||||||||||||||||||||||||||||||||
part.Title = oembed.Element("title").Value; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
else { | ||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||
part.Title = oembed.Element("url").Value; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
if (oembed.Element("description") != null) { | ||||||||||||||||||||||||||||||||||||
|
@@ -203,7 +229,7 @@ public ActionResult Replace(int replaceId, string url, string document) { | |||||||||||||||||||||||||||||||||||
return HttpNotFound(); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Check permission | ||||||||||||||||||||||||||||||||||||
if (!(_mediaLibraryService.CheckMediaFolderPermission(Permissions.EditMediaContent, replaceMedia.FolderPath) && _mediaLibraryService.CheckMediaFolderPermission(Permissions.ImportMediaContent, replaceMedia.FolderPath)) | ||||||||||||||||||||||||||||||||||||
if (!(_mediaLibraryService.CheckMediaFolderPermission(Permissions.EditMediaContent, replaceMedia.FolderPath) && _mediaLibraryService.CheckMediaFolderPermission(Permissions.ImportMediaContent, replaceMedia.FolderPath)) | ||||||||||||||||||||||||||||||||||||
&& !_mediaLibraryService.CanManageMediaFolder(replaceMedia.FolderPath)) { | ||||||||||||||||||||||||||||||||||||
return new HttpUnauthorizedResult(); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
@@ -213,8 +239,7 @@ public ActionResult Replace(int replaceId, string url, string document) { | |||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
if (oembed.Element("title") != null) { | ||||||||||||||||||||||||||||||||||||
replaceMedia.Title = oembed.Element("title").Value; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
else { | ||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||
replaceMedia.Title = oembed.Element("url").Value; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
if (oembed.Element("description") != null) { | ||||||||||||||||||||||||||||||||||||
|
@@ -238,5 +263,22 @@ public ActionResult Replace(int replaceId, string url, string document) { | |||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
return RedirectToAction("Index", new { folderPath = replaceMedia.FolderPath, replaceId = replaceMedia.Id }); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
private Uri GetRedirectUri(string url) { | ||||||||||||||||||||||||||||||||||||
Uri myUri = new Uri(url); | ||||||||||||||||||||||||||||||||||||
// Create a 'HttpWebRequest' object for the specified url. | ||||||||||||||||||||||||||||||||||||
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(myUri); | ||||||||||||||||||||||||||||||||||||
// Send the request and wait for response. | ||||||||||||||||||||||||||||||||||||
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
if (!myUri.Equals(myHttpWebResponse.ResponseUri)) { | ||||||||||||||||||||||||||||||||||||
myUri = myHttpWebResponse.ResponseUri; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Release resources of response object. | ||||||||||||||||||||||||||||||||||||
myHttpWebResponse.Close(); | ||||||||||||||||||||||||||||||||||||
Comment on lines
+270
to
+279
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
return myUri; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} |
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.