Перекуём обезьян на пушки · Заметки

Буду краток. Monkey Audio сакс: коммерческий протокол, коммерческое ПО, жрёт много проца (декодирование занимает больше времени, чем кодирование в FLAC!) Да ещё и не играется в mplayer и Amarok. Но виндузятники его любят. Поэтому изготовил такой скрипт для перегона MAC (.ape) в FLAC, как обычно, на PHP, потому что на всякие перлы у меня моск с большим трудом переключается.

·· [Continuing] ··

#!/usr/bin/php -Cq
<?php

  echo "Monkey Audio to FLAC converter by Sergey A. Galin. http://sageshome.net/\n";

  if($argc<5) 
    die("USAGE: $argv[0] artist album year files...\n");
  
  $artist=$argv[1];
  $album=$argv[2];
  $year=$argv[3];
  
  echo "ARTIST: $artist\n",
       "ALBUM:  $album\n",
       "YEAR:   $year\n";
  sleep(2);       
       
  function fn2name($noext){   
    $noext=str_replace("_", " ", $noext);
    
    if(strlen($noext>3) && ctype_digit($noext{0}) && ctype_digit($noext{1}) && $noext{2}=="-")
      $noext=substr($noext, 3);
    
    $parts=explode(" ", $noext, 2);
    if(sizeof($parts)>1) 
      if(strval(intval($parts[0]))==strval($parts[0]) || $parts[0]=="00")
        $noext=$parts[1];
    return trim($noext);
  }

  for($i=4; $i<$argc; $i++){
  
    $fn=$argv[$i];
    
    echo "Processing \"$fn\"...\n";
    
    $dot=strrpos($fn, ".");
    if(!$dot) die("ERROR: Filename extension not detected!\n");
    
    $noext=trim(substr($fn, 0, $dot));
    $track=fn2name($noext);
    echo "Track name: \"$track\"\n";    
    $oldext=strtolower(substr($fn, $dot+1));
    if($oldext!="ape") die("ERROR: Filename extension is not '.ape'!\n");
    $wav=$noext.".wav";
    echo "Wav name: \"$wav\"\n";
    if(file_exists($wav)) die("Wav file already exists!\n");
    if(file_exists($noext."flac")) die("FLAC file already exists!\n");
    if(file_exists($noext."mp3")) die("MP3 file already exists!\n");
    $cmd1="nice -n19 mac \"$fn\" \"$wav\" -d";
    echo "Decompressing: $cmd1\n";
    echo `$cmd1`;

    $cmd2="nice -n19 flac \"--tag=title=$track\" \"--tag=artist=$artist\" \"--tag=album=$album\" \"--tag=date=$year\" --best \"$wav\"";
    echo "Compressing FLAC: $cmd2\n";
    echo `$cmd2`;
    
    // Uncomment the 3 lines below for MP3 encoding    
//   $cmd3="nice -n19 lame -q 9 --cbr -b 320 -k -m s --tt \"$track\" --ta \"$artist\" --tl \"$album\" --ty \"$year\" \"$wav\" \"$noext.mp3\"";
//   echo "Compressing MP3: $cmd3\n";
//   echo `$cmd3`;
    
    echo "Deleting wav file...\n";
    unlink($wav);
        
  }
  echo "I'm done with it.\n";

?>




Comments:

No Comments for this post yet...

Leave a comment:

Your email address will not be displayed on this site.
Your URL will not be displayed on this site. Comments containing URL's of non-personal pages may be removed.
Confirmation Code:
Human Confirmation Code (Captcha)

HTML tags and "<", ">" symbols are not allowed. Links will not be converted to hyperlinks. Any commercials are removed and reported as abuse.

Archives

                                                                                                                                                                                                                                                                   


© Sergey A. Galin, 1998-2021 sageshome.net/blog/