$url = "http://gdata.youtube.com/feeds/api/videos?category={$vquery}&max-results=40&start-index={$index}&v=2&time=this_week"; // echo($url."before fetch_rss\n"); $rss = fetch_rss($url); // var_dump($rss); //echo("\n\n\n\n\n"); foreach ($rss->items as $item) { $yt_url = $item['link']; $ytID = substr($yt_url, 31, 11); $feedURL = "http://gdata.youtube.com/feeds/api/videos/{$ytID}"; //echo($feedURL. "in for each\n"); sleep($time); if (file_get_contents($feedURL)) { $time = 0.8 * $time; $entry = simplexml_load_file($feedURL); //Convert the well-formed XML document in the given file to an object. $video = parseVideoEntry($entry); $timestamp = time(); $title = $video->title; $upload_time = $video->published; $duration = $video->length; $category = $video->category; $video_url = $video->watchURL; $keywords = $video->keywords; $view_count = $video->viewCount; $rating_count = $video->numrating; $rating_avg = $video->rating; $q = "insert into {$newtable} VALUES ('','{$originalvideo}','{$v2}','{$title}','{$view_count}','{$ytID}','{$timestamp}','{$rating_count}','{$rating_avg}')"; echo $q . "insertquery\n"; $r = mysql_query($q) or mysql_error(); } else { $time = $time + 5.0;
$queryResponse = AddValue($oTableName_in, $responseVideo, $qid_in, $timestamp_in, $today_in, $responseURLArray, $count, $type, $dbh); $result = mysql_query($queryResponse) or mysql_error(); } // foreach $responseList = implode(",", $responseURLArray); } // if $count = 0; // Related video code $commaseparatedURL = ""; $relatedURLArray = array(); if ($video->relatedURL) { $type = "Related:" . $ytID_in; $relatedFeed = simplexml_load_file($video->relatedURL); foreach ($relatedFeed->entry as $related) { $video_in = parseVideoEntry($related); $timestamp_in = time(); echo "Related Video Title" . "\n"; echo $video_in->title; $queryRelated = AddValue($oTableName_in, $video_in, $qid_in, $timestamp_in, $today_in, $relatedURLArray, $count, $type, $dbh); echo "Related Query:" . "\n"; $result = mysql_query($queryRelated) or mysql_error(); } $commaseparatedURL = implode(",", $relatedURLArray); } // if // Start formualting the Query $query = "INSERT INTO {$oTableName_in} "; $query = $query . "VALUES('','{$qid_in}','{$ytID_in}','{$timestamp}','','','{$today_in}','{$typeMain}'"; $dquery = "SHOW COLUMNS FROM {$oTableName_in}"; $result = mysql_query($dquery) or mysql_error();
function LoadVideo($vid) { $feedURL = 'http://gdata.youtube.com/feeds/api/videos/' . $vid; $entry = @simplexml_load_file($feedURL); if ($entry===FALSE) return FALSE; return parseVideoEntry($entry); }
$responseFeed = simplexml_load_file($video->responsesURL); echo "<tr><td colspan=\"2\"><h3>" . $responseFeed->title . "</h3></td></tr>\n"; foreach ($responseFeed->entry as $response) { $responseVideo = parseVideoEntry($response); echo "<tr>\n"; echo "<td><a href=\"{$responseVideo->watchURL}\">\n <img src=\"{$responseVideo->thumbnailURL}\"/></a></td>\n"; echo "<td><a href=\"{$responseVideo->watchURL}\">\n {$responseVideo->title}</a><br/>\n"; echo sprintf("%0.2f", $responseVideo->length / 60) . " min. |\n {$responseVideo->rating} user rating | {$responseVideo->viewCount} \n views<br/>\n"; echo $responseVideo->description . "</td>\n"; echo "</tr>\n"; } } // read 'related videos' feed into SimpleXML object // parse and display each video entry if ($video->relatedURL) { $relatedFeed = simplexml_load_file($video->relatedURL); echo "<tr><td colspan=\"2\"><h3>" . $relatedFeed->title . "</h3></td></tr>\n"; foreach ($relatedFeed->entry as $related) { $relatedVideo = parseVideoEntry($related); echo "<tr>\n"; echo "<td><a href=\"{$relatedVideo->watchURL}\">\n <img src=\"{$relatedVideo->thumbnailURL}\"/></a></td>\n"; echo "<td><a href=\"{$relatedVideo->watchURL}\">\n {$relatedVideo->title}</a><br/>\n"; echo sprintf("%0.2f", $relatedVideo->length / 60) . " min. | \n {$relatedVideo->rating} user rating | {$relatedVideo->viewCount} \n views<br/>\n"; echo $relatedVideo->description . "</td>\n"; echo "</tr>\n"; } } echo "</table>\n"; ?> </body> </html>
$videotext = strip_tags($_POST[videotext]); $videosource = $_POST['videosource']; if(substr($videosource, 0, 4) == 'http') { if(preg_match('/youtube\.com\/(v\/|watch\?v=)([\w\-]+)/', $videosource, $match)) { $youtubeid = $match[2]; $youtubeurl = "http://gdata.youtube.com/feeds/api/videos/$youtubeid"; } else { die("We couldn't seem to get the YouTube ID from that link ... care to try again?"); } } else { $youtubeid = $videosource; $youtubeurl = "http://gdata.youtube.com/feeds/api/videos/$youtubeid"; } if(file_get_contents($youtubeurl) == 'Invalid id') { die("It seems you slipped us a curious YouTube ID? Why don't you try to copy and paste the full URL?"); } $youtubehandle = simplexml_load_file($youtubeurl); $youtubedata = parseVideoEntry($youtubehandle); $videotitle = sanitize($youtubedata->title); if(!$_POST['videotext']) { $videotext = sanitize($youtubedata->description); } $sql = "INSERT INTO posts (neighbr, type, title, note, source) VALUES ('$_SESSION[username]', 'video', '$videotitle', '$videotext', '$youtubeid')"; $result = $db->query($sql); echo ($result) ? header("Location: http://neighbr.net/$_SESSION[username]/") : "We couldn't share your video! :("; break; case "link"; $link = strip_tags($_POST[linktext]); if(substr($link, 0, 4) != 'http') { die(header("Location: http://neighbr.net/")); } if(!$_POST['linktitle'] OR !$_POST['linktext']) { die(header("Location: http://neighbr.net/")); } $sql = "INSERT INTO posts (neighbr, type, title, note) VALUES ('$_SESSION[username]', 'link', '$_POST[linktitle]', '$link')"; $result = $db->query($sql); echo ($result) ? header("Location: http://neighbr.net/$_SESSION[username]/") : "We couldn't share your link! :("; break; case "code";
function youtubegetvideodetails($vidlink, $existingcode, $categorylist, $reqtype) { global $my, $downloadcachingtimeout; $mosConfig_absolute_path = JPATH_SITE; $mosConfig_live_site = substr(JURI::base(), 0, strlen(JURI::base()) - 1); if ($reqtype == "new") { $vidlink = jalemurldecode($vidlink); $videoservertype = "youtube"; $youtubeurlmatch = "(.*)v="; //youtube urlmatch (v= must be in it) $smallvideocode = eregi_replace($youtubeurlmatch, '', $vidlink); //eregi replace vidlink $smallvideocode = substr($smallvideocode, 0, 11); } else { if ($reqtype == "refresh") { $smallvideocode = $existingcode; } } // set video data feed URL $feedURL = "http://gdata.youtube.com/feeds/api/videos/" . $smallvideocode . ""; // read feed into SimpleXML object $entry = simplexml_load_file($feedURL); // Call Function To Parse Video $video = parseVideoEntry($entry); $videotitle = $video->title; // video_title -> FIELD name in Database $videotitle = htmlentities($videotitle, ENT_NOQUOTES); $videotitle = ucwords(strtolower($videotitle)); $videodescription = $video->description; // video_desc -> FIELD name in Database $strlength = strlen($videodescription); if ($strlength == 0) { $videodescription = $videotitle; } $videodescription = strip_tags($videodescription); $videotags = $video->keywords; // tags -> FIELD name in Database $sec = $video->length; // Convert to 00:00:00 i.e. hrs:min:sec $videoduration = sec2hms($sec); // duration -> FIELD name in Database $viddate = array(); $viddate = date_parse($video->published); // Convert Date 0000-00-00 $video_published = $viddate[year] . "-" . $viddate[month] . "-" . $viddate[day]; // date_added -> FIELD name in Database $vidupdate = date_parse($video->updated); // Convert Date 0000-00-00 $date_updated = $vidupdate[year] . "-" . $vidupdate[month] . "-" . $vidupdate[day]; // date_updated -> FIELD name in Database $video_url = $video->videourl; // video_url -> FIELD name in Database $remote_id = $smallvideocode; // remote_id -> FIELD name in Database $thumbnail_link = $video->thumbnailURL; // video_thumb -> FIELD name in Database $display_thumb = $video->displayURL; // display_thumb-> FIELD name in Database $video_published = date('Y-m-d'); if ($reqtype == "new") { $renderinputform = renderinputform($video_url, $thumbnail_link, $display_thumb, $videotitle, $videodescription, $videotags, $video_published, $date_updated, $videoduration, $remote_id, $videoservertype, $smallvideocode, $categorylist); return $renderinputform; } else { if ($reqtype == "refresh") { return array($picturelink, $videotitle, $itemcomment, $videotags, $videodescription, $videoduration, $video_published, $thumbnail_link); } } }