diff options
Diffstat (limited to 'www/func.php')
| -rw-r--r-- | www/func.php | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/www/func.php b/www/func.php new file mode 100644 index 0000000..9d6ebac --- /dev/null +++ b/www/func.php @@ -0,0 +1,39 @@ +<?php + +function failure($reason){ + header("HTTP/1.1 404 Not Found"); + echo $reason; + exit; +} + +function get_all_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; +} + +function get_yt_title($id){ + $data = file_get_contents("https://gdata.youtube.com/feeds/api/videos/".$id.""); + $xmldata = simplexml_load_string($data); + $title = $xmldata->title[0]; + return $title; +} |
