【问题标题】:is there a faster way to get a YouTube clip's title than this?有没有比这更快的方法来获取 YouTube 剪辑的标题?
【发布时间】:2011-03-15 19:19:03
【问题描述】:

目前我正在使用以下内容,这对于多个剪辑来说似乎很慢:

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;
    }

有没有比这更有效的方法来使用 php 一次处理 5-10 个剪辑?

【问题讨论】:

    标签: php xml api youtube


    【解决方案1】:

    是的。

    • 获得更快的服务器。
    • 分钟,但清理你的代码

      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;
      }
      

    使用 JSON 供稿:http://gdata.youtube.com/feeds/api/videos/?alt=json,将 ?alt=json 附加到 URI

    【讨论】:

    • 很可能,这不是真的。他试图做的事情并不需要太多的计算能力。消耗的时间最多的是网络 i/o。可能有帮助的事情是:将您的服务器移近 gdata 服务器,或者可能有一种更易于解析的请求格式。除此之外,您无能为力。
    • 当我说更快的服务器时,我是在谈论连接速度,当涉及到代码时有点讽刺,只是清除了不需要的变量。
    • 如果他们有像 json 这样的不那么冗长的格式也可能会有所帮助? (通过网络发送的数据更少?)
    【解决方案2】:

    如果您对相同的剪辑 ID 执行此操作很多,您可以将结果缓存在您的服务器上。

    【讨论】:

      【解决方案3】:

      我认为没有。 据我所知,这是获取此类元数据的推荐方法。

      我还能想到另一件事,那就是从 youtube.com 上抓取 html,我几乎可以向您保证,它不会更快,而且肯定不可靠。

      【讨论】:

      • 哈哈,是的,抓取速度非常慢,就像你提到的那样痛苦!
      • 会使用 curl 来快速检索 xml 帮助吗?那么只需将 xml 解析为字符串?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-09
      • 2019-10-17
      • 2015-02-10
      • 1970-01-01
      • 1970-01-01
      • 2021-01-17
      • 1970-01-01
      相关资源
      最近更新 更多