[Frubar Paste] Hosted by SkyLime - Chat with us at XChannel IRC

Posted by zantekk on Thu 16th Aug 21:32
download

  1. #!/usr/bin/php
  2. <?php
  3.   echo "(c) 2012 Kataklysmos <kataklysmos@shitstorm.in>\n";
  4.   echo "fixed 08/16/2012 by zantekk <zantekk@gmail.com>\n";
  5.   echo "yt2mp3 - Converter 1.1\n\n";
  6.  
  7.   if(!isset($argv[1]) || !isset($argv[2]))
  8.     exit($argv[0]." <YT- URL> <FILE.MP3> [--no-hd]\n\n");
  9.  
  10.   echo "Downloading YouTube Code..\n";
  11.   $code = file_get_contents($argv[1]);
  12.  
  13.   echo "Checking possible quality..\n";
  14.   $quality = '';
  15.   if(!isset($argv[3]) || $argv[3] != '--no-hd')
  16.   {
  17.     if(strstr($code, 'quality=hd1080'))
  18.       $quality = '%3Dhd1080';
  19.     elseif(strstr($code, 'quality=hd720'))
  20.       $quality = '%3Dhd720';
  21.   }
  22.  
  23.   if(!preg_match_all('/o-o---preferred(.*?)%26quality'.$quality.'/',  $code , $m))
  24.     exit("Could not extract Video- URL!\n\n");
  25.   echo "Extracting Video- URL..\n";
  26.   $url = 'http://o-o---preferred'.urldecode(urldecode($m[1][count($m[1]) - 1]));
  27.   $url = str_replace('&', '?', $url);
  28.  
  29.   echo "Grabbing Video..\n";
  30.   $video = tempnam(sys_get_temp_dir(), 'ytvid');
  31.   if(!$h = fopen($video, 'w'))
  32.     exit("Could not open temporary file (".$video.")!\n\n");
  33.   if(!$dl = fopen($url, 'r'))
  34.     exit("Could not download video!\n\n");
  35.   while(!feof($dl))
  36.     if(!fwrite($h, fgets($dl, 1024)))
  37.       exit("Could not write temporary file (".$video.")!\n\n");
  38.   fclose($dl);
  39.   fclose($h);
  40.  
  41.   echo "Convert to MP3:\n";
  42.   shell_exec('ffmpeg -i '.$video.' -vn -ar 44100 -ac 2 -ab 192k '.$argv[2]);
  43.  
  44.   echo "Removing temporary file..\n";
  45.   if(!unlink($video))
  46.     echo "Could not delete temporary file (".$video.")!\n";
  47.  
  48.   echo "File written!\n".$argv[2]."\n\n";
  49. ?>


Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.



Remember my name in a cookie


Code: To highlight particular lines, prefix each line with @@.
Include comments to indicate what you need feedback on.