We're growing into something new. Read More
ericrasch

Eric Rasch


// The PHP Function (video_info.php)
<?php
function video_info($url) {

// Handle Youtube
if (strpos($url, "youtube.com")) {
    $url = parse_url($url);
    $vid = parse_str($url['query'], $output);
    $video_id = $output['v'];
    $data['video_type'] = 'youtube';
    $data['video_id'] = $video_id;
    $xml = simplexml_load_file("http://gdata.youtube.com/feeds/api/videos?q=$video_id");

    foreach ($xml->entry as $entry) {
        // get nodes in media: namespace
        $media = $entry->children('http://search.yahoo.com/mrss/');
        
        // get video player URL
        $attrs = $media->group->player->attributes();
        $watch = $attrs['url']; 
        
        // get video thumbnail
        $data['thumb_1'] = $media->group->thumbnail[0]->attributes(); // Thumbnail 1
        $data['thumb_2'] = $media->group->thumbnail[1]->attributes(); // Thumbnail 2
        $data['thumb_3'] = $media->group->thumbnail[2]->attributes(); // Thumbnail 3
        $data['thumb_large'] = $media->group->thumbnail[3]->attributes(); // Large thumbnail
        $data['tags'] = $media->group->keywords; // Video Tags
        $data['cat'] = $media->group->category; // Video category
        $attrs = $media->group->thumbnail[0]->attributes();
        $thumbnail = $attrs['url']; 
        
        // get <yt:duration> node for video length
        $yt = $media->children('http://gdata.youtube.com/schemas/2007');
        $attrs = $yt->duration->attributes();
        $data['duration'] = $attrs['seconds'];
        
        // get <yt:stats> node for viewer statistics
        $yt = $entry->children('http://gdata.youtube.com/schemas/2007');
        $attrs = $yt->statistics->attributes();
        $data['views'] = $viewCount = $attrs['viewCount']; 
        $data['title']=$entry->title;
        $data['info']=$entry->content;
        
        // get <gd:rating> node for video ratings
        $gd = $entry->children('http://schemas.google.com/g/2005'); 
        if ($gd->rating) {
            $attrs = $gd->rating->attributes();
            $data['rating'] = $attrs['average']; 
        } else { $data['rating'] = 0;}
    } // End foreach
} // End Youtube

// Handle Vimeo
else if (strpos($url, "vimeo.com")) {
    $video_id=explode('vimeo.com/', $url);
    $video_id=$video_id[1];
    $data['video_type'] = 'vimeo';
    $data['video_id'] = $video_id;
    $xml = simplexml_load_file("http://vimeo.com/api/v2/video/$video_id.xml");
        
    foreach ($xml->video as $video) {
        $data['id']=$video->id;
        $data['title']=$video->title;
        $data['info']=$video->description;
        $data['url']=$video->url;
        $data['upload_date']=$video->upload_date;
        $data['mobile_url']=$video->mobile_url;
        $data['thumb_small']=$video->thumbnail_small;
        $data['thumb_medium']=$video->thumbnail_medium;
        $data['thumb_large']=$video->thumbnail_large;
        $data['user_name']=$video->user_name;
        $data['urer_url']=$video->urer_url;
        $data['user_thumb_small']=$video->user_portrait_small;
        $data['user_thumb_medium']=$video->user_portrait_medium;
        $data['user_thumb_large']=$video->user_portrait_large;
        $data['user_thumb_huge']=$video->user_portrait_huge;
        $data['likes']=$video->stats_number_of_likes;
        $data['views']=$video->stats_number_of_plays;
        $data['comments']=$video->stats_number_of_comments;
        $data['duration']=$video->duration;
        $data['width']=$video->width;
        $data['height']=$video->height;
        $data['tags']=$video->tags;
    } // End foreach
} // End Vimeo

// Set false if invalid URL
else { $data = false; }

return $data;

}
?>

// Example Page
<!doctype html>
<html lang="en"><head>
<meta charset="utf-8" />
<title>Video Info Example</title>
</head>
<body>

<?php

require_once('video_info.php');

if (isset($_GET['video'])) {$url = $_GET['video'];}
else {$url = 'http://vimeo.com/10255268';}

$video=video_info($url);

if ($video!==false) {

    $thumb = $video['thumb_large'];
    $title = $video['title'];
    $info = $video['info'];
    $tags = $video['tags'];
    $views = $video['views'];
    
    // Duration is returned seconds, roughly convert to min.
    $duration = number_format($video['duration']/60, 2, '.', '');
    
    echo "<a href=\"$url\"><img src=\"$thumb\" alt=\"$title\" /></a>";
    echo "<h2>$title</h2>";
    echo '<h4>Video Info</h4>';
    echo "<p>$info</p>";
    echo "<strong>Tags: </strong>$tags<br />";
    echo "<strong>Duration: </strong> $duration min<br />";
    echo "<strong>Views: </strong>$views<br />";

} else {
    echo 'Please enter a valid Youtube or Vimeo Url';
}

?>

</div>

</body>
</html>

Grab Youtube or Vimeo Info with PHP

