Module: Embedded Youtube Videos

Nerull

Joined: 2010-08-24
Posts: 10
Posted: Tue, 2010-08-24 06:29

I wanted to have videos in a gallery, but don't really have the server for direct hosting. This is my first gallery module, and I wrote it in one night. It's very, very alpha, but it works well enough for my needs.

I found that when you access an items page, gallery will try to call the controller in modules/gallery/controller rather than the module's directory, so in order to get this working you will need to create a symlink from modules/gallery/controller/embeds.php to modules/embed/controller/embeds.php

I also had to replace the Item model, which is not ideal since it won't track changes the gallery item model, but I couldn't think of a better way to accomplish this. More abstraction in the Item code would help to solve this problem, but that's a bit beyond what I set out to do.

The module adds an entry to the 'Add' menu, and takes Youtube video IDs - the 11-character string after v= in youtube URLs. The video ID for http://www.youtube.com/watch?v=MQCNuv2QxQY is MQCNuv2QxQY, for example.

This was developed against the latest code in git, and will probably not work with rc2 due to the JSON changes.

[old code removed]

 
Nerull

Joined: 2010-08-24
Posts: 10
Posted: Thu, 2010-08-26 21:14

I've been working on rewriting this to remove the need to replace any models, and add support for more video sites, but every idea I try hits a roadblock.

At the moment I've got the basics working, except thumbnails. To show up in albums, embedded videos go in the items table like everything else, but with a different type. By switching the type after saving, I've got past validation and saving on the item model, but I can't find way around thumbnail URLs without trying a completely different approach.

The fix is to simply add a default type to the thumb_url and thumb_path functions, but I don't want to replace the entire item controller just to do this.

Does anyone have any ideas?

Latest codebase is at http://github.com/bowlesjd/gallery3-contrib/tree/master/modules/embed_videos/

 
Nerull

Joined: 2010-08-24
Posts: 10
Posted: Fri, 2010-08-27 06:09

Solved. I happened to look at the exif module and realized I could use a theme helper to conditionally insert code into the photo view. I now store embedded videos as a regular photo, all gallery code sees it no differently, and no Gallery code is replaced. When the photo view is loaded, the current Item is checked for a matching Embedded_Video model, and if found, a jQuery script is inserted to replace the photo with the video embed code.

I have also written it so as to support video sites other than youtube, and decode full URLs rather than just the video ID. I have not yet implemented any other sites, but it shouldn't require any API changes. I'll put a demo up in a few minutes. I think this is ready to be pulled into gallery_contrib.

 
Nerull

Joined: 2010-08-24
Posts: 10
Posted: Fri, 2010-08-27 06:50
 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Sun, 2010-08-29 04:18

Nice! Great work, Nerull. Should I pull this into the main gallery3-contrib repository now?
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Sun, 2010-08-29 17:23

Nerull,
Let me know if you need a hand creating a codex page for documentaion of you module.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
Nerull

Joined: 2010-08-24
Posts: 10
Posted: Tue, 2010-08-31 20:04

Yeah, it's ready to be pulled, I think.

 
anselm13

Joined: 2010-09-01
Posts: 6
Posted: Wed, 2010-09-01 16:46

Nerull, are you thinking of including support for Vimeo?
Thanks

 
Nerull

Joined: 2010-08-24
Posts: 10
Posted: Wed, 2010-09-01 20:14

Vimeo shouldn't be a problem. I'll look into it.

 
Nerull

Joined: 2010-08-24
Posts: 10
Posted: Wed, 2010-09-01 20:50

Added Vimeo support, sent pull request.

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Thu, 2010-09-02 04:29

Pulled!
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git

 
anselm13

Joined: 2010-09-01
Posts: 6
Posted: Thu, 2010-09-02 12:15

Thanks Nerull! It looks like when I embed both youtube and vimeo now, I just get the first image from the video. Gallery treats it as an image and just enlarges it with lightbox when I click it.

 
Nerull

Joined: 2010-08-24
Posts: 10
Posted: Thu, 2010-09-02 17:33

Could you post the html of the image page? I just tested it on a fresh install and it works here.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Sun, 2010-09-05 01:30

