Skip to content

Instantly share code, notes, and snippets.

@danieltroger
Created February 1, 2017 22:20
Show Gist options
  • Save danieltroger/9e5f9bb7acd6578f989a8b746f61a5cd to your computer and use it in GitHub Desktop.
Save danieltroger/9e5f9bb7acd6578f989a8b746f61a5cd to your computer and use it in GitHub Desktop.
Download embedded vimeo video (halfautomatic)
<?php
/*
Copyright (c) 2017 Daniel Troger
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// variables u get from the inspector console thingy (network tab) and some files you save then
$maserjson = "/tmp/master.json"; // file where you saved the master.json you saw in the networking tab
$segment_base_url = "https://60skyfiregce-vimeo.akamaized.net/exp=nnnnnnnnnn~acl=%2Fnnnnnnnnnn%2F%2A~hmac=nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn/nnnnnnn/video/";
// url from first segment which starts loading when you press play. Remove everything that comes after /video/. n means some numbers or characters, length not exact
// load json
$json = json_decode(file_get_contents($masterjson));
// localize largest video object
$vids = $json->video;
$video = $vids[0];
foreach($vids as $vid){
if($video->width < $vid->width)
{
$video = $vid;
}
}
// define some vars
$init_segment = base64_decode($video->init_segment);
$segment_base = $segment_base_url . $video->base_url;
$downloaded_segments = Array();
// open output file
$f = fopen("output.mp4","a");
// write video header
fwrite($f,$init_segment);
// download segment and append to file
foreach($video->segments as $segment)
{
$fnam = $segment->url;
$dlurl = $segment_base . $fnam;
echo "Downloading {$dlurl}..." . PHP_EOL;
download($dlurl,$f);
}
fclose($f);
function download($url,$f)
{
$ch = curl_init( $url);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_HEADER, false );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_FILE, $f);
curl_setopt( $ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt( $ch, CURLOPT_USERAGENT, "NUTS (1.0)");
curl_exec( $ch );
curl_close( $ch );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment