Jump to content

Module: Video embed for YouTube/Vimeo (TextformatterVideoEmbed)


ryan

Recommended Posts

  • 3 months later...

It depends on what you want to do exactly. 

Because the module converts a Youtube link that is in an RTE texatarea field, you already know the id of the video because it is in the link. You could easily insert the image link using the url schema from that first link I posted.

Maybe if you can explain your usage scenario we can help more. Where you do want to display the image? How is it connected to the embedded link.

It is easy to grab the id of the video from the link in either PHP or JS using a regex, but the video module also stores the id in the PW database (in the textformatter_video_embed table), so this might also be an option depending on your needs.

EDIT: Here is the function in the module that parses the video url:

https://github.com/ryancramerdesign/TextformatterVideoEmbed/blob/master/TextformatterVideoEmbed.module#L127

Or you can use:

$url = "http://www.youtube.com/watch?v=C4kxS1ksqtw&feature=relate";
parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars );
echo $my_array_of_vars['v'];    
  // Output: C4kxS1ksqtw
  • Like 1
Link to comment
Share on other sites

Ok, so it sounds like you are manually adding the thumbnail image to an RTE? Maybe you don't really need the video embed module, because you don't actually want the video to play inside the RTE field?

There are lots of ways to go about this. You could use a regex in your template. You could make your own module. You could maybe use the Hanna Code module (http://modules.processwire.com/modules/process-hanna-code/) and just enter the video ID and use that to output the thumbnail and link to open in fancybox.

You could even use JS to modify the link.

An example of your exact usage would really help to narrow down the best approach.

Link to comment
Share on other sites

i just did what u said, i dropped the module, now from admin panel i just enter the url for youtube movie and then i do this :

<?php
    $videoFolder = $pages->find('parent=1051, limit=3');
    $out ="";
        foreach($videoFolder as $videoItem){
            $vidUrl = $videoItem->video;
            parse_str( parse_url( $vidUrl, PHP_URL_QUERY ), $my_array_of_vars );
            $imgUrl = $my_array_of_vars['v'];
            $search     = '/youtube\.com\/watch\?v=([a-zA-Z0-9]+)/smi';
            $replace    = "youtube.com/embed/$1?autoplay=1";
            $vidUrl = preg_replace($search,$replace,$vidUrl);
            $out .= "<div>";
            $out .= "<a class='fancybox' data-fancybox-type='iframe' href='{$vidUrl}'><img src='http://img.youtube.com/vi/{$imgUrl}/0.jpg' alt='{$videoItem->title}' /></a>";
            $out .= "<div class='name'><a href='{$vidUrl}'>{$fotoItem->title}</a></div>";
            $out .= "</div> ";
        }
        echo $out;
 ?>

And thats it i got my video working :)
Ty alot Adrian u ware most helpful

  • Like 2
Link to comment
Share on other sites

Glad you got it working.

The $videoItem->video makes me think you are storing the URL for the video in a dedicated field? If that's the case, you shouldn't need to do that preg_replace. You already have the id from $my_array_of_vars['v'] so you should be able to just build the embed version directly from that.

  • Like 1
Link to comment
Share on other sites

Glad you got it working.

The $videoItem->video makes me think you are storing the URL for the video in a dedicated field? If that's the case, you shouldn't need to do that preg_replace. You already have the id from $my_array_of_vars['v'] so you should be able to just build the embed version directly from that.

HA! ... true  :D

<?php
	$videoFolder = $pages->find('parent=1051, limit=3');
	$out ="";
		foreach($videoFolder as $videoItem){
			$vidUrl = $videoItem->video;
			parse_str( parse_url( $vidUrl, PHP_URL_QUERY ), $my_array_of_vars );
			$vidID = $my_array_of_vars['v'];
			$out .= "<div>";
			$out .= "<a class='fancybox' data-fancybox-type='iframe' href='http://www.youtube.com/embed/{$vidID}?autoplay=1'><img src='http://img.youtube.com/vi/{$vidID}/0.jpg' alt='{$videoItem->title}' /></a>";
			$out .= "<div class='name'><a href='http://www.youtube.com/embed/{$vidID}?autoplay=1'>{$videoItem->title}</a></div>";
			$out .= "</div> ";
		}
		echo $out;
 ?>

