Gallery2:Modules:embedvideo - Gallery Codex
Personal tools

Gallery2:Modules:embedvideo

From Gallery Codex

Embed Video Module

Description

A simple module that allows you to embed youtube, google video, or remove .flv video files via the "Add Items" interface for any album.


Overview

I was faced with a need to share Home Video Clips with family and friends all over the world. I don't have the internet bandwidth to stream these videos directly from my server at home where my Gallery2 installation resides. My only option was to host my Home Videos on sites outside my home, and embed them as items in my gallery album pages directly. Other posts suggested ways of doing this that involved pasting the embedded video player code directly in the description field of a photo item in gallery. This was tedious, and I was seeking a faster, more automated way, of adding video content in a similar fashion. This module attempts to automate that exact process.


The Nuts & Bolts

This module extends ItemAddPlugin. It takes, as input, a URL in the "Add Items" interface of Gallery to a youtube, googlevideo, or remote .flv file, and adds an embedded video object in a gallery item to that URL. It uses the youtube API to extract the title, description, and thumbnail for a youtube video URL. It also parses the raw HTML of the video page for google videos (since no google video API exists yet) to get this same information for those URLs.


External Dependencies / Patching Required

There are no additional external PHP library dependencies or .ini changes required, and no direct patches needed to the underlying Gallery2 framework for this module to function properly, with 1 patch exception if you want to edit the items after they are added to your albums. Because this module is still using the "embed videos via html in the description field of a gallery photo item", there is a patch that must be made to the modules/core/classes/GalleryUtilities.class if you want to edit the item after it has been added to your gallery. If you don't want to edit the item after it has been added to your gallery, no patch is required. The process of editing the item will remove the embedded markup in the description field if this patch is not made, and your site is not configured to allow for rawHTML in the description field. This gallery forum[1] post mentions the patch which consists of the following steps:

1) Comment out line 859 in modules/core/classes/GalleryUtilities.class like this: /* $html = $parser->parse($html); */

2) Make sure that "Site Admin -> General -> Embedded Markup" is set to "Raw HTML".

For versions 2.2.4 and later of gallery2, it has been reported that these modifications need to be made in order to get the video embedding to work at all (not just for editing/updating as in previous gallery2 versions).

The EmbedVideo module also relies on the "Thumbnail Manager" module for a default thumbnail to use for remote .flv or .swf files that can be added to the site. If you don't have this module installed, you will need to define a valid URL to a valid thumbnail to use for these types of links by setting the flvThumbnail variable in the module.


See it in Action

http://www.pippins.net/gallery2/v/development/


Installation

  • download Embedvideo.zip[2]
  • unzip to your Gallery2 modules directory
  • From the Site Admin -> Plugins page, you can install and activate it
  • To upgrade, follow the same steps above, but click upgrade on the Plugins page for it


Usage

  • Install and activate the module.
  • Site admin -> Import, there will be a new entry for Embed Video
  • Set the youtubeDevId if you are embedding youtube URLs
  • In any album, you can click "Add Items" and you'll see a new "Embed Video" tab
  • Enter the URL to the video you wish to embed


Supported VideoSites / FileTypes

  • Video Sites:
    • YouTube:http://www.youtube.com/watch?v=xxxxxxxxxxx
    • GoogleVideo: http://video.google.com/videoplay?docid=xxxxxxxxxxx
    • YahooVideo: http://video.yahoo.com/video/play?vid=xxxxxx
    • Metacafe: http://www.metacafe.com/watch/xxxxxx/xxxxxx
    • Revver: http://www.revver.com/watch/xxxxxx
    • Dailymotion: http://www.dailymotion.com/video/xxxxxxxxxxx
    • Divshare: http://www.divshare.com/download/xxxxxxxxx
    • Stickam: http://www.stickham.com/editMediaComment.do?method=load&mId=xxxxxxxxx
    • Myspace1: http://vids.myspace.com/index.cfm?fuseaction=vids.individual&VideoID=xxxxxxxx
    • Myspace2: http://myspacetv.com/index.cfm?fuseaction=vids.individual&videoid=xxxxxxxx
    • Vimeo: http://www.vimeo.com/xxxxxx
    • Animoto: http://www.animoto.com/play/xxxxxxxxxxxxxxxxxxxxxx
    • Generic: Any webpage with an '<object ... <embed ...' style video on its page
  • File Types:
    • FlashVideo (.flv): http://*/*.flv
    • FlashVideo (.swf): http://*/*.swf
    • Mpeg4 with an external FLV player (.mp4): http://*/*.mp4

