use of com.biglybt.core.subs.Subscription in project BiglyBT by BiglySoftware.
the class MetaSearchListener method search.
protected void search(Map decodedMap, Engine target) {
String searchText = (String) decodedMap.get("searchText");
String headers = (String) decodedMap.get("headers");
final Long sid = (Long) decodedMap.get("sid");
Boolean mature = (Boolean) decodedMap.get("mature");
Long l_max_per_engine = (Long) decodedMap.get("maxResultsPerEngine");
int max_per_engine = l_max_per_engine == null ? 100 : l_max_per_engine.intValue();
if (max_per_engine < 1) {
max_per_engine = 1;
}
if (target == null) {
// override engine selection for subscriptions
String subscriptionId = ((String) decodedMap.get("subs_id"));
if (subscriptionId != null) {
Subscription subs = SubscriptionManagerFactory.getSingleton().getSubscriptionByID(subscriptionId);
if (subs != null) {
try {
Engine engine = subs.getEngine();
if (engine != null) {
target = engine;
}
} catch (Throwable e) {
Debug.out(e);
}
}
}
}
ResultListener listener = new ResultListener() {
@Override
public void contentReceived(Engine engine, String content) {
}
@Override
public void matchFound(Engine engine, String[] fields) {
}
@Override
public void engineFailed(Engine engine, Throwable e) {
Debug.out(e);
Map params = getParams(engine);
params.put("error", Debug.getNestedExceptionMessage(e));
sendBrowserMessage("metasearch", "engineFailed", params);
}
@Override
public void engineRequiresLogin(Engine engine, Throwable e) {
Map params = getParams(engine);
params.put("error", Debug.getNestedExceptionMessage(e));
sendBrowserMessage("metasearch", "engineRequiresLogin", params);
}
@Override
public void resultsComplete(Engine engine) {
sendBrowserMessage("metasearch", "engineCompleted", getParams(engine));
}
@Override
public void resultsReceived(Engine engine, Result[] results) {
Map params = getParams(engine);
List resultsList = new ArrayList(results.length);
for (int i = 0; i < results.length; i++) {
Result result = results[i];
resultsList.add(result.toJSONMap());
}
params.put("results", resultsList);
sendBrowserMessage("metasearch", "resultsReceived", params);
}
protected Map getParams(Engine engine) {
Map<String, Object> params = new HashMap<>();
params.put("id", new Long(engine.getId()));
params.put("name", engine.getName());
params.put("favicon", engine.getIcon());
params.put("dl_link_css", engine.getDownloadLinkCSS());
params.put("shareable", Boolean.valueOf(engine.isShareable()));
if (sid != null) {
params.put("sid", sid);
}
return (params);
}
};
List<SearchParameter> sps = new ArrayList<>();
sps.add(new SearchParameter("s", searchText));
if (mature != null) {
sps.add(new SearchParameter("m", mature.toString()));
}
SearchParameter[] parameters = (SearchParameter[]) sps.toArray(new SearchParameter[sps.size()]);
MetaSearchManager metaSearchManager = MetaSearchManagerFactory.getSingleton();
Map<String, String> context = new HashMap<>();
context.put(Engine.SC_FORCE_FULL, "true");
context.put(Engine.SC_BATCH_PERIOD, "1000");
context.put(Engine.SC_REMOVE_DUP_HASH, "true");
if (target == null) {
metaSearchManager.getMetaSearch().search(listener, parameters, headers, context, max_per_engine);
} else {
metaSearchManager.getMetaSearch().search(new Engine[] { target }, listener, parameters, headers, context, max_per_engine);
}
}
use of com.biglybt.core.subs.Subscription in project BiglyBT by BiglySoftware.
the class ColumnSubscriptionAutoDownload method refresh.
@Override
public void refresh(TableCell cell) {
boolean autoDownload = false;
Subscription sub = (Subscription) cell.getDataSource();
if (sub != null) {
SubscriptionHistory history = sub.getHistory();
if (history != null) {
autoDownload = history.isAutoDownload();
}
}
if (!cell.setSortValue(autoDownload ? 1 : 0) && cell.isValid()) {
return;
}
if (!cell.isShown()) {
return;
}
if (sub.isAutoDownloadSupported()) {
cell.setText(DisplayFormatters.getYesNo(autoDownload));
} else {
if (!cell.setSortValue(-1) && cell.isValid()) {
return;
}
cell.setText("");
}
return;
}
use of com.biglybt.core.subs.Subscription in project BiglyBT by BiglySoftware.
the class ColumnSubscriptionCategory method refresh.
@Override
public void refresh(TableCell cell) {
Subscription sub = (Subscription) cell.getDataSource();
String category = null;
if (sub != null) {
category = sub.getCategory();
}
if (category == null) {
category = "";
}
if (!cell.setSortValue(category) && cell.isValid()) {
return;
}
if (!cell.isShown()) {
return;
}
cell.setText(category);
return;
}
use of com.biglybt.core.subs.Subscription in project BiglyBT by BiglySoftware.
the class ColumnSubscriptionError method refresh.
@Override
public void refresh(TableCell cell) {
String error = "";
Subscription sub = (Subscription) cell.getDataSource();
if (sub != null) {
error = sub.getHistory().getLastError();
}
if (!cell.setSortValue(error) && cell.isValid()) {
return;
}
if (!cell.isShown()) {
return;
}
cell.setText(error);
}
use of com.biglybt.core.subs.Subscription in project BiglyBT by BiglySoftware.
the class ColumnSubscriptionName method refresh.
@Override
public void refresh(TableCell cell) {
String name = null;
Subscription sub = (Subscription) cell.getDataSource();
if (sub != null) {
name = sub.getName();
}
if (name == null) {
name = "";
}
if (!cell.setSortValue(name) && cell.isValid()) {
return;
}
}
Aggregations