Author Topic: process_youtube.inc.php  (Read 1391 times)

0 Members and 1 Guest are viewing this topic.

Offline Dudditz

  • Newbie
  • *
  • Posts: 16
  • Karma: -1
    • View Profile
    • PimpMyGamercard
process_youtube.inc.php
« on: April 19, 2009, 07:37:50 PM »
I notice this file is using legacy API from YouTube.
Any plans to update to the latest?
http://code.google.com/apis/youtube/migration.html#Difference

I have been working on a similar plugin for a video script using the API if you need assistance.

Offline Jeff

  • Global Moderator
  • Sr phpd Member
  • *****
  • Posts: 359
  • Karma: 5
  • Need help? Feel free to ask.
    • View Profile
Re: process_youtube.inc.php
« Reply #1 on: April 20, 2009, 11:24:22 PM »
ill mark one up really quick... you guys tell me what you think

Offline Dudditz

  • Newbie
  • *
  • Posts: 16
  • Karma: -1
    • View Profile
    • PimpMyGamercard
Re: process_youtube.inc.php
« Reply #2 on: April 22, 2009, 02:42:56 AM »
I also noticed that this process file and the google file uses multiple file_get_contents()
Isnt there a more efficient way instead of sending multiple requests for the same data?
Such as a single file_get_contents() which stores to variable, then write the additional functions
using that stored variable?
(Like the latest release dailymotion process file storing data to $file.)

Offline Jeff

  • Global Moderator
  • Sr phpd Member
  • *****
  • Posts: 359
  • Karma: 5
  • Need help? Feel free to ask.
    • View Profile
Re: process_youtube.inc.php
« Reply #3 on: April 23, 2009, 10:57:01 PM »
ughhhh... well i really dont seem to be having a whole lot of time right now(with it being my senior year in high school and having track and work  ughhh) lol.....

well im pretty sure there is a more efficient way just kinda busy to look into it right now......

ill try tho... :-D

talk to you all later

Offline Dudditz

  • Newbie
  • *
  • Posts: 16
  • Karma: -1
    • View Profile
    • PimpMyGamercard
Re: process_youtube.inc.php
« Reply #4 on: April 24, 2009, 04:53:30 AM »
Here is a less requesting version.
Instead of requesting the xml for each function, it simply sends a single request for the xml
and stores it into variable $xml which the functions feed from.
Code: [Select]
<?php
/**
 * Gets youtube link from eg http://www.youtube.com/watch?v=xxxxxxxxxxx&eurl=
 *
 * @param http://www.youtube.com/watch?v=xxxxxxxxxxx
 * @return Youtube id
 */
function getytid($url){

//checks if valid youtube link

$checkyt explode("."$url);

if (
$checkyt[1] == "youtube" ){

//gets vid id
$yt_start explode("v=",$url,2);
$yt_end explode("&",$yt_start[1],2);
$gotid $yt_end[0];
return 
$gotid;
}
}
/**
 * Gets Author from youtube id
 *
 * @param Youtube Id
 * @return $yt_author
 */
function getauthor($xml){
$yt_xml_author_start explode("<author>",$xml,2);
$yt_xml_author_end explode("</author>",$yt_xml_author_start[1],2);
$yt_author addslashes($yt_xml_author_end[0]);
return 
$yt_author;
}
/**
 * Gets Title from youtube id
 *
 * @param Youtube Id
 * @return $yt_title_noslash
 */
function gettitle($xml){
$yt_xml_title_start explode("<title>",$xml,2);
$yt_xml_title_end explode("</title>",$yt_xml_title_start[1],2);
$yt_title addslashes($yt_xml_title_end[0]);
$yt_title_noslash $yt_xml_title_end[0];
return 
$yt_title_noslash;
}

/**
 * Gets description from youtube id
 *
 * @param Youtube Id
 * @return $yt_description
 */
function getdescription($xml){
$yt_xml_description_start explode("<description>",$xml,2);
$yt_xml_description_end explode("</description>",$yt_xml_description_start[1],2);
$yt_description addslashes($yt_xml_description_end[0]);
return 
$yt_description;
}

/**
 * Gets Viewcount from youtube id
 *
 * @param Youtube Id
 * @return $yt_view_count
 *//*
function getviewcount($xml){
$yt_xml_view_count_start = explode("<view_count>",$xml,2);
$yt_xml_view_count_end = explode("</view_count>",$yt_xml_view_count_start[1],2);
$yt_view_count = $yt_xml_view_count_end[0];
return $yt_view_count;
}
*/
//check if its allready there

//$videourl is the input link eg http://www.youtube.com/watch?v=VflOBMTZiQw
//$videoid is the id that gets sorted in mysql for link above it is VflOBMTZiQw
$videoid_untrim getytid($videourl);
$videoid trim($videoid_untrim);  //removes whitespaces at the end

$xml = @file_get_contents("http://www.youtube.com/api2_rest?method=youtube.videos.get_details&dev_id=BnvzCjJ_Bzw&video_id=".$videoid);

if($videoid !== null){
$title  safe_sql_insert(gettitle($xml)); //Function to make the sql safe
$smarty->assign('title'$title);

$author safe_sql_insert(getauthor($xml));
$smarty->assign('author'$author);

$des    getdescription($xml);
$smarty->assign('description'$des);

$thumb[0]  = "http://img.youtube.com/vi/".$videoid."/1.jpg"; //Put as many as you need or just one
$thumb[1]  = "http://img.youtube.com/vi/".$videoid."/2.jpg";
$thumb[2]  = "http://img.youtube.com/vi/".$videoid."/3.jpg";
$smarty->assign('image'$thumb);
$smarty->assign('vidtype''YouTube');
$smarty->assign('videoid'$videoid);

}//check for blank end
 
?>