Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top