Skip to content

Commit

Permalink
Fix parsing of newznab results with empty attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
theotherp committed Jan 30, 2025
1 parent 64af1cd commit bc0d4dd
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 6 deletions.
4 changes: 3 additions & 1 deletion core/src/main/java/org/nzbhydra/indexers/Newznab.java
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,9 @@ protected String getEnclosureType() {
}

protected void parseAttributes(NewznabXmlItem item, SearchResultItem searchResultItem) {
Map<String, String> attributes = item.getNewznabAttributes().stream().collect(Collectors.toMap(NewznabAttribute::getName, NewznabAttribute::getValue, (a, b) -> b));
Map<String, String> attributes = item.getNewznabAttributes().stream()
.filter(x -> x.getValue() != null)
.collect(Collectors.toMap(NewznabAttribute::getName, NewznabAttribute::getValue, (a, b) -> b));
List<Integer> newznabCategories = item.getNewznabAttributes().stream().filter(x -> x.getName().equals("category") && !"None".equals(x.getValue()) && !Strings.isNullOrEmpty(x.getValue())).map(newznabAttribute -> {
try {
return Integer.parseInt(newznabAttribute.getValue());
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/resources/changelog.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#@formatter:off
- version: "v7.12.3"
date: "2025-01-30"
changes:
- type: "fix"
text: "Fix parsing when indexers return empty newznab attributes. This should fix searches for an indexer which you may know (or not)."
- type: "note"
text: "On a personal note: I had a heart attack a week ago and had to be reanimated. Without going into details bug fixes may take some more time in the near future. Take care."
final: true
- version: "v7.12.2"
date: "2025-01-24"
changes:
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/resources/static/js/nzbhydra.js
Original file line number Diff line number Diff line change
Expand Up @@ -10843,14 +10843,14 @@ function SearchResultsController($stateParams, $scope, $http, $q, $timeout, $doc

if (ConfigService.getSafe().emby.embyApiKey) {
if ($stateParams.mode === "tvsearch") {
$http.get("http://127.0.0.1:5076/internalapi/emby/isSeriesAvailable?tvdbId=" + $stateParams.tvdbId).then(function (result) {
$http.get("internalapi/emby/isSeriesAvailable?tvdbId=" + $stateParams.tvdbId).then(function (result) {
console.log("Show already available on emby: " + result.data);
$scope.showEmbyResults = result.data;
$scope.embyType = "show";
});

} else if ($stateParams.mode === "movie") {
$http.get("http://127.0.0.1:5076/internalapi/emby/isMovieAvailable?tmdbId=" + $stateParams.tmdbId).then(function (result) {
$http.get("internalapi/emby/isMovieAvailable?tmdbId=" + $stateParams.tmdbId).then(function (result) {
console.log("Movie already available on emby: " + result.data);
$scope.showEmbyResults = result.data;
$scope.embyType = "movie";
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/static/js/nzbhydra.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions core/src/test/java/org/nzbhydra/indexers/NewznabTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ void shouldCreateSearchResultItem() throws Exception {
rssItem.getNewznabAttributes().add(new NewznabAttribute("usenetdate", new JaxbPubdateAdapter().marshal(Instant.ofEpochSecond(6666666))));
rssItem.getNewznabAttributes().add(new NewznabAttribute("category", "5000"));
rssItem.getNewznabAttributes().add(new NewznabAttribute("category", "5050"));
rssItem.getNewznabAttributes().add(new NewznabAttribute("category", null));

SearchResultItem item = testee.createSearchResultItem(rssItem);
assertThat(item.getLink()).isEqualTo("http://indexer.com/nzb/123");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ void shouldParseResponseFromNzbFinder() throws Exception {
assertThat(rssRoot.getRssChannel().getItems().get(0).getPubDate()).isNotNull();
}

@Test
void shouldParseResponseUnnamed() throws Exception {
NewznabXmlRoot rssRoot = getRssRootFromXml("unnamedv2.xml");

assertThat(rssRoot.getRssChannel().getNewznabResponse().getTotal()).isEqualTo(Integer.valueOf(2000));
assertThat(rssRoot.getRssChannel().getItems().get(0).getPubDate()).isNotNull();
}

@Test
void shouldParseResponseFromNewztown() throws Exception {
NewznabXmlRoot rssRoot = getRssRootFromXml("newztownResponse.xml");
Expand Down
4 changes: 2 additions & 2 deletions core/ui-src/js/search-results-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1022,14 +1022,14 @@ function SearchResultsController($stateParams, $scope, $http, $q, $timeout, $doc

if (ConfigService.getSafe().emby.embyApiKey) {
if ($stateParams.mode === "tvsearch") {
$http.get("http://127.0.0.1:5076/internalapi/emby/isSeriesAvailable?tvdbId=" + $stateParams.tvdbId).then(function (result) {
$http.get("internalapi/emby/isSeriesAvailable?tvdbId=" + $stateParams.tvdbId).then(function (result) {
console.log("Show already available on emby: " + result.data);
$scope.showEmbyResults = result.data;
$scope.embyType = "show";
});

} else if ($stateParams.mode === "movie") {
$http.get("http://127.0.0.1:5076/internalapi/emby/isMovieAvailable?tmdbId=" + $stateParams.tmdbId).then(function (result) {
$http.get("internalapi/emby/isMovieAvailable?tmdbId=" + $stateParams.tmdbId).then(function (result) {
console.log("Movie already available on emby: " + result.data);
$scope.showEmbyResults = result.data;
$scope.embyType = "movie";
Expand Down

0 comments on commit bc0d4dd

Please sign in to comment.