Created
August 11, 2018 17:09
-
-
Save ennjoy/ef871f36aca2a5904ccd143b4ebca637 to your computer and use it in GitHub Desktop.
get url video youtube
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 getVideoUrl($id) { | |
$formats = array('18', '22', '37', '38'); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, 'http://www.youtube.com/get_video_info?video_id=' . $id); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$links = curl_exec($ch); | |
curl_close($ch); | |
parse_str($links, $info); | |
if ($info["status"] == 'fail') { | |
$video_array[] = ''; | |
return; | |
} | |
$res = explode(',', $info['url_encoded_fmt_stream_map']); | |
foreach ($res as $k => $v) { | |
parse_str($v, $rr); | |
if (in_array($rr['itag'], $formats)) { | |
$video_array[] = urldecode($rr['url']); | |
} | |
} | |
return $video_array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment