3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Youtube{ private $videoMap = array( "13" => array("3GP", "Low Quality - 176x144"), "17" => array("3GP", "Medium Quality - 176x144"), "36" => array("3GP", "High Quality - 320x240"), "5" => array("FLV", "Low Quality - 400x226"), "6" => array("FLV", "Medium Quality - 640x360"), "34" => array("FLV", "Medium Quality - 640x360"), "35" => array("FLV", "High Quality - 854x480"), "43" => array("WEBM", "Low Quality - 640x360"), "44" => array("WEBM", "Medium Quality - 854x480"), "45" => array("WEBM", "High Quality - 1280x720"), "18" => array("MP4", "Medium Quality - 480x360"), "22" => array("MP4", "High Quality - 1280x720"), "37" => array("MP4", "High Quality - 1920x1080"), "38" => array("MP4", "High Quality - 4096x230") ); private $videoPageUrl = 'http://www.youtube.com/watch?v='; protected function getPageContent($id){ $page = $this->videoPageUrl.$id; $content = file_get_contents($page); return $content; } function getDownloadLinks($id){ $content = $this->getPageContent($id); $videos = array('MP4' => array(), 'FLV' => array(), '3GP' => array(), 'WEBM' => array()); if(preg_match('/"url_encoded_fmt_stream_map": "(.*)"/iUm', $content, $r)){ $data = $r[1]; $data = explode(',', $data); foreach($data As $cdata){ $cdata = str_replace('u0026', '&', $cdata); $cdata = explode('&', $cdata); foreach($cdata As $xdata){ if(preg_match('/^sig/', $xdata)){ $sig = substr($xdata, 4); } if(preg_match('/^url/', $xdata)){ $url = substr($xdata, 4); } if(preg_match('/^itag/', $xdata)){ $type = substr($xdata, 5); } } $url = urldecode($url).'&signature='.$sig; $videos[$this->videoMap[$type][0]][$this->videoMap[$type][1]] = $url; } } return $videos; } } $youtube = new Youtube(); $download_links = $youtube->getDownloadLinks('q_gfD3nvh-8'); print_r($download_links);
Output for git.master, git.master_jit, rfc.property-hooks
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo for www.youtube.com failed: System error in /in/JfrSU on line 28 Warning: file_get_contents(http://www.youtube.com/watch?v=q_gfD3nvh-8): Failed to open stream: php_network_getaddresses: getaddrinfo for www.youtube.com failed: System error in /in/JfrSU on line 28 Array ( [MP4] => Array ( ) [FLV] => Array ( ) [3GP] => Array ( ) [WEBM] => Array ( ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
61.04 ms | 402 KiB | 8 Q