Welcome Guest, Not a member yet? Register   Sign In
Video Embed Library.
#1

[eluser]sumanchalki[/eluser]
I made this library to help adding videos from youtube.com, vimeo.com and dailymotion.com. This can extract screen-shot images and provides an easy way to embed the video. Only, users have to put the video url.

There can be lots of libraries like this, but I found it very helpful for myself.

Usage:

Code:
$video_url = 'http://www.youtube.com/watch?<other params>v=&lt;video_id&gt;&lt;other params>'; //or any vimeo/dailymotion url

try {
    $this->load->library('embed_video');
    $config['zend_library_path'] = APPPATH ."libraries/Zend/"; // This is required for youtube
    $config['video_url'] = $video_url;
    
    $this->embed_video->initialize($config);
    $this->embed_video->prepare();
}
catch(Exception $e) {
    die('Invalid url');
}

$upload_path = BASEPATH.'../uploads/';

/* saves the thumb image */
$this->embed_video->save_thumb($upload_path, '', 115, 75);

/* get the thumb image name */
$video_img_name = $this->embed_video->get_resized_imagename();

/* get the embed code for specific width and height */
$player = $this->embed_video->get_player(420, 340);

/* get the original youtube video file url */
$original_youtube_video = $this->embed_video->get_youtube_video();


Screenshot images will be resized with the exact width, height; with one side greater than the input value i.e. if someone place it as a background of div it will be shown with a fixed width and height. If someone wants the resizing within the limit of a specified width and height, he needs to add an extra 5th argument: true, e.g.

Code:
$this->embed_video->save_thumb($upload_path, '', 115, 75, true);



It has some dependencies, some helper functions need to be added.

Code:
function get_ext($filename) {
    $matches = array();
    $return_arr = array('filename'=>'', 'ext'=>'');

    preg_match('/(^.*)\.([^\.]*)/', $filename, $matches);
    if( isset($matches[1]) ) {
        $return_arr['filename'] = $matches[1];
    }
    if( isset($matches[2]) ) {
        $return_arr['ext'] = $matches[2];
    }

    return $return_arr;
}

function test_file($file) {
    if( file_exists($file) ) {
        if( is_file($file) )
            return true;
        else
            return false;
    }
    else
        return false;
}

function get_302_Location($url) {
    $headers = get_headers($url);
    $array = $headers;
    $count = count($array);
    
    for ($i=0; $i < $count; $i++) {
        if (strpos($array[$i], "ocation:")) {
            $url = substr($array[$i], 10);
        }
    }
    if ($url) {
        return $url;
    }
    else {
        return 0;
    }
}


function getSmallerDimension($img_path, $width, $height, $no_force_resize = false) {
    list($wid, $hei, $type, $attr) = getimagesize($img_path);
    $ratio = $wid / $hei;
    
    if( $height < $width/$ratio ) {
        if($no_force_resize && $wid<=$width) {
            return 'small_image|width';
        }
        else {
            return 'width';
        }
    }
    else if( $width < $height * $ratio ) {
        if($no_force_resize && $hei<=$height) {
            return 'small_image|height';
        }
        else {
            return 'height';
        }
    }
    else {
        return 'auto';
    }
}
#2

[eluser]Mr-H[/eluser]
thanks
it will help me for sur
#3

[eluser]Buso[/eluser]
What role does zend play here?

And what's the difference with regular embedding? I have my own helper for this, but it's pretty short
#4

[eluser]sumanchalki[/eluser]
Hi Buso,

It not only generates the basic embed code but also can be used to extract screen-shot image. Also it has another feature, one can get the original video file from youtube url so that he can use his own flash player to display youtube video.

Fetching of screen-shot images from youtube videos can be done easily using a quick url trick, but not a reliable method I guess. So I used the google gdata api(zend library) to extract it.

Hope you get your reply.

Thanks
Suman
#5

[eluser]baustelle[/eluser]
Hello,

nice library, works like treat for vimeo. I just wonder, do I need to include the whole zend framework or only the zendGData library?
I never worked with Zend Framework before and I can't seem to find just a a php library, I keep seeing whole application servers.


Any hint would be appreciated?

Cheers,
Daniel
#6

[eluser]sumanchalki[/eluser]
Hi Daniel,

Glad, it works for you. Only Zend Gdata library is needed for it to work. Whole Zend library is not at all mandatory. You can upload the Zend directory to the directory 'application/libraries' as for example. Then you can use it like the example code

Code:
$config['zend_library_path'] = APPPATH ."libraries/Zend/";


Regards
Suman
#7

[eluser]baustelle[/eluser]
Hello Suman,

thanks for you lightening quick reply!

There is something funky going on with the include pathes. When I do exactly what like you suggested, the the Zend loader.php seems to be loaded but it is looking in the wrong places for the other classes such as Zend/exception.php etc.

Only when I duplicate the whole Zend folder inside the libraries/Zend folder as shown in the following link it works.
system/application/libraries/Zend/Zend

Any idea why that could be? When setting $config['zend_library_path'] I tried both, with and without trailing slash.

Anyway it works like a charm and is fun to use.

Thanks and best regards,
Daniel
#8

[eluser]sumanchalki[/eluser]
Hi Daniel,

I could not get properly what can be the reason, as for my recent projects it is working this way.

If this is your problem you can also try this way:

Code:
$config['zend_library_path'] = APPPATH ."libraries/";

If you do not wish to copy Zend directory within Zend directory.

BTW, which Gdata version of zend library you are using? I am using the latest version.

Regards
Suman
#9

[eluser]baustelle[/eluser]
Hi Suman,

rather embarrassing that I didn't try it myself, but of course you are right, that was it.

Thanks a lot for you help and the time you saved me by sharing your library :-).

Best,
Daniel




Theme © iAndrew 2016 - Forum software by © MyBB