Hi everybody.
I had a case with a client, who copy pasted partial url's of vimeo videos, and because we were using fckeditor they would not see the broken video inside it. Although they could click "view source" and remove the code from there, they requested us a better solution.
The only thing i could came up with was to test if the id found using preg_match inside MediaInternetVimeoHandler's function "parse" was that of a valid video. For this I used the Vimeo Developers / Simple API, using the API call "Making a Video Request" - documentation here: http://vimeo.com/api/docs/simple-api#video . I then test if the response XML contains the video ID, or not (data is returned only for valid videos, even videos that were deleted make this call return nothing). If not I do not add the video to the library, and also throw a MediaInternetValidationException about the invalid ID.
I think this is a useful functionality, and could be included in the module, so I am attaching the patch here.
It is against 7.x-dev.
I also created a similar patch for media_youtube, the related issue is here: #1292344: Validate the youtube ID before adding to the library
Comments
Comment #1
mikeytown2 commentedI've been having issues with the regex as well.
Comment #2
noslokire commentedPatch works for me, thanks
Comment #3
drewish commentedI guess my patch at #1497108: Support more Vimeo URL formats overlaps with this. I think having an idValid function makes sense but it should be static since it takes the id as a parameter and doesn't rely on the class's state.
Comment #4
drewish commentedOkay so #1497108: Support more Vimeo URL formats got committed. I think it might make sense to look at validating the ids too but this will need a re-roll.
Comment #5
mikeytown2 commentedCurrently using the Simple API: http://vimeo.com/api/docs/simple-api
We could go for php or json instead of XML (so we don't have to use simplexml_load_file()). In any case here is the patch re-rolled currently using XML.
Format comparisons:
http://vimeo.com/api/v2/video/39078923.xml
http://vimeo.com/api/v2/video/39078923.php
http://vimeo.com/api/v2/video/39078923.json
Comment #6
drewish commentedYeah I'd prefer JSON since we could avoid this issue #1180386: Use of copy() and simplexml_load_file() rather than drupal_http_request() causes Media:YouTube thumbnails to be empty but the is_valid function almost exactly mirrors MediaVimeoStreamWrapper::getVideoProperties() I think it might make sense to just use that for checking ids.
Comment #7
mikeytown2 commentedYou mean this issue? #1504050: Use drupal_http_request() instead of of copy() and simplexml_load_file(), or else Media:Vimeo thumbnails may be empty
Comment #8
drewish commentedYeah the point being use drupal_http_request() to fetch the URLs rather than loading them directly in simplexml_load_file()... but that's really academic since we should be using the existing function that does the request in that manner.
Comment #9
RobW commentedWe decided on a solution for Media: YouTube, and can refactor that code to work here:
Comment #9.0
RobW commentedChanged link into [#] d.o issue.
Comment #10
devin carlson commentedA patch to add a validId() method similar to the one used by Media: YouTube.
Comment #11
devin carlson commentedTested #10 with a variety of deleted/invalid videos and verified that users were successfully warned.
Committed #10 to Media: Vimeo 7.x-2.x.