Skip to content

Instantly share code, notes, and snippets.

@halgatewood
Last active August 29, 2015 14:15
Show Gist options
  • Save halgatewood/d04d62c4128fc7361229 to your computer and use it in GitHub Desktop.
Save halgatewood/d04d62c4128fc7361229 to your computer and use it in GitHub Desktop.
Get the streaming video (mp4) for your public YouTube videos. -- Download YouTube videos PHP script.
function get_youtube_video_url( $youtube_id )
{
$data = trim(urldecode(file_get_contents('https://youtube.com/get_video_info?video_id=' . $youtube_id)));
$d = parse_str($data, $info);
$stream_map = trim($info['url_encoded_fmt_stream_map']);
if( !$stream_map ) return false;
if( substr( $stream_map, 0, 4 ) != "url=" )
{
return get_youtube_video_url( $youtube_id );
}
else
{
return substr( $stream_map, 4 );
}
}
$video_url = get_youtube_video_url('ndk6yxO97k4');
// RETURNS DIRECT LINK TO googlevideo.com/videoplayback VIDEO
@halgatewood
Copy link
Author

I've contacted YouTube Developers through Twitter to see if this is against the terms of service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment