tags:

views:

50

answers:

3

Currently i'm using the following, which seems quite slow for multiple clips:

static function get_yt_title($clip_id){    
    $feedURL = 'http://gdata.youtube.com/feeds/api/videos/' . $clip_id;
    $entry = @simplexml_load_file($feedURL);
    if($entry){
        $video= new stdClass;
        $media = $entry->children('http://search.yahoo.com/mrss/');
        $video->title = ucwords(strtolower($media->group->title));
        return $video->title;   
    }
    else{
        return FALSE;
    }

any more efficient methods than this for doing 5-10 clips at a time with php?

A: 

I don't think there is. As far as i can tell this is the recommended way to get meta data like that.

There's one other thing I can think of and that is scraping the html off of youtube.com, i can almost guarantee you it isn't faster and sure as hell isn't reliable.

Dennis Haarbrink
haha, yeah scraping is seriously slow and like you mentioned a pain to sustain!
Haroldo
would using curl to retrieve the xml help with the speed? then just parse the xml as a string?
fire
A: 

Yes.

  • Get a faster server.
  • Minute, but clean your code

    static function get_yt_title($clip_id)
    {
        $entry = @simplexml_load_file('http://gdata.youtube.com/feeds/api/videos/' . $clip_id);
        return ($entry) ? ucwords(strtolower($entry->children('http://search.yahoo.com/mrss/')->group->title)) : false;
    }
    

Use JSON Feeds: http://gdata.youtube.com/feeds/api/videos/?alt=json by appending the ?alt=json to the URI

RobertPitt
Most likely, that's just not true. There is not much computational power needed for what he tries to do. The most time consumed is in network i/o. Things that might help are: move your server closer to the gdata server or maybe there's a request format that is easier to parse. Besides that, there is nothing much you can do.
Dennis Haarbrink
When I said faster server, I was talking relative to connection speeds, and was being slightly sarcastic when it comes down to the code, just cleaned out the variables that was not really required.
RobertPitt
Also might help if they have a less verbose format available like json? (less data to send over the wire?)
Svish
yes i was surprised the api doesnt seem to use json?
Haroldo
Read my post again :)
RobertPitt
thanks Robert - will look into that
Haroldo
A: 

If you do this a lot for the same clip id's you could cache the results on your server.

Anders S