diff --git a/source/net/sourceforge/filebot/ui/rename/AudioFingerprintMatcher.java b/source/net/sourceforge/filebot/ui/rename/AudioFingerprintMatcher.java index fad4ac14..71c553b0 100644 --- a/source/net/sourceforge/filebot/ui/rename/AudioFingerprintMatcher.java +++ b/source/net/sourceforge/filebot/ui/rename/AudioFingerprintMatcher.java @@ -7,13 +7,16 @@ import static net.sourceforge.tuned.FileUtilities.*; import java.awt.Component; import java.io.File; +import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.Map.Entry; import net.sourceforge.filebot.similarity.Match; import net.sourceforge.filebot.web.AudioTrack; +import net.sourceforge.filebot.web.ID3Lookup; import net.sourceforge.filebot.web.MusicIdentificationService; import net.sourceforge.filebot.web.SortOrder; @@ -31,11 +34,28 @@ class AudioFingerprintMatcher implements AutoCompleteMatcher { @Override public List> match(List files, SortOrder order, Locale locale, boolean autodetection, Component parent) throws Exception { List> matches = new ArrayList>(); + List audioFiles = filter(files, AUDIO_FILES); // check audio files against acoustid - for (Entry it : service.lookup(filter(files, AUDIO_FILES)).entrySet()) { + for (Entry it : service.lookup(audioFiles).entrySet()) { if (it.getKey().exists() && it.getValue() != null) { - matches.add(new Match(it.getKey(), it.getValue().clone())); + AudioTrack track = it.getValue().clone(); + + // use AcoustID as default but prefer with ID3 data if available + if (!autodetection) { + AudioTrack id3 = new ID3Lookup().lookup(Collections.singleton(it.getKey())).get(it.getKey()); + for (Field field : AudioTrack.class.getDeclaredFields()) { + if (!field.isAccessible()) { + field.setAccessible(true); + } + Object id3value = field.get(id3); + if (id3value != null && !id3value.toString().isEmpty()) { + field.set(track, id3value); + } + } + } + + matches.add(new Match(it.getKey(), track)); } }