Since there was no grab for documentation I am going to do it.
I have downloaded and installed the module. Every time I try to add a video using the example I get
[img]http://gallery.menalto.com/files/invalid_URL.png[/img]

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
Shemo725

Joined: 2008-04-18
Posts: 424
Posted: Mon, 2010-09-06 07:22

@ Floridave...you're only supposed to add the text after the v=

"The module adds an entry to the 'Add' menu, and takes Youtube video IDs - the 11-character string after v= in youtube URLs. The video ID for http://www.youtube.com/watch?v=MQCNuv2QxQY is MQCNuv2QxQY, for example."

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Mon, 2010-09-06 16:23

I did try that as well. Still the same error; invalid URL.
[img]http://gallery.menalto.com/files/youtubeID.png[/img]

A suggestions would be to not call it a video URL but some thing else then since it is not a URL.

Dave

_____________________________________________
Blog & G2 || floridave - Gallery Team

 
rlparadise

Joined: 2009-12-27
Posts: 65
Posted: Wed, 2010-09-08 17:57

I was able to reproduce this problem briefly last night on a clean install of the latest GIT code and the latest embed_videos code. It would appear from the code that the intent is now to specify the full URL (i.e. youtube.com or vimeo.com).

After a couple of attempts to embed, I started to see if I could debug the php code. When I got my debug hooks in place, I reran the embed code and it worked. So, my guess is that it has something to do with the initial install or embedvideo database table setup. I didn't have time to get any further. That said, once I got one video to embed I could not get the problem to occur again.

@anselm13, the only way I could reproduce the problem you experienced was to deactivate the module. The images/thumbnails persist from the embedded youtube video but the hooks in place to replace with the embed video code is no longer active (so G3 handles it). Seems like valid behavior to me...

I'll let you know if I can pinpoint the cause of the invalid url issue.

 
anselm13

Joined: 2010-09-01
Posts: 6
Posted: Thu, 2010-09-09 01:29

