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 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
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 ( ) )
Output for 8.0.13 - 8.0.30
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo 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 failed: System error in /in/JfrSU on line 28 Array ( [MP4] => Array ( ) [FLV] => Array ( ) [3GP] => Array ( ) [WEBM] => Array ( ) )
Output for 8.0.0 - 8.0.12
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution 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 failed: Temporary failure in name resolution in /in/JfrSU on line 28 Array ( [MP4] => Array ( ) [FLV] => Array ( ) [3GP] => Array ( ) [WEBM] => Array ( ) )
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.26, 7.3.0 - 7.3.13, 7.3.32 - 7.3.33, 7.4.0 - 7.4.1, 7.4.26 - 7.4.33
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo 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 failed: System error in /in/JfrSU on line 28 Array ( [MP4] => Array ( ) [FLV] => Array ( ) [3GP] => Array ( ) [WEBM] => Array ( ) )
Output for 7.2.29 - 7.2.33, 7.3.16 - 7.3.31, 7.4.3 - 7.4.25
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution 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 failed: Temporary failure in name resolution in /in/JfrSU on line 28 Array ( [MP4] => Array ( ) [FLV] => Array ( ) [3GP] => Array ( ) [WEBM] => Array ( ) )

preferences:
281.75 ms | 403 KiB | 376 Q