package com.itstherules.stream.model;
import java.io.File;
import org.blinkenlights.jid3.ID3Exception;
import org.blinkenlights.jid3.MP3File;
import org.blinkenlights.jid3.v1.ID3V1Tag;
import org.blinkenlights.jid3.v1.ID3V1_0Tag;
import org.blinkenlights.jid3.v1.ID3V1Tag.Genre;
public class Mp3 implements IMp3 {
private ID3V1Tag tag1;
private final String fileName;
private final String subDirectory;
private final String rootDirectory;
public Mp3(File file) {
this.fileName = file.getName();
File sub = oneUp(file);
this.subDirectory = sub.getName();
this.rootDirectory = oneUp(sub).getName();
MP3File mp3File = new MP3File(file);
try {
tag1 = mp3File.getID3V1Tag();
if(tag1==null){
tag1 = new ID3V1_0Tag();
}
} catch (ID3Exception e) {
tag1 = new ID3V1_0Tag();
}
}
private File oneUp(File file){
return new File(file.getParent());
}
public String getRootDirectory(){
return rootDirectory;
}
public String getSubDirectory(){
return subDirectory;
}
public String getName() {
return fileName;
}
public String getAlbum() {
return guard(tag1.getAlbum());
}
private String guard(String string) {
if(string==null) return "";
return string;
}
public String getArtist() {
return guard(tag1.getArtist());
}
public String getComment() {
return guard(tag1.getComment());
}
public String getGenre() {
Genre genre = tag1.getGenre();
if(genre!=null) return genre.toString();
return "";
}
public String getTitle() {
return guard(tag1.getTitle());
}
public String getYear() {
return guard(tag1.getYear());
}
public String getFull() {
String name = getRootDirectory()+"/"+getSubDirectory()+"/"+getName();
return name;
}
@Override
public String toString() {
return getFull();
}
}