* extracted common MusicIdentificationService interface and added a dummy one that is only reading MediaInfo/ID3
This commit is contained in:
parent
1568974b89
commit
f7f41509e1
|
@ -25,9 +25,11 @@ import net.sourceforge.filebot.web.AcoustID;
|
||||||
import net.sourceforge.filebot.web.AnidbClient;
|
import net.sourceforge.filebot.web.AnidbClient;
|
||||||
import net.sourceforge.filebot.web.EpisodeListProvider;
|
import net.sourceforge.filebot.web.EpisodeListProvider;
|
||||||
import net.sourceforge.filebot.web.FanartTV;
|
import net.sourceforge.filebot.web.FanartTV;
|
||||||
|
import net.sourceforge.filebot.web.ID3Lookup;
|
||||||
import net.sourceforge.filebot.web.IMDbClient;
|
import net.sourceforge.filebot.web.IMDbClient;
|
||||||
import net.sourceforge.filebot.web.LocalSearch;
|
import net.sourceforge.filebot.web.LocalSearch;
|
||||||
import net.sourceforge.filebot.web.MovieIdentificationService;
|
import net.sourceforge.filebot.web.MovieIdentificationService;
|
||||||
|
import net.sourceforge.filebot.web.MusicIdentificationService;
|
||||||
import net.sourceforge.filebot.web.OpenSubtitlesClient;
|
import net.sourceforge.filebot.web.OpenSubtitlesClient;
|
||||||
import net.sourceforge.filebot.web.SearchResult;
|
import net.sourceforge.filebot.web.SearchResult;
|
||||||
import net.sourceforge.filebot.web.SerienjunkiesClient;
|
import net.sourceforge.filebot.web.SerienjunkiesClient;
|
||||||
|
@ -87,6 +89,11 @@ public final class WebServices {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static MusicIdentificationService[] getMusicIdentificationServices() {
|
||||||
|
return new MusicIdentificationService[] { AcoustID, new ID3Lookup() };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static EpisodeListProvider getEpisodeListProvider(String name) {
|
public static EpisodeListProvider getEpisodeListProvider(String name) {
|
||||||
for (EpisodeListProvider it : WebServices.getEpisodeListProviders()) {
|
for (EpisodeListProvider it : WebServices.getEpisodeListProviders()) {
|
||||||
if (it.getName().equalsIgnoreCase(name))
|
if (it.getName().equalsIgnoreCase(name))
|
||||||
|
@ -107,6 +114,16 @@ public final class WebServices {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static MusicIdentificationService getMusicIdentificationService(String name) {
|
||||||
|
for (MusicIdentificationService it : getMusicIdentificationServices()) {
|
||||||
|
if (it.getName().equalsIgnoreCase(name))
|
||||||
|
return it;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null; // default
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class TheTVDBClientWithLocalSearch extends TheTVDBClient {
|
private static class TheTVDBClientWithLocalSearch extends TheTVDBClient {
|
||||||
|
|
||||||
public TheTVDBClientWithLocalSearch(String apikey) {
|
public TheTVDBClientWithLocalSearch(String apikey) {
|
||||||
|
|
|
@ -66,7 +66,6 @@ import net.sourceforge.filebot.similarity.SimilarityMetric;
|
||||||
import net.sourceforge.filebot.subtitle.SubtitleFormat;
|
import net.sourceforge.filebot.subtitle.SubtitleFormat;
|
||||||
import net.sourceforge.filebot.ui.Language;
|
import net.sourceforge.filebot.ui.Language;
|
||||||
import net.sourceforge.filebot.vfs.MemoryFile;
|
import net.sourceforge.filebot.vfs.MemoryFile;
|
||||||
import net.sourceforge.filebot.web.AcoustID;
|
|
||||||
import net.sourceforge.filebot.web.AudioTrack;
|
import net.sourceforge.filebot.web.AudioTrack;
|
||||||
import net.sourceforge.filebot.web.Episode;
|
import net.sourceforge.filebot.web.Episode;
|
||||||
import net.sourceforge.filebot.web.EpisodeFormat;
|
import net.sourceforge.filebot.web.EpisodeFormat;
|
||||||
|
@ -75,6 +74,7 @@ import net.sourceforge.filebot.web.Movie;
|
||||||
import net.sourceforge.filebot.web.MovieFormat;
|
import net.sourceforge.filebot.web.MovieFormat;
|
||||||
import net.sourceforge.filebot.web.MovieIdentificationService;
|
import net.sourceforge.filebot.web.MovieIdentificationService;
|
||||||
import net.sourceforge.filebot.web.MoviePart;
|
import net.sourceforge.filebot.web.MoviePart;
|
||||||
|
import net.sourceforge.filebot.web.MusicIdentificationService;
|
||||||
import net.sourceforge.filebot.web.SearchResult;
|
import net.sourceforge.filebot.web.SearchResult;
|
||||||
import net.sourceforge.filebot.web.SortOrder;
|
import net.sourceforge.filebot.web.SortOrder;
|
||||||
import net.sourceforge.filebot.web.SubtitleDescriptor;
|
import net.sourceforge.filebot.web.SubtitleDescriptor;
|
||||||
|
@ -103,9 +103,9 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
return renameMovie(files, action, conflictAction, outputDir, format, getMovieIdentificationService(db), query, locale, strict);
|
return renameMovie(files, action, conflictAction, outputDir, format, getMovieIdentificationService(db), query, locale, strict);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WebServices.AcoustID.getName().equalsIgnoreCase(db) || containsOnly(files, AUDIO_FILES)) {
|
if (getMusicIdentificationService(db) != null || containsOnly(files, AUDIO_FILES)) {
|
||||||
// music mode
|
// music mode
|
||||||
return renameMusic(files, action, conflictAction, outputDir, format, WebServices.AcoustID);
|
return renameMusic(files, action, conflictAction, outputDir, format, getMusicIdentificationService(db) == null ? AcoustID : getMusicIdentificationService(db));
|
||||||
}
|
}
|
||||||
|
|
||||||
// auto-determine mode
|
// auto-determine mode
|
||||||
|
@ -505,7 +505,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<File> renameMusic(Collection<File> files, RenameAction renameAction, ConflictAction conflictAction, File outputDir, ExpressionFormat format, AcoustID service) throws Exception {
|
public List<File> renameMusic(Collection<File> files, RenameAction renameAction, ConflictAction conflictAction, File outputDir, ExpressionFormat format, MusicIdentificationService service) throws Exception {
|
||||||
// map old files to new paths by applying formatting and validating filenames
|
// map old files to new paths by applying formatting and validating filenames
|
||||||
Map<File, File> renameMap = new LinkedHashMap<File, File>();
|
Map<File, File> renameMap = new LinkedHashMap<File, File>();
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,8 @@ public class MediaBindingBean {
|
||||||
return getEpisode().getSeriesStartDate().getYear();
|
return getEpisode().getSeriesStartDate().getYear();
|
||||||
if (infoObject instanceof Movie)
|
if (infoObject instanceof Movie)
|
||||||
return getMovie().getYear();
|
return getMovie().getYear();
|
||||||
|
if (infoObject instanceof AudioTrack)
|
||||||
|
return new Scanner(getMediaInfo(StreamKind.General, 0, "Recorded_Date")).useDelimiter("\\D+").nextInt();
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -422,6 +424,9 @@ public class MediaBindingBean {
|
||||||
|
|
||||||
@Define("genres")
|
@Define("genres")
|
||||||
public Object getGenres() {
|
public Object getGenres() {
|
||||||
|
if (infoObject instanceof AudioTrack)
|
||||||
|
return asList(getMediaInfo(StreamKind.General, 0, "Genre").split(";"));
|
||||||
|
|
||||||
return getMetaInfo().getProperty("genres");
|
return getMetaInfo().getProperty("genres");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -561,7 +566,12 @@ public class MediaBindingBean {
|
||||||
|
|
||||||
@Define("pi")
|
@Define("pi")
|
||||||
public Integer getPart() {
|
public Integer getPart() {
|
||||||
|
if (infoObject instanceof AudioTrack)
|
||||||
|
return Integer.parseInt(getMediaInfo(StreamKind.General, 0, "Track/Position"));
|
||||||
|
if (infoObject instanceof MoviePart)
|
||||||
return ((MoviePart) infoObject).getPartIndex();
|
return ((MoviePart) infoObject).getPartIndex();
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,17 +13,17 @@ import java.util.Locale;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import net.sourceforge.filebot.similarity.Match;
|
import net.sourceforge.filebot.similarity.Match;
|
||||||
import net.sourceforge.filebot.web.AcoustID;
|
|
||||||
import net.sourceforge.filebot.web.AudioTrack;
|
import net.sourceforge.filebot.web.AudioTrack;
|
||||||
|
import net.sourceforge.filebot.web.MusicIdentificationService;
|
||||||
import net.sourceforge.filebot.web.SortOrder;
|
import net.sourceforge.filebot.web.SortOrder;
|
||||||
|
|
||||||
|
|
||||||
class AudioFingerprintMatcher implements AutoCompleteMatcher {
|
class AudioFingerprintMatcher implements AutoCompleteMatcher {
|
||||||
|
|
||||||
private AcoustID service;
|
private MusicIdentificationService service;
|
||||||
|
|
||||||
|
|
||||||
public AudioFingerprintMatcher(AcoustID service) {
|
public AudioFingerprintMatcher(MusicIdentificationService service) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ import net.sourceforge.filebot.ResourceManager;
|
||||||
import com.cedarsoftware.util.io.JsonReader;
|
import com.cedarsoftware.util.io.JsonReader;
|
||||||
|
|
||||||
|
|
||||||
public class AcoustID {
|
public class AcoustID implements MusicIdentificationService {
|
||||||
|
|
||||||
private static final FloodLimit REQUEST_LIMIT = new FloodLimit(3, 1, TimeUnit.SECONDS);
|
private static final FloodLimit REQUEST_LIMIT = new FloodLimit(3, 1, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
@ -37,16 +37,19 @@ public class AcoustID {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "AcoustID";
|
return "AcoustID";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public Icon getIcon() {
|
public Icon getIcon() {
|
||||||
return ResourceManager.getIcon("search.acoustid");
|
return ResourceManager.getIcon("search.acoustid");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public Map<File, AudioTrack> lookup(Iterable<File> files) throws Exception {
|
public Map<File, AudioTrack> lookup(Iterable<File> files) throws Exception {
|
||||||
Map<File, AudioTrack> results = new LinkedHashMap<File, AudioTrack>();
|
Map<File, AudioTrack> results = new LinkedHashMap<File, AudioTrack>();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
|
||||||
|
package net.sourceforge.filebot.web;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.swing.Icon;
|
||||||
|
|
||||||
|
import net.sourceforge.filebot.mediainfo.MediaInfo;
|
||||||
|
import net.sourceforge.filebot.mediainfo.MediaInfo.StreamKind;
|
||||||
|
|
||||||
|
|
||||||
|
public class ID3Lookup implements MusicIdentificationService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "ID3";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Icon getIcon() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<File, AudioTrack> lookup(Iterable<File> files) throws Exception {
|
||||||
|
Map<File, AudioTrack> info = new HashMap<File, AudioTrack>();
|
||||||
|
|
||||||
|
MediaInfo mediaInfo = new MediaInfo();
|
||||||
|
for (File f : files) {
|
||||||
|
if (!mediaInfo.open(f)) {
|
||||||
|
throw new IOException("MediaInfo failed to open file: " + f);
|
||||||
|
}
|
||||||
|
|
||||||
|
String artist = mediaInfo.get(StreamKind.General, 0, "Performer");
|
||||||
|
String title = mediaInfo.get(StreamKind.General, 0, "Title");
|
||||||
|
String album = mediaInfo.get(StreamKind.General, 0, "Album");
|
||||||
|
mediaInfo.close();
|
||||||
|
|
||||||
|
info.put(f, new AudioTrack(artist, title, album));
|
||||||
|
}
|
||||||
|
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
package net.sourceforge.filebot.web;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.swing.Icon;
|
||||||
|
|
||||||
|
|
||||||
|
public interface MusicIdentificationService {
|
||||||
|
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
|
||||||
|
Icon getIcon();
|
||||||
|
|
||||||
|
|
||||||
|
Map<File, AudioTrack> lookup(Iterable<File> files) throws Exception;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue