* osdb: check movie hash in batches of 50

This commit is contained in:
Reinhard Pointner 2011-11-30 18:44:46 +00:00
parent 6c7db64174
commit 37527a8e8e
2 changed files with 42 additions and 13 deletions

View File

@ -160,7 +160,7 @@ class SubtitleAutoMatchDialog extends JDialog {
public void addSubtitleService(SubtitleProvider service) { public void addSubtitleService(SubtitleProvider service) {
addSubtitleService(new SubtitleProviderBean(service), nameMatcherServicePanel); addSubtitleService(new SubtitleProviderBean(service, this), nameMatcherServicePanel);
} }
@ -190,6 +190,20 @@ class SubtitleAutoMatchDialog extends JDialog {
} }
// remember last user input
private List<String> userQuery = new ArrayList<String>();
protected List<String> getUserQuery(String suggestion, String title, Component parent) throws Exception {
synchronized (userQuery) {
if (userQuery.isEmpty()) {
userQuery.addAll(showMultiValueInputDialog("Enter series / movie names:", suggestion, title, parent));
}
return userQuery;
}
}
public void startQuery(String languageName) { public void startQuery(String languageName) {
final SubtitleMappingTableModel mappingModel = (SubtitleMappingTableModel) subtitleMappingTable.getModel(); final SubtitleMappingTableModel mappingModel = (SubtitleMappingTableModel) subtitleMappingTable.getModel();
QueryTask queryTask = new QueryTask(services, mappingModel.getVideoFiles(), languageName, SubtitleAutoMatchDialog.this) { QueryTask queryTask = new QueryTask(services, mappingModel.getVideoFiles(), languageName, SubtitleAutoMatchDialog.this) {
@ -940,12 +954,14 @@ class SubtitleAutoMatchDialog extends JDialog {
protected static class SubtitleProviderBean extends SubtitleServiceBean { protected static class SubtitleProviderBean extends SubtitleServiceBean {
private SubtitleAutoMatchDialog inputProvider;
private SubtitleProvider service; private SubtitleProvider service;
public SubtitleProviderBean(SubtitleProvider service) { public SubtitleProviderBean(SubtitleProvider service, SubtitleAutoMatchDialog inputProvider) {
super(service.getName(), service.getIcon(), service.getLink()); super(service.getName(), service.getIcon(), service.getLink());
this.service = service; this.service = service;
this.inputProvider = inputProvider;
} }
@ -966,7 +982,7 @@ class SubtitleAutoMatchDialog extends JDialog {
if (Thread.interrupted()) if (Thread.interrupted())
throw new CancellationException(); throw new CancellationException();
querySet = showMultiValueInputDialog("Enter series / movie names:", join(querySet, ","), service.getName(), parent); querySet = inputProvider.getUserQuery(join(querySet, ","), service.getName(), parent);
subtitles = findSubtitles(service, querySet, languageName); subtitles = findSubtitles(service, querySet, languageName);
// still no luck... na women ye mei banfa // still no luck... na women ye mei banfa

View File

@ -2,6 +2,7 @@
package net.sourceforge.filebot.web; package net.sourceforge.filebot.web;
import static java.lang.Math.*;
import static java.util.Collections.*; import static java.util.Collections.*;
import static net.sourceforge.filebot.web.OpenSubtitlesHasher.*; import static net.sourceforge.filebot.web.OpenSubtitlesHasher.*;
@ -122,8 +123,13 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
// require login // require login
login(); login();
// dispatch query for all hashes
int batchSize = 50;
for (int bn = 0; bn < ceil((float) queryList.size() / batchSize); bn++) {
List<Query> batch = queryList.subList(bn * batchSize, min((bn * batchSize) + batchSize, queryList.size()));
// submit query and map results to given files // submit query and map results to given files
for (OpenSubtitlesSubtitleDescriptor subtitle : xmlrpc.searchSubtitles(queryList)) { for (OpenSubtitlesSubtitleDescriptor subtitle : xmlrpc.searchSubtitles(batch)) {
// get file for hash // get file for hash
File file = hashMap.get(subtitle.getMovieHash()); File file = hashMap.get(subtitle.getMovieHash());
@ -131,6 +137,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
resultMap.get(file).add(subtitle); resultMap.get(file).add(subtitle);
} }
} }
}
return resultMap; return resultMap;
} }
@ -193,12 +200,18 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
// require login // require login
login(); login();
// dispatch single query for all hashes // dispatch query for all hashes
for (Entry<String, Movie> entry : xmlrpc.checkMovieHash(indexMap.keySet()).entrySet()) { List<String> hashes = new ArrayList<String>(indexMap.keySet());
int batchSize = 50;
for (int bn = 0; bn < ceil((float) hashes.size() / batchSize); bn++) {
List<String> batch = hashes.subList(bn * batchSize, min((bn * batchSize) + batchSize, hashes.size()));
for (Entry<String, Movie> entry : xmlrpc.checkMovieHash(batch).entrySet()) {
int index = indexMap.get(entry.getKey()); int index = indexMap.get(entry.getKey());
result[index] = entry.getValue(); result[index] = entry.getValue();
} }
} }
}
return result; return result;
} }