<?php
class video extends google_data
{
public $author = null;
public $title = null;
public $description = null;
public $keywords = null;
public $player_url = null;
public $duration = null;
public $duration_str = null;
public $position = null;
public $view_count = 0;
public $fav_count = 0;
public $rating_min = 0;
public $rating_max = 0;
public $num_raters = 0;
public $avg_rate = 0;
public $comments_feed = null;
public $comment_count = 0;
public $video_responses_feed = null;
public $related_videos_feed = null;
public $thumbnails = null;
public $comments = null;
function __construct($xpath, $node)
{
$this->load($xpath, $node);
}
public function to_time($seconds)
{
return date(($seconds >= 3600 ? "H:i:s" : "i:s"), mktime(0, 0, $seconds));
}
public function load($xpath, $node)
{
$this->author = $this->get_node_value($xpath, "atom:author//atom:name", $node, "");
$this->title = $this->get_node_value($xpath, "media:group//media:title", $node, "");
$this->description = $this->get_node_value($xpath, "media:group//media:description", $node, "");
$this->keywords = $this->get_node_value($xpath, "media:group//media:keywords", $node, "");
$this->player_url = $this->get_node_attr($xpath, "media:group//media:player", $node, "url", "");
$this->duration = $this->get_node_attr($xpath, "media:group//yt:duration", $node, "seconds", 0);
$this->duration_str = $this->to_time($this->duration);
$this->load_thumbnails($xpath, $node);
$this->load_links($xpath, $node);
$this->load_position($xpath, $node);
$this->load_statistics($xpath, $node);
$this->load_rating($xpath, $node);
$this->load_comments($xpath, $node);
}
private function load_thumbnails($xpath, $node)
{
unset($this->thumbnails);
$thumbnails = $xpath->query("media:group//media:thumbnail", $node);
if ($thumbnails)
{
$this->thumbnails = array();
foreach ($thumbnails as $thumbnail)
{
array_push($this->thumbnails, array(
"url" => $thumbnail->getAttribute("url"),
"width" => $thumbnail->getAttribute("width"),
"height" => $thumbnail->getAttribute("height")
));
}
}
}
private function load_links($xpath, $node)
{
$this->video_responses_feed = $this->load_link($xpath, $node, "video.responses");
$this->related_videos_feed = $this->load_link($xpath, $node, "video.related");
}
private function load_link($xpath, $node, $key)
{
return $this->get_node_attr($xpath, "atom:link[@rel='" . $key . "']", $node, "href", null);
}
private function load_position($xpath, $node)
{
$this->position = $this->get_node_value($xpath, "georss:where/gml:Point/gml:Pos", $node, "");
if ($this->position != "")
{
$this->position = explode(" ", $this->position);
}
}
private function load_statistics($xpath, $node)
{
$stats = $this->get_node($xpath, "yt:statistics", $node);
if ($stats)
{
$this->view_count = intval($stats->getAttribute("viewCount"));
$this->fav_count = intval($stats->getAttribute("favoriteCount"));
}
}
private function load_rating($xpath, $node)
{
$rating = $this->get_node($xpath, "gd:rating", $node);
if ($rating)
{
$this->rating_min = intval($rating->getAttribute("min"));
$this->rating_max = intval($rating->getAttribute("max"));
$this->num_raters = intval($rating->getAttribute("numRaters"));
$this->avg_rate = floatval($rating->getAttribute("average"));
}
}
private function load_comments($xpath, $node)
{
$comments = $this->get_node($xpath, "gd:comments//gd:feedLink", $node);
if ($comments)
{
$this->comments_feed = $comments->getAttribute("href");
$this->comment_count = intval($comments->getAttribute("countHint"));
$this->comments = new comments($this->comments_feed);
}
}
}
?>