I need a direct link to a video from Vimeo with a PHP script. I managed to find them manually, but my PHP script is not working. Here is the initiative: For example, I took this video: http://vimeo.com/22439234
When you go to the page, Vimeo generates a signature associated with the current timestamp and this video. This information is stored in a JavaScript variable on line 520 immediately after: window.addEvent ('domready', function () {
Then, when you click Play, the HTML5 player reads this variable and sends an HTTP request:
http:// player.vimeo.com/play_redirect?clip_id=37111719&sig={SIGNATURE}&time={TIMESTAMP}&quality=sd&codecs=H264,VP8,VP6&type=moogaloop_local&embed_location=
But it also works with:
http:
If this URL does not open with the IP address that http://vimeo.com/22439234 has opened, it returns an HTTP 200 code with an error message.
If this URL is opened with the correct IP address, the Location header is redirected to the video link: http://av.vimeo.com/XXX/XX/XXXX.mp4?aksessionid=XXXX&token=XXXXX_XXXXXXXXX
When I create this link http://player.vimeo.com/play_redirect?... manually ("right click"> "source code"> "line 520"), it works.
But with PHP and regex, it returns an HTTP code 200 with an error message.
Why?
From my observations, Vimeo does not check the HTTP request headers for http:// player.vimeo.com/play_redirect?... GET , HEAD , with cookies, without cookies, referrer, etc ... does not change.
With PHP, I use the functions file_get_contents() and get_headers() .
<?php function getVimeo($id) { $content = file_get_contents('http://vimeo.com/'.$id); if (preg_match('#document\.getElementById\(\'player_(.+)\n#i', $content, $scriptBlock) == 0) return 1; preg_match('#"timestamp":([0-9]+)#i', $scriptBlock[1], $matches); $timestamp = $matches[1]; preg_match('#"signature":"([a-z0-9]+)"#i', $scriptBlock[1], $matches); $signature = $matches[1]; $url = 'http://player.vimeo.com/play_redirect?clip_id='.$id.'&sig='.$signature.'&time='.$timestamp.'&quality=sd'; print_r(get_headers($url, 1)); }