forked from Mondego/TubeKit
-
Notifications
You must be signed in to change notification settings - Fork 12
/
collectEverytime.php
executable file
·127 lines (121 loc) · 3.74 KB
/
collectEverytime.php
1
<?php // TubeKit Beta 4 // http://www.tubekit.org // Author: Chirag Shah // Date: 08/08/2008 ini_set("memory_limit","100M"); require_once("config.php"); require_once("$mpdirectory/rss_fetch.inc"); require_once("parseRSS.php"); $t=getdate(); $today=date('Y-m-d',$t[0]); $oTableName = $prefix . "_once";cd $eTableName = $prefix . "_everytime"; $query = "SELECT * FROM $oTableName"; $vresult = mysql_query($query) or die(" ". mysql_error()); while ($line = mysql_fetch_array($vresult, MYSQL_ASSOC)) { $ytID = $line['yt_id']; $id = $line['video_id']; $qid = $line['query_id']; $rID = ereg_replace('-', '\-', $ytID); // Open the apporipriate query file to read the ranks // of the results found by executing those queries on YouTube. $rankFile = $prefix . "_" . $qid . ".ranks"; $tempFile = $prefix . ".tmp"; $command = "grep \"$rID\" $rankFile | awk '{print \$1;}' > $tempFile"; system($command); $fy = fopen($tempFile, 'r'); $rank = fgets($fy); fclose($fy); $feedURL = "http://gdata.youtube.com/feeds/api/videos/$ytID"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $feedURL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $page = curl_exec($ch); curl_close($ch); if($page) { $entry = simplexml_load_file($feedURL); $video = parseVideoEntry($entry); $timestamp = time(); $title = $video->title; $description = $video->description; $username = $video->username; $upload_time = $video->published; $duration = $video->length; $category = $video->category; $video_url = $video->watchURL; $thumb_url = 'http://i1.ytimg.com/vi/' . $ytID . '/0.jpg'; $keywords = $video->keywords; $view_count = $video->viewCount; $rating_count = $video->numrating; $rating_avg = $video->rating; $comment_count = $video->commentsCount; $favorited = $video->favoriteCount; $response_count = $video->responseCount; $query = "INSERT INTO $eTableName VALUES('','$id','$timestamp','$today'"; $dquery = "SHOW COLUMNS FROM $eTableName"; $result = mysql_query($dquery) or mysql_error(); while($line = mysql_fetch_assoc($result)) { $fieldName = $line['Field']; switch($fieldName) { case 'title': $query = $query . ",'$title'"; break; case 'description': $query = $query . ",'$description'"; break; case 'username': $query = $query . ",'$username'"; break; case 'upload_time': $query = $query . ",'$upload_time'"; break; case 'duration': $query = $query . ",'$duration'"; break; case 'category': $query = $query . ",'$category'"; break; case 'keywords': $query = $query . ",'$keywords'"; break; case 'video_url': $query = $query . ",'$video_url'"; break; case 'thumb_url': $query = $query . ",'$thumb_url'"; break; case 'view_count': $query = $query . ",'$view_count'"; break; case 'rating_count': $query = $query . ",'$rating_count'"; break; case 'rating_avg': $query = $query . ",'$rating_avg'"; break; case 'comment_count': $query = $query . ",'$comment_count'"; break; case 'response_count': $query = $query . ",'$response_count'"; break; case 'favorite_count': $query = $query . ",'$favorited'"; break; case 'rank': $query = $query . ",'$rank'"; break; default: break; } // switch($fieldName) } // while($line = mysql_fetch_assoc($result)) $query = $query . ")"; $result = mysql_query($query) or mysql_error(); } // if(file_get_contents($feedURL)) } // while ($line = mysql_fetch_array($vresult, MYSQL_ASSOC)) ?>