Pages

Showing posts with label Youtube. Show all posts
Showing posts with label Youtube. Show all posts

Thursday, July 11, 2013

How to get youtube video duration from id - PHP



function parseVideoEntry($video_id) {    
    $obj= new stdClass;

$url = 'http://gdata.youtube.com/feeds/api/videos/'.$video_id;
$categoriesArray = array();
$xml = simplexml_load_file($url);


    $media = $xml->children('http://search.yahoo.com/mrss/');
    $obj->title = $media->group->title;
    $obj->description = $media->group->description;
     
    $yt = $media->children('http://gdata.youtube.com/schemas/2007');
    $attrs = $yt->duration->attributes();

    $obj->length = $attrs['seconds'];
    $VideoSeconds = $obj->length;
    return $VideoSeconds;    
}

echo $video = parseVideoEntry("nVhM3IYMF8o");

Monday, July 8, 2013

Get Youtube video id from embaded code - PHP

function parse_youtube($link){

    $regexstr = '~
        # Match Youtube link and embed code
        (?:                             # Group to match embed codes
            (?:<iframe [^>]*src=")?       # If iframe match up to first quote of src
            |(?:                        # Group to match if older embed
                (?:<object .*>)?      # Match opening Object tag
                (?:<param .*</param>)*  # Match all param tags
                (?:<embed [^>]*src=")?  # Match embed tag to the first quote of src
            )?                          # End older embed code group
        )?                              # End embed code groups
        (?:                             # Group youtube url
            https?:\/\/                 # Either http or https
            (?:[\w]+\.)*                # Optional subdomains
            (?:                         # Group host alternatives.
            youtu\.be/                  # Either youtu.be,
            | youtube\.com              # or youtube.com
            | youtube-nocookie\.com     # or youtube-nocookie.com
            )                           # End Host Group
            (?:\S*[^\w\-\s])?           # Extra stuff up to VIDEO_ID
            ([\w\-]{11})                # $1: VIDEO_ID is numeric
            [^\s]*                      # Not a space
        )                               # End group
        "?                              # Match end quote if part of src
        (?:[^>]*>)?                       # Match any extra stuff up to close brace
        (?:                             # Group to match last embed code
            </iframe>                 # Match the end of the iframe
            |</embed></object>          # or Match the end of the older embed
        )?                              # End Group of last bit of embed code
        ~ix';

    preg_match($regexstr, $link, $matches);
    return $matches[1];
}

function get_youtube_id($embadedcode){
 if(strpos($embadedcode,'iframe') !== false){
  return parse_youtube($embadedcode);
 } else if(strpos($embadedcode,'object') !== false){
  preg_match('#(?<=youtube\.com/v/)\w+#', $embadedcode, $matches);
  return $matches[0];
 }
}

Thursday, November 29, 2012

How to get thumbnail of YouTube video link using YouTube Video ID?

Each YouTube video has 4 generated images. They are predictably formatted as follows:

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

The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (ie. one of 1.jpg, 2.jpg, 3.jpg) is:

http://img.youtube.com/vi/<insert-youtube-video-id>/default.jpg

For the high quality version of the thumbnail use a url similar to this:

http://img.youtube.com/vi/<insert-youtube-video-id>/hqdefault.jpg

There is also a medium quality version of the thumbnail, using a url similar to the HQ:

http://img.youtube.com/vi/<insert-youtube-video-id>/mqdefault.jpg

For the maximum resolution version of the thumbnail use a url similar to this:

http://img.youtube.com/vi/<insert-youtube-video-id>/maxresdefault.jpg

Saturday, November 3, 2012

How to fix z-index in YouTube videos

Add a parameter to force YouTube iframe to set a low z-index.

If you have any element you’ll like to show above a YouTube iframe you just have to add a parameter to the iFrame URL.

wmode=transparent

Add the wmode parameter in the src URL.

<iframe class="youtube-player" type="text/html" width="520" height="330" src="http://www.youtube.com/embed/asfdsafsdfWSDF?wmode=transparent" frameborder="0"></iframe>

If you have YouTube videos that appear infront of your other website content and giving it a lower z-index does not seem to do the trick then try adding the wmode parameter to the embedded movie.


<object width='425' height='344'> 
    <param name='movie' value='http://www.youtube.com/v/Wj_JNwNbETA&hl=en&fs=1'> 
    <param name='type' value='application/x-shockwave-flash'> 
    <param name='allowfullscreen' value='true'> 
    <param name='allowscriptaccess' value='always'> 
    <param name="wmode" value="transparent" />
    <embed width='425' height='344'
            src='http://www.youtube.com/v/Wj_JNwNbETA&hl=en&fs=1'
            type='application/x-shockwave-flash'
            allowfullscreen='true'
            allowscriptaccess='always'
            wmode="opaque"
    ></embed> 
    </object>