Search in sources :

Example 1 with NotSupportedException

use of com.mpatric.mp3agic.NotSupportedException in project selenium_java by sergueik.

the class DefaultId3vTagManager method fix.

@SneakyThrows
@Override
public File fix(File source) {
    Mp3File mp3File = new Mp3File(source);
    mp3File.removeCustomTag();
    if (mp3File.hasId3v1Tag()) {
        ID3v1 tag = mp3File.getId3v1Tag();
        tag.setArtist(fixString(tag.getArtist()));
        tag.setTitle(fixString(tag.getTitle()));
        tag.setAlbum(fixString(tag.getAlbum()));
        tag.setComment(fixString(tag.getComment()));
        mp3File.setId3v1Tag(tag);
    }
    if (mp3File.hasId3v2Tag()) {
        ID3v2 tag = mp3File.getId3v2Tag();
        tag.setArtist(fixString(tag.getArtist()));
        tag.setTitle(fixString(tag.getTitle()));
        tag.setAlbum(fixString(tag.getAlbum()));
        tag.setComment(fixString(tag.getComment()));
        mp3File.setId3v2Tag(tag);
    }
    String filename = source.toString() + "_fixed.mp3";
    try {
        mp3File.save(filename);
    } catch (NotSupportedException e) {
        mp3File.removeId3v2Tag();
        mp3File.save(filename);
    }
    return new File(filename);
}
Also used : ID3v2(com.mpatric.mp3agic.ID3v2) Mp3File(com.mpatric.mp3agic.Mp3File) ID3v1(com.mpatric.mp3agic.ID3v1) NotSupportedException(com.mpatric.mp3agic.NotSupportedException) Mp3File(com.mpatric.mp3agic.Mp3File) File(java.io.File) SneakyThrows(lombok.SneakyThrows)

Aggregations

ID3v1 (com.mpatric.mp3agic.ID3v1)1 ID3v2 (com.mpatric.mp3agic.ID3v2)1 Mp3File (com.mpatric.mp3agic.Mp3File)1 NotSupportedException (com.mpatric.mp3agic.NotSupportedException)1 File (java.io.File)1 SneakyThrows (lombok.SneakyThrows)1