What if it doesn't work, or I get an error?

Despite my best efforts to create bug free code, you may come across something that doesn't quite work right. If you can't get the module to work as advertised, or get an error you don't understand, the module has a built in debug mode that can help. Under your site admin, click on the "Embed Video" link, and add a parameter called "debugOutput" and set it to "true". Proceed to add the video URL that is giving you the trouble. The resulting webpage will be full of debug information about the process it underwent to add your video. Right click on the webpage that is shown in this debug mode, and save it as a local .html file on your system. Next, add it as a file attachment in a post you make to the message forum[3]. I will look at your attached html file, and get back to you with any insight I may have.


Code ToDos / Known Issues / Bugs

  • No thumbnails for remote .flv file URLs that are embedded
  • Cannot suppress the autostart of video.yahoo.com embedded videos
  • Cannot extract descriptions from the google video embedded videos


Drawbacks / Weaknesses

  • The requirement to patch the GalleryUtilities.class to allow for editing of these items
  • Overloading of the description field of a photo item with raw HTML to get all this to work properly


Requested Features

  • Discontinue the hack of using the description field in a Photo object to embed the videos. Create a new GalleryEmbeddedItem object that will naturally allow these objects to exist in gallery.
  • Add a feature to the Add Embed Video page that allows you to specify a youtube userID, and to fetch all the videos for that user, and list them on the page with their titles and thumbnails. Enable the Add Embed Video process to add multiple videos (as selected from this list) to Gallery2.
  • Add support for youtube playlist embedding (like http://uk.youtube.com/p/2D133BCB977E1A97). This is also described here: http://www.google.com/support/youtube/bin/answer.py?hl=th&answer=70458
  • Add support for youtube fullscreen playback option in the embedded youtube player.

Revision History

2007-06-12 - 1.0.0 - Initial Release

2007-06-23 - 1.0.1 - Fixed bug related to override parameters not trumping default parameters & youtube URL match being too restrictive.

2007-06-28 - 1.0.2 - Added remote file "does not exist check". Fixed google video title parsing bug. Added support for metacafe.com & video.yahoo.com. Added new useRemoteSize & autoStart parameters.

2007-07-01 - 1.0.3 - Added thumbnail resize capability for thumbnails used from remote video servers.

2007-07-09 - 1.0.4 - Fixed google video size issues. Improved debug output.

2007-08-30 - 1.0.5 - Added support for .swf file types. Added parameter to control disabling/enabling youtube embedded related videos. Improved thumbnail sizing logic.

2007-10-31 - 1.0.6 - Added support for watermarking the thumbnails of the embedded videos

2007-11-17 - 1.0.7 - Added support for adding revver, dailymotion, and divshare embedded videos. Added support for adding youtube embedded videos without a youtube developer ID. Fixed default watermark alignment.

2007-11-28 - 1.0.8 - Added support for StickAm and Myspace embedded videos. Added new wordwrap parameters for summaries and descriptions.

2008-04-17 - 1.0.9 - Added support for high quality youtube video urls. Updated dailymotion parsing algorithms. Added support for adding vimeo.com videos. Added support for new youtube API (GDATA) and deprecated youtubeDevId entry.

2008-05-28 - 1.1.0 - Fixed google video thumbnail parsing algorithm. Added support for generic site embed video content.

2008-09-13 - 1.1.1 - Added ".mp4" type to supported remote embedded types. Added support for "youtube.com/v/" style video URLs. Fixed myspace video parsing algorithm.

2008-09-23 - 1.1.2 - Loosened URL pattern matching, dropping "www." and ".com" expectations. Fixed stickam and vimeo video parsing algorithms.

2009-02-01 - 1.1.3 - Fixed google video thumbnail parsing algorithm. Added code to remove trailing whitespace from url.

2009-06-17 - 1.1.4 - Fixed dailymotion parsing algorithm. Added new allowFullScreen youtube parameter. Fixed google video thumbnail parsing algorithm.

2009-10-13 - 1.1.5 - Added support for Animoto embedded videos. Added new centerVideo parameter.

2010-10-02 - 1.1.6 - Fixed vimeo and dailymotion embedded video parsing algorithms. Added urlencode to youtube api feed.