Ty alot :)

Link to comment
Share on other sites

  • 1 month later...

Just noticed that if you copypaste youtube url from Chrome (Win7) addressbar into CKeditor, it will be transformed into <a> tag and therefor embedding doesn't work. I don't know how CKeditor does that, since if you copypaste it from another source (like text editor), it will not be transformed into a link. 

Possible solution could be allowing links also transformed into a embed. What do you think?

  • Like 1
Link to comment
Share on other sites

It might just be a matter of the forum using an older version of CKEditor (3 vs 4). Does it work if you do an unformatted paste? i.e. shift+ctrl+v ? Though I'd have no problem making it support the videos as links, but it seems like that then creates a problem where you actually want to link to a video (as opposed to embedding it). If someone puts the link in it's own paragraph, maybe it's safe to assume they are trying to embed though. Especially if the anchor text matches the src attribute. 

Link to comment
Share on other sites

  • 1 month later...

Hi all, 

I have an issue with the module.

It works fine for me under all browsers apart from Firefox(Win 7) - I've updated to version 26.0, from 24.*;

However I still get only a black box. I can see the code, exactly the same as under Chrome/Safari/Opera, but it doesn't work.

Any ideas what could be causing the problem ? 

p.s. I get no errors with Firebug. 

Link to comment
Share on other sites

Is it possible your browser doesn't have the necessary plugins to display videos (Flash, etc.) or has some kind of blocker installed? I know with my copy of Firefox, both are the case (no flash, and everything external blocked... but it was intentionally configured that way). 

Link to comment
Share on other sites

  • 3 weeks later...

Is there any way I can call that youtube ID part from template using this module?

Youtube uses these urls:

http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg

to give us pre-generated thumbnails, so it would be great if I could use thumbnails on my front page as a preview, which leads to full page with properly embeded video.

Link to comment
Share on other sites

  • 2 weeks later...

@Ryan: fantastic Module. I have used it the first time now on a site for a colleague.

There is one thing I want to ask if it could be possible:

With the param rel=0 added to the $embedCode  $queryString (e.g. ?feature=oembed&rel=0) the video gets reset to the first frame of it after playing, - instead of displaying a lot of thumbs to other videos.

On some pages / sites it looks much better this way.

Can this be added to the module? (maybe as option, or default?)

Link to comment
Share on other sites

Horst, it should already support the rel=0 option for video embedding (at least it used to). Try adding it to the YouTube URL you are embedding. If it doesn't work, go to the module settings and clear the video cache and try again. 

Link to comment
Share on other sites

Ryan, unfortunately it doesn't work. (have flushed the DB)
 
My url is


and the resulting code in DB is

video_id = oUdcc7fYlp8?rel=0

embed_code = <iframe width="640" height="360" src="http://www.youtube.com/embed/oUdcc7fYlp8?feature=oembed" frameborder="0" allowfullscreen></iframe>

The rel=0 doesn't make it into the embedded code. ??

Link to comment
Share on other sites

  • 1 month later...

Hi Guys!

A question for you gents...

Is it possible to modify the module such that it automatically adds  &rel=0  to all our YouTube video urls that we enter?

Been trying to plug it in into various parts of the module but I can't seem to get it to work.

It would save having to type in $rel=0 every single time I add a video.

Cheers guys!

Link to comment
Share on other sites

After you installed the Textformatter, go to /site/modules/TextformatterVideoEmbed.module

add a line in the methode embedYoutube:

// line number +/- 145
$queryString = isset($matches[3][$key]) ? $matches[3][$key] : '';
$queryString = $queryString . "&rel=0"; // this is the new line you should add

---

If you make modifications to this module, it's better to rename the module and the file and install it again. This to insures updates won't delete your modifications

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...