如何从“友好”网址获取vimeo id

时间:2013-05-04 06:14:05

标签: php ajax vimeo

众所周知,vimeo视频通常具有以下外观:

http://vimeo.com/123456

但昨天我看到,有些视频不同,就像这个:

https://vimeo.com/donialiechti/stranded

有趣的是,当您点击该链接时,您会在地址栏中看到

http://vimeo.com/64334084

此视频的嵌入代码为:

<iframe src="http://player.vimeo.com/video/64334084"... ></iframe>

问题是我的应用需要知道视频ID才能正常工作。 那么如何将“友好”的网址转换为常规的vimeo ID?

提前致谢!

3 个答案:

答案 0 :(得分:5)

Vimeo在HTTP标头中发送重定向信息,您可以像这样获取它们:

function fetch_vimeo_id($url) {
    $headers = get_headers($url);
    # Reverse loop because we want the last matching header,
    # as Vimeo does multiple redirects with your `https` URL
    for($i = count($headers) - 1; $i >= 0; $i--) {
        $header = $headers[$i];
        if(strpos($header, "Location: /") === 0) {
            return substr($header, strlen("Location: /"));
        }
    }
    # Could not find id
    return null;
}

echo fetch_vimeo_id("https://vimeo.com/donialiechti/stranded");

输出:

64334084

答案 1 :(得分:3)

解决此问题的更好方法是使用Vimeo's OEmbed API

video_id包含在响应中,它接受所有Vimeo可能的视频端点。

答案 2 :(得分:0)

检查下面的解决方案,它的工作原理。

即。 :

cluster@cluster0-vm:~$ sudo apt-get install g++
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 g++:i386 : Depends: cpp:i386 (>= 4:4.7.3-1ubuntu10) but it is not going to be installed
            Depends: gcc:i386 (>= 4:4.7.3-1ubuntu10) but it is not going to be installed
            Depends: g++-4.7:i386 (>= 4.7.3-1~) but it is not going to be installed
            Depends: gcc-4.7:i386 (>= 4.7.3-1~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

代码:

http://vimeo.com/11111111
http://player.vimeo.com/video/11111111
http://vimeo.com/channels/channelname/11111111
http://vimeo.com/groups/groupname/11111111