* some refactoring & polishing

* update nekohtml to 1.9.13
* update jna to 3.2.3
* update ehcache to 1.7.0
* update mediainfo native libs to 0.7.24
* remove 32-bit mediainfo.dynlib for Mac because Java 6 is only available in 64-bit anyway
This commit is contained in:
Reinhard Pointner 2009-11-02 23:25:04 +00:00
parent f61b084769
commit 5c7f90540a
26 changed files with 187 additions and 35 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -137,8 +137,11 @@
-->
<cache name="anidb"
maxElementsInMemory="20"
maxElementsOnDisk="120"
eternal="false"
timeToIdleSeconds="2628000"
timeToLiveSeconds="2628000"
overflowToDisk="true"
diskPersistent="true"
memoryStoreEvictionPolicy="LRU"
/>
@ -162,7 +165,7 @@
Short-lived memory cache for resources like icons. This cache is used by ResourceManager.
-->
<cache name="resource"
maxElementsInMemory="100"
maxElementsInMemory="40"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"

View File

@ -1,6 +1,7 @@
# application settings
application.name: FileBot
application.version: 0.0
application.version: 1.94
thetvdb.apikey: 58B4AA94C59AD656
themoviedb.apikey: 66308fb6e3fd850dde4c7d21df2e8306
sublight.apikey: afa9ecb2-a3ee-42b1-9225-000b4038bc85

View File

@ -55,23 +55,23 @@ String.metaClass.lowerTrail = { replaceAll(/\b(\p{Alpha})(\p{Alpha}+)\b/, { matc
/**
* Return substring before the given delimiter.
* Return substring before the given pattern.
*/
String.metaClass.before = {
def matcher = delegate =~ it
// delimiter was found, return leading substring, else return original value
// pattern was found, return leading substring, else return original value
return matcher.find() ? delegate.substring(0, matcher.start()) : delegate
}
/**
* Return substring after the given delimiter.
* Return substring after the given pattern.
*/
String.metaClass.after = {
def matcher = delegate =~ it
// delimiter was found, return trailing substring, else return original value
// pattern was found, return trailing substring, else return original value
return matcher.find() ? delegate.substring(matcher.end(), delegate.length()) : delegate
}
@ -85,7 +85,7 @@ String.metaClass.replaceTrailingBraces = { replacement = "" -> replaceAll(/\s*[(
/**
* Replace 'part section'.
* Replace 'part identifier'.
*
* e.g. "Today Is the Day: Part 1" -> "Today Is the Day, Part 1"
* "Today Is the Day (1)" -> "Today Is the Day, Part 1"

View File

@ -144,7 +144,7 @@ abstract class SubtitleDropTarget extends JButton {
throw new UnsupportedOperationException("Not implemented yet");
}
if (filter(files, VIDEO_FILES).size() == filter(files, SUBTITLE_FILES).size()) {
if (containsOnlyVideoSubtitleMatches(files)) {
// TODO implement upload
throw new UnsupportedOperationException("Not implemented yet");
}

View File

@ -74,9 +74,12 @@ public class AnidbClient implements EpisodeListProvider {
for (AnidbSearchResult anime : getAnimeTitles()) {
for (String name : new String[] { anime.getMainTitle(), anime.getEnglishTitle() }) {
if (name != null) {
float similarity = metric.getSimilarity(name.toLowerCase(), query);
// normalize
name = name.toLowerCase();
if (similarity > 0.5 || name.toLowerCase().contains(query)) {
float similarity = metric.getSimilarity(name, query);
if (similarity > 0.5 || name.contains(query)) {
resultSet.add(new SimpleEntry<SearchResult, Float>(anime, similarity));
// add only once

View File

@ -8,6 +8,7 @@ import java.net.URI;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@ -61,25 +62,26 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
// require login
login();
@SuppressWarnings("unchecked")
List<SearchResult> results = (List) xmlrpc.searchMoviesOnIMDB(query);
// search for movies / series
SearchResult[] result = xmlrpc.searchMoviesOnIMDB(query).toArray(new SearchResult[0]);
return results;
return Arrays.asList(result);
}
@Override
public List<SubtitleDescriptor> getSubtitleList(SearchResult searchResult, String languageName) throws Exception {
// singleton array with or empty array
int imdbid = ((MovieDescriptor) searchResult).getImdbId();
String[] languageFilter = languageName != null ? new String[] { getSubLanguageID(languageName) } : new String[0];
// require login
login();
@SuppressWarnings("unchecked")
List<SubtitleDescriptor> subtitles = (List) xmlrpc.searchSubtitles(((MovieDescriptor) searchResult).getImdbId(), languageFilter);
// get subtitle list
SubtitleDescriptor[] subtitles = xmlrpc.searchSubtitles(imdbid, languageFilter).toArray(new SubtitleDescriptor[0]);
return subtitles;
return Arrays.asList(subtitles);
}

View File

@ -0,0 +1,86 @@
package net.sourceforge.filebot.web;
import static net.sourceforge.filebot.web.WebRequest.*;
import static net.sourceforge.tuned.XPathUtilities.*;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
public class TMDbClient implements MovieIdentificationService {
private static final String host = "api.themoviedb.org";
private static final String version = "2.1";
private final String apikey;
public TMDbClient(String apikey) {
this.apikey = apikey;
}
public List<MovieDescriptor> searchMovie(String query) throws IOException, SAXException {
return getMovies("Movie.search", query);
}
public List<MovieDescriptor> searchMovie(File file) throws IOException, SAXException {
return getMovies("Hash.getInfo", OpenSubtitlesHasher.computeHash(file));
}
@Override
public MovieDescriptor[] getMovieDescriptors(File[] movieFiles) throws Exception {
MovieDescriptor[] movies = new MovieDescriptor[movieFiles.length];
for (int i = 0; i < movies.length; i++) {
List<MovieDescriptor> options = searchMovie(movieFiles[i]);
// just use first result, if possible
movies[i] = options.isEmpty() ? null : options.get(0);
}
return movies;
}
protected List<MovieDescriptor> getMovies(String method, String parameter) throws IOException, SAXException {
List<MovieDescriptor> result = new ArrayList<MovieDescriptor>();
for (Node node : selectNodes("//movie", getDocument(getResource(method, parameter)))) {
try {
String name = getTextContent("name", node);
// release date format will be YYYY-MM-DD, but we only care about the year
int year = new Scanner(getTextContent("released", node)).useDelimiter("\\D+").nextInt();
// imdb id will be tt1234567, but we only care about the number
int imdbid = new Scanner(getTextContent("imdb_id", node)).useDelimiter("\\D+").nextInt();
result.add(new MovieDescriptor(name, year, imdbid));
} catch (RuntimeException e) {
// release date or imdb id are undefined
}
}
return result;
}
protected URL getResource(String method, String parameter) throws MalformedURLException {
// e.g. http://api.themoviedb.org/2.1/Movie.search/en/xml/{apikey}/serenity
return new URL("http", host, "/" + version + "/" + method + "/en/xml/" + apikey + "/" + parameter);
}
}

View File

@ -13,7 +13,7 @@ import java.util.UUID;
public final class TemporaryFolder {
private static final String tmpdir = System.getProperty("java.io.tmpdir");
private static final File tmpdir = new File(System.getProperty("java.io.tmpdir"));
private static final Map<String, TemporaryFolder> folders = new HashMap<String, TemporaryFolder>();
@ -43,6 +43,7 @@ public final class TemporaryFolder {
}
}
/**
* Delete all temporary folders on shutdown
*/

View File

@ -53,7 +53,7 @@ public class ActionPopup extends JPopupMenu {
public void addAction(JComponent component) {
actionPanel.add(component, "gapx 12px 12px, wrap");
actionPanel.add(component, "gapx 12px 12px, growx, wrap");
}
@ -109,6 +109,7 @@ public class ActionPopup extends JPopupMenu {
return statusLabel.getText();
}
private final ActionListener closeListener = new ActionListener() {
@Override

View File

@ -39,6 +39,7 @@ public class LinkButton extends JButton {
setContentAreaFilled(false);
setBorder(null);
setHorizontalAlignment(LEFT);
setIconTextGap(6);
setRolloverEnabled(true);
@ -80,6 +81,7 @@ public class LinkButton extends JButton {
this.rolloverColor = rolloverColor;
}
protected final MouseListener rolloverListener = new MouseAdapter() {
@Override

View File

@ -6,9 +6,11 @@ import static org.junit.Assert.*;
import java.util.List;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import net.sf.ehcache.CacheManager;
import net.sourceforge.filebot.web.AnidbClient.AnidbSearchResult;
@ -118,4 +120,11 @@ public class AnidbClientTest {
assertEquals("http://anidb.net/a1539", anidb.getEpisodeListLink(monsterSearchResult).toURL().toString());
}
@BeforeClass
@AfterClass
public static void clearCache() {
CacheManager.getInstance().clearAll();
}
}

View File

@ -3,6 +3,7 @@ package net.sourceforge.filebot.web;
import static java.util.Collections.*;
import static net.sourceforge.filebot.Settings.*;
import static org.junit.Assert.*;
import java.nio.ByteBuffer;
@ -21,7 +22,7 @@ import net.sourceforge.filebot.web.OpenSubtitlesXmlRpc.TryUploadResponse;
public class OpenSubtitlesXmlRpcTest {
private static OpenSubtitlesXmlRpc xmlrpc = new OpenSubtitlesXmlRpc("FileBot 0.0");
private static OpenSubtitlesXmlRpc xmlrpc = new OpenSubtitlesXmlRpc(String.format("%s %s", getApplicationName(), getApplicationVersion()));
@BeforeClass

View File

@ -2,6 +2,7 @@
package net.sourceforge.filebot.web;
import static net.sourceforge.filebot.Settings.*;
import static org.junit.Assert.*;
import java.io.ByteArrayInputStream;
@ -18,7 +19,7 @@ import net.sublight.webservice.Subtitle;
public class SublightSubtitleClientTest {
private static SublightSubtitleClient client = new SublightSubtitleClient("FileBot", "afa9ecb2-a3ee-42b1-9225-000b4038bc85");
private static SublightSubtitleClient client = new SublightSubtitleClient(getApplicationName(), getApplicationProperty("sublight.apikey"));
@BeforeClass

View File

@ -0,0 +1,39 @@
package net.sourceforge.filebot.web;
import static net.sourceforge.filebot.Settings.*;
import static org.junit.Assert.*;
import java.util.List;
import org.junit.Test;
public class TMDbClientTest {
private final TMDbClient tmdb = new TMDbClient(getApplicationProperty("themoviedb.apikey"));
@Test
public void searchByName() throws Exception {
List<MovieDescriptor> result = tmdb.searchMovie("transformers");
MovieDescriptor movie = result.get(0);
assertEquals("Transformers", movie.getName());
assertEquals(2007, movie.getYear());
assertEquals(418279, movie.getImdbId());
}
@Test
public void searchByHash() throws Exception {
List<MovieDescriptor> results = tmdb.getMovies("Hash.getInfo", "d7aa0275cace4410");
MovieDescriptor movie = results.get(0);
assertEquals("Iron Man", movie.getName());
assertEquals(2008, movie.getYear());
assertEquals(371746, movie.getImdbId());
}
}

View File

@ -8,7 +8,8 @@ import java.util.EnumSet;
import java.util.List;
import java.util.Locale;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import net.sf.ehcache.CacheManager;
@ -21,12 +22,6 @@ public class TheTVDBClientTest {
private TheTVDBClient thetvdb = new TheTVDBClient("BA864DEE427E384A");
@After
public void clearCache() {
CacheManager.getInstance().clearAll();
}
@Test
public void search() throws Exception {
// test default language and query escaping (blanks)
@ -122,4 +117,11 @@ public class TheTVDBClientTest {
assertEquals(EnumSet.allOf(MirrorType.class), MirrorType.fromTypeMask(7));
}
@BeforeClass
@AfterClass
public static void clearCache() {
CacheManager.getInstance().clearAll();
}
}

View File

@ -8,7 +8,8 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses( { TVDotComClientTest.class, AnidbClientTest.class, TVRageClientTest.class, TheTVDBClientTest.class, IMDbClientTest.class, SubsceneSubtitleClientTest.class, SubtitleSourceClientTest.class, SublightSubtitleClientTest.class, OpenSubtitlesXmlRpcTest.class })
@SuiteClasses( { TVDotComClientTest.class, AnidbClientTest.class, TVRageClientTest.class, TheTVDBClientTest.class, TMDbClientTest.class, IMDbClientTest.class, SubsceneSubtitleClientTest.class, SubtitleSourceClientTest.class,
SublightSubtitleClientTest.class, OpenSubtitlesXmlRpcTest.class })
public class WebTestSuite {
}