<?php
// rsspopulate.php
// Populate database table with videos from Google Video RSS feed into Top Level category
// Supply GET variable "q" (search query)
// Supply GET variable "maxresults" (will only populate this many or less into db table)
// Optional GET variable "category" (id of category for videos to be added to, defaults to Top Level if not supplied)
// Example:
// http://www.videosplurge.com/admin/rsspopulate.php?q=tv&category=46&maxresults=50
require_once "includes/RSS.php";
include("../dbinc.php");
include("../includes/db.php");
include("../includes/sanitize.php");
include("../includes/videoinfo.php");
include("../includes/getrecordcount.php");
$searchquery = $_GET['q'];
$Category = $_GET['category'];
if(!$Category) { $Category=-99; }
$counter = 0;
// Connect to MySQL database server
$link = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$link) { die('Could not connect: ' . mysql_error() . "\nPlease review your settings for MySQL database host, db name, db user, db password, and that the user has adequate access to the database."); }
// Select database
mysql_select_db($dbname);
for($start=0; $start<$maxresults; $start+=10)
{
// change this to search you want to return, retain "&output=rss"
$rssurl = "http://video.google.com/videosearch?q=$searchquery&hl=en&output=rss&start=$start&sitesearch=video.google.com#";
$rss =& new XML_RSS($rssurl);
$rss->parse();
// get 10 results
foreach ($rss->getItems() as $item) {
//Category Type RemoteID Name Thumbnail Description Length
$videolink = urldecode($item['link']);
$parsedurl = parse_url($videolink);
$parsedurlquery = $parsedurl['query'];
parse_str($parsedurlquery, $urlvars);
$videolink = $urlvars['q'];
$parsedurl = parse_url($videolink);
$parsedurlquery = $parsedurl['query'];
parse_str($parsedurlquery, $urlvars);
$RemoteID = $urlvars['docid'];
$Name = sanitize($item['title']);
$DateAdded = $item['pubDate'];
$Description = "";
$Keywords = "";
$Type = 2;
$Length = "00:00:00";
//$guid = $item['guid'];
//$Author = $item['author'];
if($RemoteID) {
// Construct thumbnail URL
$vrss = file_get_contents("http://video.google.com/videofeed?docid=".$RemoteID) or die("Invalid docid.");
if(!empty($vrss)) {
preg_match('/<media:thumbnail url="([^"]+)/',$vrss,$thumbnail_array);
$Thumbnail = $thumbnail_array[1];
//Remove amp;
$Thumbnail = str_replace('amp;','',$Thumbnail);
}
$sql = "INSERT INTO videos (Category, Type, RemoteID, Name, Thumbnail, Description, Keywords, Length, DateAdded) " .
"VALUES ($Category, $Type, \"$RemoteID\", \"$Name\", \"$Thumbnail\", \"$Description\", \"$Keywords\", \"$Length\", \"$DateAdded\")";
$result = mysql_query($sql) or die("Error: " . mysql_error());
$counter++;
echo "Added Google Video $RemoteID...\n";
}
}
}
mysql_close($link);
echo "$counter videos added successfully from Google Video search query '$searchquery'.";
?>