Last active
September 8, 2020 21:35
-
-
Save halgatewood/d33398f3b3185a862728 to your computer and use it in GitHub Desktop.
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
<?php | |
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 ); | |
} | |
} | |
// CREATE A PHP PAGE LIKE video.php FOR EXAMPLE | |
// THEN GO TO VIDEO video.php?v=ndk6yxO97k4 | |
header("Location: " . get_youtube_video_url( $_GET['v'] ) ); | |
die; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment