summaryrefslogtreecommitdiff
path: root/www/functions/func_yt.php
blob: 4aa1e298ff2ccc114b151d78cf26bdce95d0996c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php

function get_yt_data($id){
	$data = file_get_contents("https://gdata.youtube.com/feeds/api/videos/".$id."");
	$data = preg_replace("/yt:statistics/", "ytstatistics", $data);
	$data = preg_replace("/media:group/", "mediagroup", $data);
	$data = preg_replace("/media:description/", "mediadescription", $data);
	$data = preg_replace("/gd:rating/", "gdrating", $data);
	$xmldata = simplexml_load_string($data);

	$title = $xmldata->title[0];
	$viewCount = $xmldata->ytstatistics["viewCount"];
	$author = $xmldata->author->name[0];
	$desc = $xmldata->mediagroup->mediadescription[0];
	$date = $xmldata->published[0];
	$rate = $xmldata->gdrating["average"];

	$res["title"] = $title;
	$res["viewCount"] = $viewCount;
	$res["author"] = $author;
	$res["desc"] = $desc;
	$res["date"] = $date;
	$res["rate"] = $rate;

	return $res;
}