Here's a little function I pieced together to grab info on a video based on the URL. It will determine the video service (youtube.com or vimeo.com), grab the id, thumnbail, description, view count, rating, etc. I built this while I was working on the video section for MF Magazine. They use both Youtube and Vimeo videos on their site, so I needed it to be able to accept URL's from either service. However, if you only need one or the other you could easily cut the size of the code in half. I've included a basic example page bellow the PHP code to get you stared. There's a live version of the example here: (sublantic.com/labfiles/video/…) I also put in a GET parameter if you want to try passing your own video URL, just append ?video=URLHERE to the above link. For example: (sublantic.com/labfiles/video/…) If you don’t specify a video in the url, it will just load a default video. Just a quick disclaimer, this doesn't pull ALL of the available info, just what I needed at the time. But it wouldn't be hard to modify if you wanted to pull additional info. I’ll do a separate post in a bit with a simple Javascript function that will automatically load the video within a specified element on the page using the info pulled with this PHP function. This way you don’t have to use messy “embed” tags, and allows for better branding & customization. Here’s an example of this php script combined with the javascript loader that loads a video “full screen” with basic info on the bottom, a logo overlayed at the top right, and a “hide panels” button on the top left that will hide everything but the video: (sublantic.com/labfiles/…) Again, it accepts a GET parameter, so you can input your own video link like so: (sublantic.com/labfiles/video/) Anyway, it's nowhere near perfect, and could definitely use a little cleaning up. But, maybe it can save a little work for a few people.I’ll try and post the script to embed the video either late tonight or tomorrow. Also, I apologize for none of the links "linking", but there seems to be some kind of bug with the new Forrst that's screwing up links. They kept getting cut weird, and I had to put them in parentheses to get them to display correctly, but that keeps them from linking. So you'll have to just copy/paste. Cheers!

HTML:

<form class="niceform">
    <p>
        <select>
            <option>This is an option</option>
            <option>This is another option</option>
            <option>This is a third option</option>
        </select>
    </p>
    
    <p>
        <label for="radio1">Radio</label>
        <input type="radio" id="radio1" name="radio" />
        
        <label for="radio2">Another Radio</label>
        <input type="radio" id="radio2" name="radio" />
    </p>
</form>

CSS: 


body {
    font-family:"Helvetica", Arial, sans-serif;
    font-size:12px;  
}

p {
    margin-bottom:25px;   
}

form {
    width:250px;
}

label {
    float:right;
    clear:right;
    margin:0 80px 5px 0;
    width:150px;
    text-align:left;
    line-height:1;
}
    
/* Niceform styles */
    
.niceform select {
    -webkit-appearance: menulist-button; 
    cursor:pointer;
    width:170px;
    height:28px;
}

.niceform .select {
    cursor:pointer;
    position:relative;
    width:171px;
    height:28px;
    background:url(http://i52.tinypic.com/ng6kap.png) no-repeat;
}

.niceform .select:hover {
    background-position:0 -28px;
}

.niceform .select span {
    position:absolute;
    top:8px;
    left:10px;
    font-size:0.9em;
    color:#83674a;
}

.niceform .select select option {
    padding:5px;
}

.niceform .select select option:hover {
    background:#ccc;
}

.niceform radio {
    margin:0;
    padding:0;
}

.niceform .radio {
    overflow:hidden;
    cursor:pointer;
    position:relative;
    width:12px;
    height:12px;
    float:left;
    clear:left;
    background:url(http://i54.tinypic.com/24wv6uf.png) no-repeat;
}

jQuery:

// Create nice looking forms
function niceForm() {
    $(".niceform select, .niceform input:radio").each(function() {
        var elem = $(this);
        elem.css("opacity", "0");
        if (elem.is(":radio")) {
            elem.wrap("<div class='radio' />");
        } else if (elem.is("select")) {
            elem.wrap("<div class='select' />");
            elem.parent().prepend("<span />");
        }
    });

    $(".select").each(function() {
        var elem = $(this);
        elem.find("span").text($(this).find("option:first-child").val());
        elem.find("select").change(function() {
            var elem = $(this);
            elem.parent().find("span").text($(this).val());
        });
    });

    $(".radio").click(function() {
        var elem = $(this);
        $(".radio").attr("checked", false);
        elem.attr("checked", true);
        $(".radio").css("background-position", "0 0");
        elem.css("background-position", "0 -12px");
    });
}

// If a form has a class of niceform, style the elements
if ($("form").hasClass("niceform")) {
    niceForm();
}

Simple jQuery custom form styling

I didn't like having to use a bloated plugin every time I wanted to style forms on sites I was working on, so decided to roll my own solution. It's kept intentionally simple. But I don't see why it can't be built on if necessary. Demo: jsfiddle.net/KkGgN/2/

Untitled

This is an in-progress redesign of my site, tylersticka.com I'm at that terrible precipice of "move into markup" or "I'm already sick of it, time to start over." I need some fresh eyes. I need some fresh perspective. Worth pursuing? Or more of the same stuff we've seen a zillion times? Thank you in advance for your opinions.