Note that there are some explanatory texts on larger screens.

plurals
  1. POGet direct link videos from Vimeo in PHP
    text
    copied!<p>I want a direct link to videos from Vimeo with a PHP script. I managed to find them manually, but my PHP script does not work. Here is the initiative: For example I took this video: <a href="http://vimeo.com/22439234" rel="noreferrer">http://vimeo.com/22439234</a></p> <p>When you go on the page, Vimeo generates a signature associated with the current timestamp and this video. This information is stored in a JavaScript variable, around line 520 just after: <code>window.addEvent ('domready', function () {</code></p> <p>Then when you click Play, the HTML5 player reads this variable and sends an HTTP request:</p> <pre><code>http:// player.vimeo.com/play_redirect?clip_id=37111719&amp;sig={SIGNATURE}&amp;time={TIMESTAMP}&amp;quality=sd&amp;codecs=H264,VP8,VP6&amp;type=moogaloop_local&amp;embed_location= </code></pre> <p>But it also works with:</p> <pre><code>http:// player.vimeo.com/play_redirect?clip_id=37111719&amp;sig={SIGNATURE}&amp;time={TIMESTAMP}&amp;quality=sd </code></pre> <p>If this URL does not open with the IP address that opened <a href="http://vimeo.com/22439234" rel="noreferrer">http://vimeo.com/22439234</a>, this returns the HTTP code 200 with an error message.</p> <p>If this URL is opened with the correct IP address, the header "Location" redirects to link to the video file: <code>http://av.vimeo.com/XXX/XX/XXXX.mp4?aksessionid=XXXX&amp;token=XXXXX_XXXXXXXXX</code></p> <p>When I build this link <code>http://player.vimeo.com/play_redirect?...</code> manually ("right click"> "source code"> "line 520") it works.</p> <p>But with PHP and regex it returns the <code>HTTP code 200</code> with an error message.</p> <p>Why ?</p> <p>From my observations, Vimeo does not check the headers of the HTTP request for <code>http:// player.vimeo.com/play_redirect?...</code> <code>GET</code>, <code>HEAD</code>, with cookies, without cookies, referrer etc. ... does not change.</p> <p>With PHP, I use the function <code>file_get_contents()</code> and <code>get_headers()</code>.</p> <pre><code> &lt;?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.'&amp;sig='.$signature.'&amp;time='.$timestamp.'&amp;quality=sd'; print_r(get_headers($url, 1)); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload