* 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,16 +107,18 @@ 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
|
||||||
|
if (file.length() > HASH_CHUNK_SIZE) {
|
||||||
|
String movieHash = computeHash(file);
|
||||||
queryList.add(Query.forHash(movieHash, file.length(), languageFilter));
|
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>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (queryList.size() > 0) {
|
||||||
// require login
|
// require login
|
||||||
login();
|
login();
|
||||||
|
|
||||||
|
@ -127,6 +130,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
|
||||||
// add subtitle
|
// add subtitle
|
||||||
resultMap.get(file).add(subtitle);
|
resultMap.get(file).add(subtitle);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return resultMap;
|
return resultMap;
|
||||||
}
|
}
|
||||||
|
@ -180,12 +184,12 @@ 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (indexMap.size() > 0) {
|
||||||
// require login
|
// require login
|
||||||
login();
|
login();
|
||||||
|
|
||||||
|
@ -194,6 +198,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
|
||||||
int index = indexMap.get(entry.getKey());
|
int index = indexMap.get(entry.getKey());
|
||||||
result[index] = entry.getValue();
|
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