* ignore empty query
This commit is contained in:
parent
f1f56a5fd1
commit
c22d867453
|
@ -3,6 +3,7 @@ package net.sourceforge.filebot.web;
|
||||||
|
|
||||||
|
|
||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
|
import static net.sourceforge.filebot.web.OpenSubtitlesHasher.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
@ -106,26 +107,29 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
|
||||||
List<Query> queryList = new ArrayList<Query>(files.length);
|
List<Query> queryList = new ArrayList<Query>(files.length);
|
||||||
|
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
String movieHash = OpenSubtitlesHasher.computeHash(file);
|
|
||||||
|
|
||||||
// add query
|
// add query
|
||||||
queryList.add(Query.forHash(movieHash, file.length(), languageFilter));
|
if (file.length() > HASH_CHUNK_SIZE) {
|
||||||
|
String movieHash = computeHash(file);
|
||||||
|
queryList.add(Query.forHash(movieHash, file.length(), languageFilter));
|
||||||
|
hashMap.put(movieHash, file);
|
||||||
|
}
|
||||||
|
|
||||||
// prepare result map
|
// prepare result map
|
||||||
hashMap.put(movieHash, file);
|
|
||||||
resultMap.put(file, new LinkedList<SubtitleDescriptor>());
|
resultMap.put(file, new LinkedList<SubtitleDescriptor>());
|
||||||
}
|
}
|
||||||
|
|
||||||
// require login
|
if (queryList.size() > 0) {
|
||||||
login();
|
// require login
|
||||||
|
login();
|
||||||
// submit query and map results to given files
|
|
||||||
for (OpenSubtitlesSubtitleDescriptor subtitle : xmlrpc.searchSubtitles(queryList)) {
|
|
||||||
// get file for hash
|
|
||||||
File file = hashMap.get(subtitle.getMovieHash());
|
|
||||||
|
|
||||||
// add subtitle
|
// submit query and map results to given files
|
||||||
resultMap.get(file).add(subtitle);
|
for (OpenSubtitlesSubtitleDescriptor subtitle : xmlrpc.searchSubtitles(queryList)) {
|
||||||
|
// get file for hash
|
||||||
|
File file = hashMap.get(subtitle.getMovieHash());
|
||||||
|
|
||||||
|
// add subtitle
|
||||||
|
resultMap.get(file).add(subtitle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return resultMap;
|
return resultMap;
|
||||||
|
@ -180,19 +184,20 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
|
||||||
Map<String, Integer> indexMap = new HashMap<String, Integer>(movieFiles.length);
|
Map<String, Integer> indexMap = new HashMap<String, Integer>(movieFiles.length);
|
||||||
|
|
||||||
for (int i = 0; i < movieFiles.length; i++) {
|
for (int i = 0; i < movieFiles.length; i++) {
|
||||||
String hash = OpenSubtitlesHasher.computeHash(movieFiles[i]);
|
if (movieFiles[i].length() > HASH_CHUNK_SIZE) {
|
||||||
|
indexMap.put(computeHash(movieFiles[i]), i); // remember original index
|
||||||
// remember original index
|
}
|
||||||
indexMap.put(hash, i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// require login
|
if (indexMap.size() > 0) {
|
||||||
login();
|
// require login
|
||||||
|
login();
|
||||||
// dispatch single query for all hashes
|
|
||||||
for (Entry<String, Movie> entry : xmlrpc.checkMovieHash(indexMap.keySet()).entrySet()) {
|
// dispatch single query for all hashes
|
||||||
int index = indexMap.get(entry.getKey());
|
for (Entry<String, Movie> entry : xmlrpc.checkMovieHash(indexMap.keySet()).entrySet()) {
|
||||||
result[index] = entry.getValue();
|
int index = indexMap.get(entry.getKey());
|
||||||
|
result[index] = entry.getValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -24,7 +24,7 @@ public final class OpenSubtitlesHasher {
|
||||||
/**
|
/**
|
||||||
* Size of the chunks that will be hashed in bytes (64 KB)
|
* Size of the chunks that will be hashed in bytes (64 KB)
|
||||||
*/
|
*/
|
||||||
private static final int HASH_CHUNK_SIZE = 64 * 1024;
|
public static final int HASH_CHUNK_SIZE = 64 * 1024;
|
||||||
|
|
||||||
|
|
||||||
public static String computeHash(File file) throws IOException {
|
public static String computeHash(File file) throws IOException {
|
||||||
|
|
Loading…
Reference in New Issue