Last active
August 29, 2015 14:15
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've contacted YouTube Developers through Twitter to see if this is against the terms of service.