Help - Search - Members - Calendar
Full Version: Youtube And Google Video Plugin
Movable Type Community Forum > Additional Resources > Plugin Development and Usage
dwees
Just developed a plugin to embed either Youtube or Google video directly into MT posts. Doesn't currently work with Dynamic publishing mostly because I'm not totally sure how to do so. I know how to write the proper Php code (because this plugin is basically a port of a Wordpress plugin) but not totally sure I know how to make it interact with MT properly. If someone tests my mathematical equation plugin for Dynamic publishing (see another recent post in this forum) maybe they can let me know what changes I need to make?

With this code you can use either use [yt]insert_YouTube_Id_here[/yt] or [yt width="somenumber" height="somenumber"]insert_YouTube_Id_here[/yt] for inserting YouTube videos into your posts OR for Google Video you can use [gv]insert_GoogleVideo_Id_here[/gv] or [gv width="somenumber" height="somenumber"]insert_GoogleVideo_Id_here[/gv].

Notes:

1. GoogleVideo ids sometimes have a - in the front, which is important to include.
2. The standard window sizes for YouTube are width = 425 and height = 350 and for Google Video the standard window sizes are width = 400 and height = 326. When choosing your height and width for either YouTube or Google Video, you'll have to do a bit of math to get the new dimensions correct (so that your video doesn't look distorted).

Installation:

To install this plugin simply save the code below into a file named videoembedding.pl (using a typical text editor like Notepad) and upload the file to your mt/plugins directory. You need to chmod the file to 755 to allow the web server to access it properly. I also suggest that you create a videoembedding directory within your plugins directory (and chmod it to 755) and actually place the file inside that, mostly just to keep your plugins directory organized.

When using the [yt][/yt] tags in your posts, you need to apply the Video filter in the Text Formatting options (which are generally located below your Edit post window).

You can see the results of my plug-in at: http://www.unitorganizer.com/myblog/

CODE
# Quick code + Video
# a text filter plug-in for bb style [codes]
#
# Modified by David Wees
# ver 1.02 Copyright 2004 Crys Clouse;

use MT;

MT->add_text_filter(video => { label => 'Video', on_format => sub { &vcode }, });

sub vcode {
    $_=shift;

    vfullcodes($_);
}

sub vfullcodes {
    $s = $_[0];

    $s =~ s!\[yt\](.*?)\[/yt\]!<object width="425" height="350" type="application/x-shockwave-flash" data="http://www.youtube.com/v/$1"><param name="movie" value="http://www.youtube.com/v/$1" /><param name="wmode" value="transparent" /></object>!gis;
    $s =~ s!\[yt width="(.*?)" height="(.*?)"](.*?)\[\/yt]!<object width="$1" height="$2" type="application/x-shockwave-flash" data="http://www.youtube.com/v/$3"><param name="movie" value="http://www.youtube.com/v/$3" /><param name="wmode" value="transparent" /></object>!gis;
    $s =~ s!\[gv\](.*?)\[/gv\]!<object width="400" height="326" type="application/x-shockwave-flash" data="http://video.google.com/googleplayer.swf?docId=$1"><param name="movie" value="http://video.google.com/googleplayer.swf?docId=$1" /><param name="allowScriptAccess" value="sameDomain" /><param name="quality" value="best" /><param name="scale" value="noScale" /><param name="wmode" value="transparent" /><param name="salign" value="TL" /><param name="FlashVars" value="playerMode=embedded" /></object>!gis;
    $s =~ s!\[gv width="(.*?)" height="(.*?)"\](.*?)\[/gv\]!<object width="$1" height="$2" type="application/x-shockwave-flash" data="http://video.google.com/googleplayer.swf?docId=$3"><param name="movie" value="http://video.google.com/googleplayer.swf?docId=$3" /><param name="allowScriptAccess" value="sameDomain" /><param name="quality" value="best" /><param name="scale" value="noScale" /><param name="wmode" value="transparent" /><param name="salign" value="TL" /><param name="FlashVars" value="playerMode=embedded" /></object>!gis;
    $s = vmaincodes($s);

    #$s =~ s!\*amp;!&!g;

    return $s;

    vmaincodes($_);
}
sub vcommentcodes {
    $s = $_[0];
    $s =~ s!<!\*amp;lt;!g;
    $s =~ s!>!\*amp;gt;!g;

    $s = vmaincodes($s);

    $s =~ s!\*amp;!&!g;

    return $s;
}
sub vmaincodes {
    $s = $_[0];

    $s =~ s!…!…!g;
    $s =~ s!‘!‘!g;
    $s =~ s!’!’!g;
    $s =~ s!“!“!g;
    $s =~ s!”!”!g;
    $s =~ s!–!–!g;
    $s =~ s!—!—!g;

    $s = MT::Util::html_text_transform($_[0]);
    $s =~ s!(<p>.*?</p>)!vsmarty_pnts($1)!geis;
    $s =~ s!<linebreak>!\n!g;

    return $s;
}

sub vsmarty_pnts {
    $s = $_[0];

    my $smarty = $MT::Template::Context::Global_filters{'smarty_pants'};

    if ($smarty)
      {
        return $smarty->($s, '1');
      }
    else
      {
        return $s;
    }
}

1;
microage97
Works great.

Dave
Emiliano Bruni
I completely rewrote this plugin for optimize regular expression, include standard movable type plugin interface and I extended support for other video source like vimeo.com and myspace.com.

Every suggestion and bug report is welcome.

Plugin home page:

http://www.ebruni.it/software/os/mtos/videoembedding/
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.