I isolated the problem to the xmp module (http://kott.fm/tomek/plugins-extensions/module-xmp/). When xmp is enabled when I embed a video, the photo is not replaced with the video. When xmp is disabled when I embed a video, it works.

Incidentally, I also have an issue right after the embed where the window remains and things appear to have hung. I cancel out the window and then refresh the browser and the video appears. So everything works, just get this issue and that behavior appears on a clean install with no other additional modules enabled.

 
SexDrugsOverclocking

Joined: 2010-09-06
Posts: 10
Posted: Thu, 2010-09-09 11:42

I am hoping you can help me. I am running Gallery 3.0 RC2 and everything is working OK now. I decided to do Video's and when trying this module I cannot get it to work.

When I go to add a video, I put in the information CORRECTLY however every time I click add I get a pop up and the button cannot be clicked.

I added a screen shot to show what I am talking about. When this pop up shows, when I put my cursor over the "Add embeded videos on x" I get the 4 arrow cursor and the button IS NOT clickable.

Any ideas?

 
anselm13

Joined: 2010-09-01
Posts: 6
Posted: Thu, 2010-09-09 20:24

I get that too if I only enter the youtube video ID in the Video URL field. If I add the full youtube URL, then the embedded video gets added (though I have to press cancel and refresh the browser).

 
Nerull

Joined: 2010-08-24
Posts: 10
Posted: Mon, 2010-09-13 19:13

The module definitely needs some better error handling, however using it with RC2 is unlikely to work, due to the JSON changes. The module was developed against the Git version.

 
anselm13

Joined: 2010-09-01
Posts: 6
Posted: Tue, 2010-09-14 16:29

I no longer have the issues now that I've upgraded to the g3 git version. Still have issue with xmp incompatibility, though disabling it during the embed and then re-enabling afterword works.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Tue, 2010-11-02 01:36

I am still unable to add a video form youtube with this ID/URL:
MQCNuv2QxQY
or this one:
[img]http://gallery.menalto.com/files/youtubeID.png[/img]

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
Shemo725

Joined: 2008-04-18
Posts: 424
Posted: Wed, 2010-11-03 20:38

Dave..try the entire url.

I tried this, as rlparadise pointed out, and it worked.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Wed, 2010-11-03 23:29

I have tried:
http://www.youtube.com/watch?v=MQCNuv2QxQY
www.youtube.com/watch?v=MQCNuv2QxQY
youtube.com/watch?v=MQCNuv2QxQY
MQCNuv2QxQY
and many other combos Still get invalid.url error.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
daveman

Joined: 2009-10-09
Posts: 25
Posted: Fri, 2010-11-05 01:09

I still can not get it to work

 
gertie

Joined: 2009-10-23
Posts: 2
Posted: Fri, 2011-01-07 03:39

I'm going to chime in with a "me too" here as I've not seen any additional commentary on either changes to this module or possible fixes.

I'm getting the exact same error as Dave and have tried all variations on a YouTube embed URL with different files, and have always gotten the "invalid URL" error. I even tried a completely blank install with the latest experimental versions of everything (newly created database, embedded video as first thing I tried to add, etc.) and still error.

Is there an undocumented dependency, a SQL trick to remove and re-install the database tables needed, anything someone has found to make this thing work?

I'm only using Gallery for a small, .htaccess protected site for family but someone was featured in a recent news story and it would be nice to embed the video.

Thanks!

floridave wrote:
I have tried:
http://www.youtube.com/watch?v=MQCNuv2QxQY
www.youtube.com/watch?v=MQCNuv2QxQY
youtube.com/watch?v=MQCNuv2QxQY
MQCNuv2QxQY
and many other combos Still get invalid.url error.

Dave

_____________________________________________
gertie. not a dev. good at breaking things. sometimes clever enough to fix them.

 
phurt74

Joined: 2010-09-07
Posts: 1
Posted: Wed, 2011-01-19 06:42

Is there any resolution to this, I get the same issue below, please help.

gertie wrote:
I'm going to chime in with a "me too" here as I've not seen any additional commentary on either changes to this module or possible fixes.

I'm getting the exact same error as Dave and have tried all variations on a YouTube embed URL with different files, and have always gotten the "invalid URL" error. I even tried a completely blank install with the latest experimental versions of everything (newly created database, embedded video as first thing I tried to add, etc.) and still error.

Is there an undocumented dependency, a SQL trick to remove and re-install the database tables needed, anything someone has found to make this thing work?

I'm only using Gallery for a small, .htaccess protected site for family but someone was featured in a recent news story and it would be nice to embed the video.

Thanks!

floridave wrote:
I have tried:
http://www.youtube.com/watch?v=MQCNuv2QxQY
www.youtube.com/watch?v=MQCNuv2QxQY
youtube.com/watch?v=MQCNuv2QxQY
MQCNuv2QxQY
and many other combos Still get invalid.url error.

Dave

_____________________________________________
gertie. not a dev. good at breaking things. sometimes clever enough to fix them.

 
fatcatfan

Joined: 2011-01-24
Posts: 7
Posted: Thu, 2011-01-27 20:55
anselm13 wrote:
Thanks Nerull! It looks like when I embed both youtube and vimeo now, I just get the first image from the video. Gallery treats it as an image and just enlarges it with lightbox when I click it.

I was experiencing this as well. Changing embed_videos_theme.php to put embed_video_js.html in the footer instead of the header fixed it. In a default G3.0.1 install with embed_videos added from git, the script is put in the header before jQuery is loaded, I think. I'm not 100% sure on the internals, but Firefox error console was showing a "$" is not defined error, which went away once the script was placed in the footer.

 
henriemedia

Joined: 2011-02-02
Posts: 29
Posted: Wed, 2011-02-09 01:01

fatcatfan, I am getting the same error in Firefox, but I am not sure how to change the embed_videos_theme.php to put the embed_video_js.html in footer instead of the header. Can you give me a little more details so I can fix this error. Thank you.

 
henriemedia

Joined: 2011-02-02
Posts: 29
Posted: Wed, 2011-02-09 01:21

Nevermind. I got it. Changed "static function head($theme)" to "static function footer($theme)". Thank you.

 
dreamernyc

Joined: 2010-11-09
Posts: 30
Posted: Fri, 2011-02-18 14:53

Guys, Thank you.. I also was able to change the:
"static function head($theme)" to "static function footer($theme)" in /helpers folder file: embed_videos_theme in the embed_videos module.

1. Is there a way to remove that video icon that gets attached to the Generated Thumbnail.
2. Is it possible to change the Thumbnail Image:
a. with my own image that I would grab from video,
b. add a slider in the video, to point and create a snapshot at that specific moment.

 
dreamernyc

Joined: 2010-11-09
Posts: 30
Posted: Fri, 2011-02-18 14:55

What is the difference between "Video URL" and "Internet Access" on the Menu? Do we need to fill in both?

 
chris88

Joined: 2011-01-28
Posts: 10
Posted: Sun, 2011-02-27 20:53
dreamernyc wrote:
What is the difference between "Video URL" and "Internet Access" on the Menu? Do we need to fill in both?

To the best of my knowledge, the "Video URL" is the actual URL of the video (the "embed URL"). The "Internet Address" is internal to Gallery - simply how you'd like the embedded video page to look in YOUR URL. For example: http://www.example.com/MyVideoAlbum/MyVideo/ - "MyVideo" would be the "Internet Address" in the previous example.

 
chris88

Joined: 2011-01-28
Posts: 10
Posted: Sun, 2011-02-27 21:13

For what it's worth, I was finally able to get this module working with Vimeo. I'm by no means a programmer, developer, or anything like that - so take this with a grain of salt. I downloaded what I think was the latest version of this module from GitHub. Initially, I was getting the "Invalid URL" message referenced above. Taking a quick look at the relevant code, I modified line 80 of /controllers/embedded_videos.php to this:

if(preg_match("/(\d+)/",$url,$matches)) {

Which seems to work with Vimeo videos. The previous code was apparently returning more than just the video ID (/video/video_id_number). The regex above, I think, will just return any numbers in the URL, which in the case if Vimeo, I think would be limited to the video ID. So, I'm now able to embed my Vimeo videos - the proper dimensions are applied, the title, description, and a thumbnail are all generated.

One potential problem I'm having now - as a "Vimeo Plus" user - I'd like to set my videos to "Hide my videos from vimeo.com" and limit the embedding of videos to my domain only. Changing this setting appears to effect the "Simple API"'s ability to pull information about the video though. Line 83 of the aforementioned file: $sxml = simplexml_load_file("http://vimeo.com/api/v2/video/$video_id.xml"); - returns an empty XML file when the video permissions are set to private on Vimeo. I suspect the solution is a bit complex, and involves OAuth and the "Advanced" Vimeo API.

Anyway, I'm happy for now. I've got my HD videos embedded in my gallery, so that's a start.

 
rpenberthy

Joined: 2011-04-29
Posts: 1
Posted: Fri, 2011-04-29 06:10

To dreamernyc and everyone else that has been trying to figure out how to do away with the Film Strip icon or to replace it with one of your own...

I haven't found where in the code it is creating the thumbnail with the film strip, but the film strip icon comes from the embed_videos/images/embed_video_icon.png. Simply pull the file into a program like Photoshop and turn it into a pure transparent image. Or, if you want it to look different, modify it and save it.

I tried renaming the file to solve this, but the script is looking for this file. So, the only way around it that I've found is to give it a file with that name but containing the image you want.

No offense to the creator of this wonderful module (I'm on godaddy so I don't have any other option than videos hosted elsewhere), but I just didn't like the film strip icon pasted right over my video thumbnail.

Dream, using the same approach I took with the film strip icon, to change the thumbnail pulled for the video... you could provide it with an image of the same name. Though I haven't tried it you would most likely need to make sure it's the same dimensions in size. Though when I click the edit photo option after adding the video, it looks like it gives me the option to specify the thumbnail image...

Anyways, great job on the module. I've been loving it!

 
doclalor

Joined: 2005-04-28
Posts: 14
Posted: Sun, 2011-07-03 05:26

I got it working after some trial and error. See the attached image. Thanks all!