-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support DETAILS function from Newznab API spec
Closes #942
- Loading branch information
Showing
8 changed files
with
142 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
core/src/main/java/org/nzbhydra/indexers/DetailsResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.nzbhydra.indexers; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import org.nzbhydra.searching.dtoseventsenums.SearchResultItem; | ||
import org.nzbhydra.springnative.ReflectionMarker; | ||
|
||
import java.io.Serializable; | ||
|
||
@Data | ||
@ReflectionMarker | ||
@AllArgsConstructor | ||
public class DetailsResult implements Serializable { | ||
|
||
private boolean successful; | ||
private SearchResultItem searchResultItem; | ||
private String errorMessage; | ||
|
||
|
||
public static DetailsResult unsuccessful(String error) { | ||
return new DetailsResult(false, null, error); | ||
} | ||
|
||
public static DetailsResult withItem(SearchResultItem item) { | ||
return new DetailsResult(true, item, null); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ | |
public enum IndexerApiAccessType { | ||
NFO, | ||
NZB, | ||
SEARCH | ||
SEARCH, | ||
DETAILS | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
core/src/main/java/org/nzbhydra/searching/DetailsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* (C) Copyright 2024 TheOtherP ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.nzbhydra.searching; | ||
|
||
import org.nzbhydra.indexers.DetailsResult; | ||
import org.nzbhydra.indexers.Indexer; | ||
import org.nzbhydra.indexers.exceptions.IndexerAccessException; | ||
import org.nzbhydra.searching.db.SearchResultEntity; | ||
import org.nzbhydra.searching.db.SearchResultRepository; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Optional; | ||
|
||
@Component | ||
public class DetailsProvider { | ||
|
||
private final SearchResultRepository searchResultRepository; | ||
private final SearchModuleProvider searchModuleProvider; | ||
|
||
public DetailsProvider(SearchResultRepository searchResultRepository, SearchModuleProvider searchModuleProvider) { | ||
this.searchResultRepository = searchResultRepository; | ||
this.searchModuleProvider = searchModuleProvider; | ||
} | ||
|
||
public DetailsResult getDetails(String resultId) { | ||
Optional<SearchResultEntity> searchResult = searchResultRepository.findById(Long.parseLong(resultId)); | ||
if (searchResult.isEmpty()) { | ||
return null; | ||
} | ||
Indexer indexer = searchModuleProvider.getIndexerByName(searchResult.get().getIndexer().getName()); | ||
try { | ||
return indexer.getDetails(searchResult.get().getIndexerGuid()); | ||
} catch (IndexerAccessException e) { | ||
return DetailsResult.unsuccessful(e.getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters