1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-23 00:08:51 -05:00

Collect more data from TheTVDB search queries (to maybe present better options to the user, including years and banners)

This commit is contained in:
Reinhard Pointner 2019-04-28 17:32:46 +07:00
parent 086bd41552
commit 7d4e34ec47
4 changed files with 38 additions and 22 deletions

View File

@ -44,6 +44,7 @@ import net.filebot.web.TMDbClient;
import net.filebot.web.TMDbTVClient;
import net.filebot.web.TVMazeClient;
import net.filebot.web.TheTVDBClient;
import net.filebot.web.TheTVDBSearchResult;
import net.filebot.web.VideoHashSubtitleService;
/**
@ -199,12 +200,19 @@ public final class WebServices {
// local TheTVDB search index
private final Resource<LocalSearch<SearchResult>> localIndex = Resource.lazy(() -> new LocalSearch<SearchResult>(releaseInfo.getTheTVDBIndex(), SearchResult::getEffectiveNames));
private SearchResult merge(SearchResult prime, List<SearchResult> group) {
private SearchResult merge(List<SearchResult> group) {
SearchResult prime = group.get(0);
int id = prime.getId();
String name = prime.getName();
String[] aliasNames = group.stream().flatMap(it -> stream(it.getAliasNames())).filter(n -> !n.equals(name)).distinct().toArray(String[]::new);
return new SearchResult(id, name, aliasNames);
if (prime instanceof TheTVDBSearchResult) {
TheTVDBSearchResult r = (TheTVDBSearchResult) prime;
return new TheTVDBSearchResult(id, name, aliasNames, r.getSlug(), r.getFirstAired(), r.getOverview(), r.getNetwork(), r.getStatus());
} else {
return new SearchResult(id, name, aliasNames);
}
}
@Override
@ -214,7 +222,7 @@ public final class WebServices {
Future<List<SearchResult>> localSearch = requestThreadPool.submit(() -> localIndex.get().search(query));
// combine alias names into a single search results, and keep API search name as primary name
Map<Integer, SearchResult> results = Stream.of(apiSearch.get(), localSearch.get()).flatMap(List::stream).collect(groupingBy(SearchResult::getId, LinkedHashMap::new, collectingAndThen(toList(), group -> merge(group.get(0), group))));
Map<Integer, SearchResult> results = Stream.of(apiSearch.get(), localSearch.get()).flatMap(List::stream).collect(groupingBy(SearchResult::getId, LinkedHashMap::new, collectingAndThen(toList(), this::merge)));
return sortBySimilarity(results.values(), singleton(query), getSeriesMatchMetric());
}

View File

@ -27,6 +27,7 @@ import javax.swing.SwingUtilities;
import net.filebot.ResourceManager;
import net.filebot.util.ui.DefaultFancyListCellRenderer;
import net.filebot.web.SearchResult;
import net.filebot.web.TheTVDBSearchResult;
import net.miginfocom.swing.MigLayout;
public class SelectDialog<T> extends JDialog {
@ -113,16 +114,32 @@ public class SelectDialog<T> extends JDialog {
protected String getTooltipText(SearchResult item) {
StringBuilder html = new StringBuilder(64);
html.append("<html><b>").append(escapeHTML(item.toString())).append("</b><br>");
html.append("<html><h3>").append(escapeHTML(item.toString())).append("</h3>");
String[] names = item.getAliasNames();
if (names.length > 0) {
html.append("<br>AKA:<br>");
for (String n : names) {
html.append("").append(escapeHTML(n)).append("<br>");
}
appendTooltipParagraph(html, "AKA", String.join(" | ", names));
}
html.append("<br>ID: <br>• ").append(Integer.toString(item.getId())).append("</html>");
return html.toString();
if (item instanceof TheTVDBSearchResult) {
TheTVDBSearchResult r = (TheTVDBSearchResult) item;
appendTooltipParagraph(html, "First Aired", r.getFirstAired());
appendTooltipParagraph(html, "Network", r.getNetwork());
appendTooltipParagraph(html, "Status", r.getStatus());
appendTooltipParagraph(html, "Overview", r.getOverview());
}
appendTooltipParagraph(html, "ID", item.getId());
return html.append("</html>").toString();
}
private StringBuilder appendTooltipParagraph(StringBuilder html, String label, Object value) {
if (value != null) {
html.append("<p style='width:250px; margin:3px'><b>").append(label).append(":</b> ").append(escapeHTML(value.toString())).append("</p>");
}
return html;
}
public JLabel getMessageLabel() {

View File

@ -154,9 +154,8 @@ public class TheTVDBClient extends AbstractEpisodeListProvider implements Artwor
String status = getString(it, "status");
SimpleDate firstAired = getStringValue(it, "firstAired", SimpleDate::parse);
String overview = getString(it, "overview");
URL banner = getStringValue(it, "banner", this::resolveImage);
return new TheTVDBSearchResult(id, seriesName, aliasNames, slug, firstAired, overview, network, status, banner);
return new TheTVDBSearchResult(id, seriesName, aliasNames, slug, firstAired, overview, network, status);
}).filter(Objects::nonNull).collect(toList());
}

View File

@ -1,7 +1,5 @@
package net.filebot.web;
import java.net.URL;
public class TheTVDBSearchResult extends SearchResult {
protected String slug;
@ -9,16 +7,14 @@ public class TheTVDBSearchResult extends SearchResult {
protected String overview;
protected String network;
protected String status;
protected URL banner;
public TheTVDBSearchResult(int id, String name, String[] aliasNames, String slug, SimpleDate firstAired, String overview, String network, String status, URL banner) {
public TheTVDBSearchResult(int id, String name, String[] aliasNames, String slug, SimpleDate firstAired, String overview, String network, String status) {
super(id, name, aliasNames);
this.slug = slug;
this.firstAired = firstAired;
this.overview = overview;
this.network = network;
this.status = status;
this.banner = banner;
}
public String getSlug() {
@ -41,8 +37,4 @@ public class TheTVDBSearchResult extends SearchResult {
return status;
}
public URL getBanner() {
return banner;
}
}