Print Curl Verbose Info on the web browser in php

By default, the CURLOPT_VERBOSE option will print verbose info to the stderr stream. If you want to print the verbose info to the stdout stream and make it visible to the web browser it’s easy:


			  curl_setopt($hCurl, CURLOPT_STDERR, fopen('php://output', 'w+'));
			  curl_setopt($hCurl, CURLOPT_VERBOSE, 1);

Download a whole youtube playlist to your computer in php.

I don’t know if I should be sharing this code snippet, but this is just too cool!

  1. Get the code from the links on this page:
  2. Append this hack at the bottom of the php code:
$watch_ids	=	array();
$url = "";
$plyst	=	file_get_contents("");
$matchall	=	preg_match_all('/<li class="playlist-video-item[^>]+>([\s\S]*?)<\/li>/', $plyst, $matches);

$info		=	preg_match_all('/<span class="title video-title "[^>]+>([^<]+)/', $plyst, $desc);

#var_dump($desc, $matches);exit;
for($i = 0; $i < $matchall ; $i++)
  preg_match('/watch\?v=([a-zA-Z0-9]+)/', $matches[1][$i], $id);
  $id	=	$id[1];

  $itemurl	=	sprintf($url, $id);
  $itemdesc	=	preg_replace('/[^A-Za-z0-9\s\.]+/', '', $desc[1][$i]);

  $filename	=	"$itemdesc.flv";
  if(file_exists($filename)) continue;

  echo "Fetching: " , $itemdesc, "\n";
  $youtubegrabber = new youtubegrabber($itemurl, $filename, 0);

3. modify and enjoy

Bonus: Add this to the options in the get_curl_binary method to get download progress info.

        curl_setopt($ch, CURLOPT_NOPROGRESS, FALSE);