* osdb: check movie hash in batches of 50
This commit is contained in:
parent
6c7db64174
commit
37527a8e8e
|
@ -160,7 +160,7 @@ class SubtitleAutoMatchDialog extends JDialog {
|
|||
|
||||
|
||||
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) {
|
||||
final SubtitleMappingTableModel mappingModel = (SubtitleMappingTableModel) subtitleMappingTable.getModel();
|
||||
QueryTask queryTask = new QueryTask(services, mappingModel.getVideoFiles(), languageName, SubtitleAutoMatchDialog.this) {
|
||||
|
@ -940,12 +954,14 @@ class SubtitleAutoMatchDialog extends JDialog {
|
|||
|
||||
protected static class SubtitleProviderBean extends SubtitleServiceBean {
|
||||
|
||||
private SubtitleAutoMatchDialog inputProvider;
|
||||
private SubtitleProvider service;
|
||||
|
||||
|
||||
public SubtitleProviderBean(SubtitleProvider service) {
|
||||
public SubtitleProviderBean(SubtitleProvider service, SubtitleAutoMatchDialog inputProvider) {
|
||||
super(service.getName(), service.getIcon(), service.getLink());
|
||||
this.service = service;
|
||||
this.inputProvider = inputProvider;
|
||||
}
|
||||
|
||||
|
||||
|
@ -966,7 +982,7 @@ class SubtitleAutoMatchDialog extends JDialog {
|
|||
if (Thread.interrupted())
|
||||
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);
|
||||
|
||||
// still no luck... na women ye mei banfa
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
package net.sourceforge.filebot.web;
|
||||
|
||||
|
||||
import static java.lang.Math.*;
|
||||
import static java.util.Collections.*;
|
||||
import static net.sourceforge.filebot.web.OpenSubtitlesHasher.*;
|
||||
|
||||
|
@ -122,13 +123,19 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
|
|||
// 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());
|
||||
// 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()));
|
||||
|
||||
// add subtitle
|
||||
resultMap.get(file).add(subtitle);
|
||||
// submit query and map results to given files
|
||||
for (OpenSubtitlesSubtitleDescriptor subtitle : xmlrpc.searchSubtitles(batch)) {
|
||||
// get file for hash
|
||||
File file = hashMap.get(subtitle.getMovieHash());
|
||||
|
||||
// add subtitle
|
||||
resultMap.get(file).add(subtitle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,10 +200,16 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
|
|||
// require login
|
||||
login();
|
||||
|
||||
// dispatch single query for all hashes
|
||||
for (Entry<String, Movie> entry : xmlrpc.checkMovieHash(indexMap.keySet()).entrySet()) {
|
||||
int index = indexMap.get(entry.getKey());
|
||||
result[index] = entry.getValue();
|
||||
// dispatch query for all hashes
|
||||
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());
|
||||
result[index] = entry.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue