mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-24 16:58:51 -05:00
* added preferred language support for movie mode (via TheMovieDB data source only)
This commit is contained in:
parent
e90f970b80
commit
f85224a8ff
@ -48,7 +48,7 @@ class MovieHashMatcher implements AutoCompleteMatcher {
|
|||||||
public List<Match<File, ?>> match(final List<File> files, Locale locale) throws Exception {
|
public List<Match<File, ?>> match(final List<File> files, Locale locale) throws Exception {
|
||||||
// handle movie files
|
// handle movie files
|
||||||
File[] movieFiles = filter(files, VIDEO_FILES).toArray(new File[0]);
|
File[] movieFiles = filter(files, VIDEO_FILES).toArray(new File[0]);
|
||||||
MovieDescriptor[] movieDescriptors = service.getMovieDescriptors(movieFiles);
|
MovieDescriptor[] movieDescriptors = service.getMovieDescriptors(movieFiles, locale);
|
||||||
|
|
||||||
// map movies to (possibly multiple) files (in natural order)
|
// map movies to (possibly multiple) files (in natural order)
|
||||||
Map<MovieDescriptor, SortedSet<File>> filesByMovie = new HashMap<MovieDescriptor, SortedSet<File>>();
|
Map<MovieDescriptor, SortedSet<File>> filesByMovie = new HashMap<MovieDescriptor, SortedSet<File>>();
|
||||||
@ -59,7 +59,7 @@ class MovieHashMatcher implements AutoCompleteMatcher {
|
|||||||
|
|
||||||
// unknown hash, try via imdb id from nfo file
|
// unknown hash, try via imdb id from nfo file
|
||||||
if (movie == null) {
|
if (movie == null) {
|
||||||
movie = determineMovie(movieFiles[i]);
|
movie = determineMovie(movieFiles[i], locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we managed to lookup the movie descriptor
|
// check if we managed to lookup the movie descriptor
|
||||||
@ -141,12 +141,12 @@ class MovieHashMatcher implements AutoCompleteMatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected MovieDescriptor determineMovie(File movieFile) throws Exception {
|
protected MovieDescriptor determineMovie(File movieFile, Locale locale) throws Exception {
|
||||||
List<MovieDescriptor> options = new ArrayList<MovieDescriptor>();
|
List<MovieDescriptor> options = new ArrayList<MovieDescriptor>();
|
||||||
|
|
||||||
// try to grep imdb id from nfo files
|
// try to grep imdb id from nfo files
|
||||||
for (int imdbid : grepImdbId(movieFile.getParentFile().listFiles(getDefaultFilter("application/nfo")))) {
|
for (int imdbid : grepImdbId(movieFile.getParentFile().listFiles(getDefaultFilter("application/nfo")))) {
|
||||||
MovieDescriptor movie = service.getMovieDescriptor(imdbid);
|
MovieDescriptor movie = service.getMovieDescriptor(imdbid, locale);
|
||||||
|
|
||||||
if (movie != null) {
|
if (movie != null) {
|
||||||
options.add(movie);
|
options.add(movie);
|
||||||
@ -156,12 +156,12 @@ class MovieHashMatcher implements AutoCompleteMatcher {
|
|||||||
// search by file name
|
// search by file name
|
||||||
if (options.isEmpty()) {
|
if (options.isEmpty()) {
|
||||||
String query = getName(movieFile).replaceAll("\\p{Punct}+", " ").trim();
|
String query = getName(movieFile).replaceAll("\\p{Punct}+", " ").trim();
|
||||||
options = service.searchMovie(query);
|
options = service.searchMovie(query, locale);
|
||||||
|
|
||||||
// search by folder name
|
// search by folder name
|
||||||
if (options.isEmpty()) {
|
if (options.isEmpty()) {
|
||||||
query = getName(movieFile.getParentFile()).replaceAll("\\p{Punct}+", " ").trim();
|
query = getName(movieFile.getParentFile()).replaceAll("\\p{Punct}+", " ").trim();
|
||||||
options = service.searchMovie(query);
|
options = service.searchMovie(query, locale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,16 +4,17 @@ package net.sourceforge.filebot.web;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
|
||||||
public interface MovieIdentificationService {
|
public interface MovieIdentificationService {
|
||||||
|
|
||||||
public List<MovieDescriptor> searchMovie(String query) throws Exception;
|
public List<MovieDescriptor> searchMovie(String query, Locale locale) throws Exception;
|
||||||
|
|
||||||
|
|
||||||
public MovieDescriptor getMovieDescriptor(int imdbid) throws Exception;
|
public MovieDescriptor getMovieDescriptor(int imdbid, Locale locale) throws Exception;
|
||||||
|
|
||||||
|
|
||||||
public MovieDescriptor[] getMovieDescriptors(File[] movieFiles) throws Exception;
|
public MovieDescriptor[] getMovieDescriptors(File[] movieFiles, Locale locale) throws Exception;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import java.util.Arrays;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@ -147,7 +148,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MovieDescriptor> searchMovie(String query) throws Exception {
|
public List<MovieDescriptor> searchMovie(String query, Locale locale) throws Exception {
|
||||||
// require login
|
// require login
|
||||||
login();
|
login();
|
||||||
|
|
||||||
@ -156,7 +157,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MovieDescriptor getMovieDescriptor(int imdbid) throws Exception {
|
public MovieDescriptor getMovieDescriptor(int imdbid, Locale locale) throws Exception {
|
||||||
// require login
|
// require login
|
||||||
login();
|
login();
|
||||||
|
|
||||||
@ -165,7 +166,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MovieDescriptor[] getMovieDescriptors(File[] movieFiles) throws Exception {
|
public MovieDescriptor[] getMovieDescriptors(File[] movieFiles, Locale locale) throws Exception {
|
||||||
// create result array
|
// create result array
|
||||||
MovieDescriptor[] result = new MovieDescriptor[movieFiles.length];
|
MovieDescriptor[] result = new MovieDescriptor[movieFiles.length];
|
||||||
|
|
||||||
|
@ -45,18 +45,7 @@ public class OpenSubtitlesXmlRpc {
|
|||||||
* Login as anonymous user
|
* Login as anonymous user
|
||||||
*/
|
*/
|
||||||
public void loginAnonymous() throws XmlRpcFault {
|
public void loginAnonymous() throws XmlRpcFault {
|
||||||
login("", "");
|
login("", "", "en");
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Login as user and use English as language
|
|
||||||
*
|
|
||||||
* @param username username (blank for anonymous user)
|
|
||||||
* @param password password (blank for anonymous user)
|
|
||||||
*/
|
|
||||||
public void login(String username, String password) throws XmlRpcFault {
|
|
||||||
login(username, password, "en");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import java.net.URL;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -48,9 +49,9 @@ public class TMDbClient implements MovieIdentificationService {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MovieDescriptor> searchMovie(String query) throws IOException {
|
public List<MovieDescriptor> searchMovie(String query, Locale locale) throws IOException {
|
||||||
try {
|
try {
|
||||||
return getMovies("Movie.search", query);
|
return getMovies("Movie.search", query, locale);
|
||||||
} catch (SAXException e) {
|
} catch (SAXException e) {
|
||||||
// TMDb output is sometimes malformed xml
|
// TMDb output is sometimes malformed xml
|
||||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, e.getMessage());
|
Logger.getLogger(getClass().getName()).log(Level.WARNING, e.getMessage());
|
||||||
@ -59,19 +60,19 @@ public class TMDbClient implements MovieIdentificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<MovieDescriptor> searchMovie(File file) throws IOException, SAXException {
|
public List<MovieDescriptor> searchMovie(File file, Locale locale) throws IOException, SAXException {
|
||||||
return searchMovie(OpenSubtitlesHasher.computeHash(file), file.length());
|
return searchMovie(OpenSubtitlesHasher.computeHash(file), file.length(), locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<MovieDescriptor> searchMovie(String hash, long bytesize) throws IOException, SAXException {
|
public List<MovieDescriptor> searchMovie(String hash, long bytesize, Locale locale) throws IOException, SAXException {
|
||||||
return getMovies("Media.getInfo", hash + "/" + bytesize);
|
return getMovies("Media.getInfo", hash + "/" + bytesize, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MovieDescriptor getMovieDescriptor(int imdbid) throws Exception {
|
public MovieDescriptor getMovieDescriptor(int imdbid, Locale locale) throws Exception {
|
||||||
URL resource = getResource("Movie.imdbLookup", String.format("tt%07d", imdbid));
|
URL resource = getResource("Movie.imdbLookup", String.format("tt%07d", imdbid), locale);
|
||||||
Node movie = selectNode("//movie", getDocument(resource));
|
Node movie = selectNode("//movie", getDocument(resource));
|
||||||
|
|
||||||
if (movie == null)
|
if (movie == null)
|
||||||
@ -85,11 +86,11 @@ public class TMDbClient implements MovieIdentificationService {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MovieDescriptor[] getMovieDescriptors(File[] movieFiles) throws Exception {
|
public MovieDescriptor[] getMovieDescriptors(File[] movieFiles, Locale locale) throws Exception {
|
||||||
MovieDescriptor[] movies = new MovieDescriptor[movieFiles.length];
|
MovieDescriptor[] movies = new MovieDescriptor[movieFiles.length];
|
||||||
|
|
||||||
for (int i = 0; i < movies.length; i++) {
|
for (int i = 0; i < movies.length; i++) {
|
||||||
List<MovieDescriptor> options = searchMovie(movieFiles[i]);
|
List<MovieDescriptor> options = searchMovie(movieFiles[i], locale);
|
||||||
|
|
||||||
// just use first result, if possible
|
// just use first result, if possible
|
||||||
movies[i] = options.isEmpty() ? null : options.get(0);
|
movies[i] = options.isEmpty() ? null : options.get(0);
|
||||||
@ -99,10 +100,10 @@ public class TMDbClient implements MovieIdentificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected List<MovieDescriptor> getMovies(String method, String parameter) throws IOException, SAXException {
|
protected List<MovieDescriptor> getMovies(String method, String parameter, Locale locale) throws IOException, SAXException {
|
||||||
List<MovieDescriptor> result = new ArrayList<MovieDescriptor>();
|
List<MovieDescriptor> result = new ArrayList<MovieDescriptor>();
|
||||||
|
|
||||||
for (Node node : selectNodes("//movie", getDocument(getResource(method, parameter)))) {
|
for (Node node : selectNodes("//movie", getDocument(getResource(method, parameter, locale)))) {
|
||||||
try {
|
try {
|
||||||
String name = getTextContent("name", node);
|
String name = getTextContent("name", node);
|
||||||
|
|
||||||
@ -122,9 +123,9 @@ public class TMDbClient implements MovieIdentificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected URL getResource(String method, String parameter) throws MalformedURLException {
|
protected URL getResource(String method, String parameter, Locale locale) throws MalformedURLException {
|
||||||
// e.g. http://api.themoviedb.org/2.1/Movie.search/en/xml/{apikey}/serenity
|
// 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);
|
return new URL("http", host, "/" + version + "/" + method + "/" + locale.getLanguage() + "/xml/" + apikey + "/" + parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import static net.sourceforge.filebot.Settings.*;
|
|||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -17,10 +18,10 @@ public class TMDbClientTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void searchByName() throws Exception {
|
public void searchByName() throws Exception {
|
||||||
List<MovieDescriptor> result = tmdb.searchMovie("Serenity");
|
List<MovieDescriptor> result = tmdb.searchMovie("Serenity", Locale.CHINESE);
|
||||||
MovieDescriptor movie = result.get(0);
|
MovieDescriptor movie = result.get(0);
|
||||||
|
|
||||||
assertEquals("Serenity", movie.getName());
|
assertEquals("冲出宁静号", movie.getName());
|
||||||
assertEquals(2005, movie.getYear());
|
assertEquals(2005, movie.getYear());
|
||||||
assertEquals(379786, movie.getImdbId());
|
assertEquals(379786, movie.getImdbId());
|
||||||
}
|
}
|
||||||
@ -28,7 +29,7 @@ public class TMDbClientTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void searchByHash() throws Exception {
|
public void searchByHash() throws Exception {
|
||||||
List<MovieDescriptor> results = tmdb.searchMovie("907172e7fe51ba57", 742086656);
|
List<MovieDescriptor> results = tmdb.searchMovie("907172e7fe51ba57", 742086656, Locale.ENGLISH);
|
||||||
MovieDescriptor movie = results.get(0);
|
MovieDescriptor movie = results.get(0);
|
||||||
|
|
||||||
assertEquals("Sin City", movie.getName());
|
assertEquals("Sin City", movie.getName());
|
||||||
@ -39,7 +40,7 @@ public class TMDbClientTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void searchByIMDB() throws Exception {
|
public void searchByIMDB() throws Exception {
|
||||||
MovieDescriptor movie = tmdb.getMovieDescriptor(418279);
|
MovieDescriptor movie = tmdb.getMovieDescriptor(418279, Locale.ENGLISH);
|
||||||
|
|
||||||
assertEquals("Transformers", movie.getName());
|
assertEquals("Transformers", movie.getName());
|
||||||
assertEquals(2007, movie.getYear());
|
assertEquals(2007, movie.getYear());
|
||||||
|
Loading…
Reference in New Issue
Block a user