Scala

Scala MP3 Sorter

Sunday, April 15th, 2012

So over at MITB all of us cool kids rehashed the same shitty mp3 sorting program in multiple languages. here is mine in SCALA

 

package mp3sorter
import java.io.File;
import java.io.FileInputStream;
object MP3Sort {
 
  /**
   *Simple MP3 sorting application translated from C to C# to Java to Jython to Scala
   *By Silabsoft and all those prior.
   * @param args the command line arguments
   */
  def main(args: Array[String]): Unit = {
    if(args.length < 2){
      println("USAGE: MP3Sort [source] [destination]");
      return;
    }
    val source : File = new File(args(0));
    val destination : File = new File(args(1));
    var mp3List : List[MP3File] = Nil;
    if(!source.isDirectory || !source.canRead){
      println("Please check the source path");
      return;
    }
    for (file  "INVALID"
      }
    };
    def getYearTitle = {
      try{
        year.toInt+" - ";
      }catch{
        case e: Exception => ""
      }
    }
    def getAlbum = album;
    def getTitle = title;
    def getFileName = title+".mp3";
    def getFile : File = file;
    def isValid = valid;
 
    override def toString = artist + " - " + title + " (" + getYear + ", " + album + ")";   
 
    // could use some more valudation checking but I'm lazy and noone else bothered.'
    def parseTags = {
      try{
        val buffer :Array[Byte] = new Array(128);
        val fis : FileInputStream = new FileInputStream(file);
        fis.skip(this.file.length() - buffer.length);
        fis.read(buffer, 0, buffer.length);
 
        for(i  valid = false;
      }
    };
  }
 
}