Support ID3 with AcoustID fallback

This commit is contained in:
Reinhard Pointner 2016-04-06 18:56:30 +00:00
parent b71b16f60b
commit 451424153f
1 changed files with 14 additions and 13 deletions

View File

@ -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<File, ?>> match(List<File> files, boolean strict, SortOrder order, Locale locale, boolean autodetection, Component parent) throws Exception {
public List<Match<File, ?>> match(Collection<File> files, boolean strict, SortOrder order, Locale locale, boolean autodetection, Component parent) throws Exception {
List<Match<File, ?>> matches = new ArrayList<Match<File, ?>>();
List<File> audioFiles = filter(files, AUDIO_FILES, VIDEO_FILES);
LinkedHashSet<File> remaining = new LinkedHashSet<File>(filter(files, AUDIO_FILES, VIDEO_FILES));
// check audio files against AcoustID
if (audioFiles.size() > 0) {
for (Entry<File, AudioTrack> it : service.lookup(audioFiles).entrySet()) {
if (it.getKey().exists() && it.getValue() != null) {
AudioTrack track = it.getValue().clone();
matches.add(new Match<File, AudioTrack>(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<File, AudioTrack>(k, v.clone()));
remaining.remove(k);
}
}
});
}
return matches;