tagging problem?

This commit is contained in:
openaudible 2018-06-30 12:13:53 -07:00
parent 319f49b709
commit 09a0f9e020
2 changed files with 36 additions and 21 deletions

View file

@ -13,6 +13,7 @@ import org.openaudible.util.queues.IQueueJob;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
@ -29,6 +30,7 @@ public class ConvertJob implements IQueueJob, LineListener {
private IProgressTask progress;
final String duration;
final static int mp3Qscale = 6; // audio quality value 0 to 9. See https://trac.ffmpeg.org/wiki/Encode/MP3
static boolean addAdditionalTags = true;
public ConvertJob(Book b) {
book = b;
@ -207,13 +209,19 @@ public class ConvertJob implements IQueueJob, LineListener {
public void tagMP3() throws Exception {
TagMP3AudioBook.setMP3Tags(book, temp, image);
if (addAdditionalTags)
TagMP3AudioBook.setMP3Tags(book, temp, image);
}
public void renameMP3() throws IOException {
boolean ok = temp.renameTo(mp3);
if (!ok) {
throw new IOException("Error renaming: " + temp.getAbsolutePath() + " to " + mp3.getAbsolutePath());
mp3.delete();
Files.copy(temp.toPath(), mp3.toPath());
temp.delete();
if (!mp3.exists())
throw new IOException("Error renaming: " + temp.getAbsolutePath() + " size ["+temp.length()+"] to " + mp3.getAbsolutePath()+" mp3 exists="+mp3.exists());
}
}
@ -235,6 +243,7 @@ public class ConvertJob implements IQueueJob, LineListener {
if (progress != null)
progress.setTask(null, "Complete");
} catch (Exception e) {
LOG.error("Error converting book:"+book, e);
if (progress != null) {
progress.setSubTask(e.getMessage());
}

View file

@ -33,29 +33,35 @@ public class TagMP3AudioBook {
// replaces any existing mp3 tags with new tags from the book meta data.
public static void setMP3Tags(Book book, File bookMP3File, File imageFile) throws Exception {
MP3File mp3file = new MP3File(bookMP3File.getAbsolutePath());
ID3v24Tag tag = new ID3v24Tag();
mp3file.setID3v2Tag(tag);
try {
ID3v24Tag tag = new ID3v24Tag();
mp3file.setID3v2Tag(tag);
tag.addField(tag.createField(ID3v24FieldKey.GENRE, book.getGenre()));
tag.addField(tag.createField(ID3v24FieldKey.ARTIST, book.getAuthor()));
tag.addField(tag.createField(ID3v24FieldKey.COMPOSER, book.getNarratedBy()));
tag.addField(tag.createField(ID3v24FieldKey.TITLE, book.getFullTitle()));
tag.addField(tag.createField(ID3v24FieldKey.AMAZON_ID, book.getAsin()));
tag.addField(tag.createField(ID3v24FieldKey.URL_OFFICIAL_RELEASE_SITE, "https://www.audible.com" + book.getInfoLink()));
tag.addField(tag.createField(ID3v24FieldKey.RECORD_LABEL, book.getPublisher()));
tag.addField(tag.createField(ID3v24FieldKey.COMMENT, book.getSummary()));
tag.addField(tag.createField(ID3v24FieldKey.CATALOG_NO, book.getProduct_id()));
tag.addField(tag.createField(ID3v24FieldKey.ENCODER, book.getCopyright()));
tag.addField(tag.createField(ID3v24FieldKey.GENRE, book.getGenre()));
tag.addField(tag.createField(ID3v24FieldKey.ARTIST, book.getAuthor()));
tag.addField(tag.createField(ID3v24FieldKey.COMPOSER, book.getNarratedBy()));
tag.addField(tag.createField(ID3v24FieldKey.TITLE, book.getFullTitle()));
tag.addField(tag.createField(ID3v24FieldKey.AMAZON_ID, book.getAsin()));
tag.addField(tag.createField(ID3v24FieldKey.URL_OFFICIAL_RELEASE_SITE, "https://www.audible.com" + book.getInfoLink()));
tag.addField(tag.createField(ID3v24FieldKey.RECORD_LABEL, book.getPublisher()));
tag.addField(tag.createField(ID3v24FieldKey.COMMENT, book.getSummary()));
tag.addField(tag.createField(ID3v24FieldKey.CATALOG_NO, book.getProduct_id()));
tag.addField(tag.createField(ID3v24FieldKey.ENCODER, book.getCopyright()));
tag.addField(tag.createField(ID3v24FieldKey.ALBUM, book.getShortTitle()));
tag.addField(tag.createField(ID3v24FieldKey.YEAR, AudibleUtils.getYear(book)));
tag.addField(tag.createField(ID3v24FieldKey.ALBUM, book.getShortTitle()));
tag.addField(tag.createField(ID3v24FieldKey.YEAR, AudibleUtils.getYear(book)));
if (imageFile.exists()) {
byte imageBytes[] = Files.readAllBytes(Paths.get(imageFile.getAbsolutePath()));
tag.addField(tag.createArtworkField(imageBytes, "image/jpeg"));
}
mp3file.commit();
mp3file.save();
} catch(Throwable th)
{
if (imageFile.exists()) {
byte imageBytes[] = Files.readAllBytes(Paths.get(imageFile.getAbsolutePath()));
tag.addField(tag.createArtworkField(imageBytes, "image/jpeg"));
}
mp3file.commit();
mp3file.save();
}
public static void debugTags(File f) throws CannotReadException, IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException {