Skip to content

Instantly share code, notes, and snippets.

@kategray
Created June 5, 2015 07:58
Show Gist options
  • Save kategray/2fce6bd38796142bfb2d to your computer and use it in GitHub Desktop.
Save kategray/2fce6bd38796142bfb2d to your computer and use it in GitHub Desktop.
Do not so nice things to VEVO
<?php
// Target video to get
$video_id = 'USCJY1531563'; // http://www.vevo.com/watch/taylor-swift/Bad-Blood/USCJY1531563
define ('API_URI', 'https://apiv2.vevo.com/video/%s?token=%s');
define ('STREAM_URI', 'https://apiv2.vevo.com/video/%s/streams/%s?token=%s');
// They blacklist certain user agents, so pretend to be my Mac
define ('USER_AGENT', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36');
$curl = curl_init ();
curl_setopt ($curl, CURLOPT_USERAGENT, USER_AGENT);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl, CURLOPT_REFERER, 'http://www.vevo.com/');
// Get an auth token
curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_URL, 'http://www.vevo.com/auth');
curl_setopt ($curl, CURLOPT_POSTFIELDS, '{}');
$tokens = json_decode (curl_exec ($curl), TRUE);
if (!$tokens || !isset ($tokens['access_token'])) {
exit ("Yeah, this isn't working.\n");
}
// Make the API call
$api_uri = sprintf (API_URI, $video_id, $tokens['access_token']);
curl_setopt ($curl, CURLOPT_POST, 0);
curl_setopt ($curl, CURLOPT_URL, $api_uri);
$metadata = json_decode (curl_exec ($curl), TRUE);
echo "Metadata: \n";
var_export ($metadata);
// Get the HLS streams
$stream_uri = sprintf (STREAM_URI, $video_id, 'hls', $tokens['access_token']);
curl_setopt ($curl, CURLOPT_URL, $stream_uri);
$hls_streams = json_decode (curl_exec ($curl), TRUE);
echo "\n\nHLS Streams: \n";
var_export ($hls_streams);
// Get the MP$ streams
$stream_uri = sprintf (STREAM_URI, $video_id, 'mp4', $tokens['access_token']);
curl_setopt ($curl, CURLOPT_URL, $stream_uri);
$mp4_streams = json_decode (curl_exec ($curl), TRUE);
echo "\n\nMP4 Streams: \n";
var_export ($mp4_streams);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment