views:

36

answers:

2

I have a scenario where users can upload an image, OR a video (from youtube or vimeo) using CCK via ImageField (Images) & Embedded Media Field (Videos)

My site has been using the ImageField images to create thumbnails in various views with imagecache actions.

Youtube/vimeo provide an image capture of the video that I want to use as a "fallback" for the images.

Rather than rewriting each view to provide this fallback, and to keep everything consistent, I was wondering the best route to download and store the external video capture image as if the user uploaded it as an image WITH the video.

I'm familiar with Rules & Actions and PHP, any basic outline of what I should be doing is greaty appreciated.

+1  A: 

This would be part of a custom module. I am not aware of a module that handles this.

Such as module is not easy to write. If it has to perform (every site has to perform, right?) it would contain some sort of queue or spool mechanism, so it can process and download remote video in its own time. It might need an encoding street, if you want the video's in one, consistent format. It would need a lot of ugly hacks, for, after all, Youtube does not allow downloading their video's and will make it as hard as possible.

berkes
OTOH: you might want to have a look at Bluedroplet, it might be a very well matching alternative for your demands. http://bluedroplet.com/
berkes
+1  A: 

In hook_nodeapi($op == 'presave', ...) you can check if an image was provided and download it from youtube. A simple solution may be to use drupal_http_request() to download the file then file_save_data() to write it to disk. But this will load the file content in memory which shouldn't be needed. I think Curl can be used to directly download an HTTP file to disk.

Downloading the files when nodes are saved my be a performance issue (because it increase response time). In that case, you can delay it to an implementation of hook_cron. You can use the Job Queue to easily enqueue image download for next cron. If running during Drupal's cron is an issue, you can also try to use the Drupal Queue module to handle downloads separately.

mongolito404
Thanks mongolitho404, I think I'm going to run with this. I've created the function to populate the fid, just doing some research on the module function.The images coming from youtube/vimeo are small (14kb for example), should I really be concerned about performance on calling this function immediately as its saved rather than the cron job? Wouldn't it be close to the same performance hit as if this user uploaded their own (3-6mb) image?
askon
IMHO, downloading small files from a large website like youtube should'nt be a concern. Get the thing working first. Once it works, you can test and see if downloading the file a node creation is a performance issue and if it needs to be addressed.
mongolito404
Thanks again mongolitho404, this has really helped me, I've opened myself up to the module creation process and the nodeapi function isn't nearly as scary as I anticipated. I've got the thumbnails downloading and storing, just working on the database insert and update :)
askon

related questions