Skip to content

Commit

Permalink
Switch to search type search for some indexers with no IDs but query …
Browse files Browse the repository at this point in the history
…words
  • Loading branch information
theotherp committed Dec 6, 2021
1 parent 39dfc70 commit 077a3fc
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 25 deletions.
16 changes: 13 additions & 3 deletions core/src/main/java/org/nzbhydra/indexers/Newznab.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class Newznab extends Indexer<Xml> {
private static Pattern GUID_PATTERN = Pattern.compile("(.*\\/)?([a-zA-Z0-9@\\.]+)(#\\w+)?");

private static final List<String> HOSTS_NOT_SUPPORTING_EMPTY_TYPE_SEARCH = Arrays.asList("nzbgeek", "6box");
private static final List<String> HOSTS_NOT_SUPPORTING_SPECIAL_TYPE_Q_SEARCH = Arrays.asList("dognzb", "nzbplanet");

private static final Pattern TV_PATTERN = Pattern.compile("(?<showtitle>[\\w\\.\\-_]+)S(?<season>\\d+)e(?<episode>\\d+)|(?<season2>\\d{1,2})x(?<episode2>\\d{1,2})", Pattern.CASE_INSENSITIVE);

Expand Down Expand Up @@ -123,9 +124,14 @@ protected UriComponentsBuilder buildSearchUrl(SearchRequest searchRequest, Integ
searchType = SearchType.SEARCH;
}
boolean searchTypeTvOrMovie = searchRequest.getSearchType() == SearchType.MOVIE || searchRequest.getSearchType() == SearchType.TVSEARCH;
if (searchTypeTvOrMovie && searchRequest.getIdentifiers().isEmpty() && isIndexerNotSupportingEmptyTypeSearch()) {
debug("Switching search type to SEARCH because this indexer doesn't allow using search type MOVIE/TVSEARCH without identifiers");
searchType = SearchType.SEARCH;
if (searchTypeTvOrMovie && searchRequest.getIdentifiers().isEmpty()) {
if (!searchRequest.getQuery().isPresent() && isIndexerNotSupportingEmptyTypeSearch()) {
debug("Switching search type to SEARCH because this indexer doesn't allow using search type MOVIE/TVSEARCH without identifiers and without query");
searchType = SearchType.SEARCH;
} else if (searchRequest.getQuery().isPresent() && isIndexerNotSupportingSpecialTypeQSearch()) {
debug("Switching search type to SEARCH because this indexer doesn't allow using search type MOVIE/TVSEARCH with a query");
searchType = SearchType.SEARCH;
}
}
componentsBuilder = componentsBuilder.queryParam("t", searchType.name().toLowerCase()).queryParam("extended", "1");

Expand Down Expand Up @@ -252,6 +258,10 @@ private boolean isIndexerNotSupportingEmptyTypeSearch() {
return HOSTS_NOT_SUPPORTING_EMPTY_TYPE_SEARCH.stream().anyMatch(x -> getConfig().getHost().toLowerCase().contains(x));
}

private boolean isIndexerNotSupportingSpecialTypeQSearch() {
return HOSTS_NOT_SUPPORTING_SPECIAL_TYPE_Q_SEARCH.stream().anyMatch(x -> getConfig().getHost().toLowerCase().contains(x));
}

protected String addRequiredAndforbiddenWordsToQuery(SearchRequest searchRequest, String query) {
if (Strings.isNullOrEmpty(query)) {
//Indexers do not allow having a query that only contains forbidden words
Expand Down
62 changes: 40 additions & 22 deletions core/src/main/resources/changelog.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
[ {
"version" : "v3.18.1",
"date" : "2021-12-01",
"changes" : [ {
"type" : "fix",
"text" : "Fix exception when unexpected java version is found. Why the fuck does every JDK have to have its own version format?"
} ],
"final" : true
}, {
"version" : "v3.18.0",
"date" : "2021-11-27",
"changes" : [ {
"type" : "fix",
"text" : "Make sure that when the NZBHydra API is accessed with a duplicate /api in the URL this is not interpreted as wanting to only use an indexer with the name \"api\"."
}, {
"type" : "feature",
"text" : "Abort on startup if incompatible Java version is used."
} ],
"final" : true
}, {
"version" : "v3.17.3",
[
{
"version": "v3.18.2",
"changes": [
{
"type": "fix",
"text": "Some indexers do not support movie/tvsearch type queries without IDs but with word based queries (I know of nzbplanet and dognzb). For these indexers the search type is automatically switched to search when no IDs but a word query is given."
}
],
"final": true
},
{
"version": "v3.18.1",
"date": "2021-12-01",
"changes": [
{
"type": "fix",
"text": "Fix exception when unexpected java version is found. Why the fuck does every JDK have to have its own version format?"
}
],
"final": true
},
{
"version": "v3.18.0",
"date": "2021-11-27",
"changes": [
{
"type": "fix",
"text": "Make sure that when the NZBHydra API is accessed with a duplicate /api in the URL this is not interpreted as wanting to only use an indexer with the name \"api\"."
},
{
"type": "feature",
"text": "Abort on startup if incompatible Java version is used."
}
],
"final": true
},
{
"version": "v3.17.3",
"date" : "2021-10-05",
"changes" : [ {
"type" : "fix",
Expand Down Expand Up @@ -3360,4 +3378,4 @@
"text" : "First public release. Welcome!"
} ],
"final" : true
} ]
} ]

0 comments on commit 077a3fc

Please sign in to comment.