diff --git a/source/net/filebot/ui/rename/AudioFingerprintMatcher.java b/source/net/filebot/ui/rename/AudioFingerprintMatcher.java index 71d70a9a..0f4af82c 100644 --- a/source/net/filebot/ui/rename/AudioFingerprintMatcher.java +++ b/source/net/filebot/ui/rename/AudioFingerprintMatcher.java @@ -6,9 +6,10 @@ import static net.filebot.util.FileUtilities.*; import java.awt.Component; import java.io.File; import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; -import java.util.Map.Entry; import net.filebot.similarity.Match; import net.filebot.web.AudioTrack; @@ -17,25 +18,25 @@ import net.filebot.web.SortOrder; class AudioFingerprintMatcher implements AutoCompleteMatcher { - private MusicIdentificationService service; + private MusicIdentificationService[] services; - public AudioFingerprintMatcher(MusicIdentificationService service) { - this.service = service; + public AudioFingerprintMatcher(MusicIdentificationService... services) { + this.services = services; } @Override - public List> match(List files, boolean strict, SortOrder order, Locale locale, boolean autodetection, Component parent) throws Exception { + public List> match(Collection files, boolean strict, SortOrder order, Locale locale, boolean autodetection, Component parent) throws Exception { List> matches = new ArrayList>(); - List audioFiles = filter(files, AUDIO_FILES, VIDEO_FILES); + LinkedHashSet remaining = new LinkedHashSet(filter(files, AUDIO_FILES, VIDEO_FILES)); - // check audio files against AcoustID - if (audioFiles.size() > 0) { - for (Entry it : service.lookup(audioFiles).entrySet()) { - if (it.getKey().exists() && it.getValue() != null) { - AudioTrack track = it.getValue().clone(); - matches.add(new Match(it.getKey(), track)); + // check audio files against all services + for (int i = 0; i < services.length && remaining.size() > 0; i++) { + services[i].lookup(remaining).forEach((k, v) -> { + if (v != null) { + matches.add(new Match(k, v.clone())); + remaining.remove(k); } - } + }); } return matches;