5

I try to get the id video from an url of vimeo, but looking in the source code sometimes it comes like:

http://vimeo.com/XXXXXXXXX

and others like:

http://player.vimeo.com/video/XXXXXXXXX

I just get the id video, but it must be with regExp because I must parse a content from a blog and format like a facebook page does when we insert code html.

This is the regExp that I made:

/vimeo\.com\/(\w+\s*\/?)*([0-9]+)*$/i

Can you help me? I appreciate all your help.

PD: Sorry for my english

4

3 回答 3

22

为什么不向 Vimeo询问视频?

http://vimeo.com/api/oembed.json?url=http%3A//vimeo.com/17892962

上面的 URL 将为您提供一个很好的 JSON 响应,其中包含许多有用的信息,包括视频 ID 和用于将视频嵌入页面的适当 HTML。只需将您的 URL 传递给 oEmbed 端点,如上所示。

示例 JSON 响应(为了显示目的截断长行)

{
    "type": "video",
    "version": "1.0",
    "provider_name": "Vimeo",
    "provider_url": "http://vimeo.com/",
    "title": "Danny MacAskill - \"Way Back Home\"",
    "author_name": "Dave Sowerby",
    "author_url": "http://vimeo.com/tdave",
    "is_plus": "1",
    "html": "<iframe src=\"http://player.vimeo.com/video/17892962\" …",
    "width": 1280,
    "height": 720,
    "duration": 462,
    "description": "A journey from Edinburgh to Skye where Danny finds …",
    "thumbnail_url": "http://b.vimeocdn.com/ts/399/121/399121670_1280.jpg",
    "thumbnail_width": 1280,
    "thumbnail_height": 720,
    "video_id": 17892962
}

有关完整信息,请参阅他们的oEmbed 文档

于 2013-06-17T21:04:23.610 回答
3

http://(player\.)?vimeo\.com(/video)?/(\d+)涵盖了您的两个示例,尽管我确信它可以在给定更多 URL 的情况下进行优化。

于 2013-06-17T20:34:40.177 回答
0

这应该工作:vimeo\.com/(\w*/)*(\d+). (\w/)* 让您拥有类似 vimeo.com/video/something/something-more/more-more-more/XXXXXXXXX 这样的 URL,没有任何问题。然后你可以通过获得第二个地面(\d+)来抓住 XXXXXXXX。如果您知道视频 id 有多少位数,您可以将 \d+ 替换为 \d{n} ,其中 n 是位数。

于 2013-06-17T20:43:14.953 回答