This project requires JVM version of at least 1.8
newznab-api top
NewzNab API in java
Table of Contents top
- newznab-api
- Table of Contents
- Building the Package
- Running the Tests
- Logging - slf4j
- Artefact Publishing - Github
- Artefact Publishing - Bintray
Easily and quickly connect to your favourite NewzNab provider's API programmatically
Provided you have a Usenet Indexer that is based on the NewzNab API protocol, this API will allow you to:
-
Get various personal feeds
- Your cart
- Your 'My Shows' section
- Your 'My Movies' section
-
Get feeds for
- Movies
- Consoles
- PC (Games)
- Other
- TV
- Audio
-
Commenting
- add comments
- view comments
-
Download
- The NZB file
- The nfo
-
Search
- generic search
- TV search
- Book Search
- Movie Search
- Audio Search
See the following file for a quick start:
package synapticloop.newznab.api;
import java.io.IOException;
import java.util.List;
import synapticloop.newznab.api.exception.NewzNabApiException;
import synapticloop.newznab.api.response.CartResponse;
import synapticloop.newznab.api.response.CommentResponse;
import synapticloop.newznab.api.response.CommentsResponse;
import synapticloop.newznab.api.response.FeedResponse;
import synapticloop.newznab.api.response.SearchResponse;
import synapticloop.newznab.api.response.model.CommentItem;
import synapticloop.newznab.api.response.model.FeedItem;
import synapticloop.newznab.api.response.model.Item;
public class Main {
private static final String NEWZNAB_API = "http://lolo.sickbeard.com/api";
public static void main(String[] args) {
// Set up the API call - normally you would use the following line, but
// for example purposes - the lolo.sickbeard.com API will work
// NewzNabApi newzNabApi = new NewzNabApi("YOUR_API_URL", "YOUR_API_KEY");
NewzNabApi newzNabApi = new NewzNabApi(NEWZNAB_API);
search(newzNabApi);
// you can also get various feeds
try {
printFeedResponse("AUDIO", newzNabApi.getFeedForAudio());
printFeedResponse("CONSOLES", newzNabApi.getFeedForConsoles());
printFeedResponse("MOVIES", newzNabApi.getFeedForMovies());
printFeedResponse("OTHER", newzNabApi.getFeedForOther());
printFeedResponse("PC", newzNabApi.getFeedForPc());
printFeedResponse("TV", newzNabApi.getFeedForTv());
printFeedResponse("SITE", newzNabApi.getFeedForSite());
} catch (IOException | NewzNabApiException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// now get some details
try {
SearchResponse searchResponse = getSearchResponse(newzNabApi, 0);
// get the first result
Item item = searchResponse.getItems().get(0);
String guid = item.getGuid();
// now that we have the guid - get some of the details
String nfo = newzNabApi.getNfo(guid);
System.out.println(nfo);
CommentsResponse comments = newzNabApi.getComments(guid);
List<CommentItem> commentItems = comments.getItems();
System.out.println("Found " + commentItems.size() + " comments");
for (CommentItem commentItem : commentItems) {
System.out.println(" [COMMENT]: " + commentItem.getComment());
}
CommentResponse commentResponse = newzNabApi.addComment(guid, "We can add a comment");
System.out.println("Added a comment with id: " + commentResponse.getId());
// we can also add this to our cart
CartResponse cartAddResponse = newzNabApi.cartAdd(guid);
System.out.println("Cart add with id: " + cartAddResponse.getId());
// we can also list the cart contents
FeedResponse feedForCart = newzNabApi.getFeedForCart();
List<FeedItem> feedItems = feedForCart.getFeedItems();
for (FeedItem feedItem : feedItems) {
System.out.println("Found the following in the cart, guid: " + feedItem.getGuid().getGuid() + ", title" + feedItem.getTitle());
}
CartResponse cartDeleteResponse = newzNabApi.cartDelete(guid);
System.out.println("Cart delete with guid: " + cartDeleteResponse.getId());
} catch (NewzNabApiException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void printFeedResponse(String group, FeedResponse feedResponse) {
List<FeedItem> feedItems = feedResponse.getFeedItems();
for (FeedItem feedItem : feedItems) {
System.out.println("Found [" + group + "] item with title: " + feedItem.getTitle());
}
}
private static void search(NewzNabApi newzNabApi) {
try {
SearchResponse searchResponse = getSearchResponse(newzNabApi, 0);
System.out.println("Found " + searchResponse.getTotal() + " results for the search.");
printResults(searchResponse);
searchResponse = getSearchResponse(newzNabApi, 10);
printResults(searchResponse);
} catch (IOException | NewzNabApiException ex) {
ex.printStackTrace();
}
}
private static SearchResponse getSearchResponse(NewzNabApi newzNabApi, int offset) throws NewzNabApiException, IOException {
SearchResponse searchResponse = newzNabApi.search(
"wanted", // the search phrase
offset, // the offset
10, // the max number of results to return
-1, // the number of days back to search - in this case all
false, // delete from cart
false, // return extended attributes
null, // the categories to search in - in this case we are searching all
null // the usenet groups to search in - all of them if null
);
return searchResponse;
}
private static void printResults(SearchResponse searchResponse) {
List<Item> searchItems = searchResponse.getItems();
for (Item item : searchItems) {
System.out.println(" Found result in category: [" + item.getCategoryName() + "] with name: " + item.getTitle());
}
}
}
Building the Package top
*NIX/Mac OS X top
From the root of the project, simply run
./gradlew build
Windows top
./gradlew.bat build
This will compile and assemble the artefacts into the build/libs/
directory.
Note that this may also run tests (if applicable see the Testing notes)
Running the Tests top
*NIX/Mac OS X top
From the root of the project, simply run
gradle --info test
if you do not have gradle installed, try:
gradlew --info test
Windows top
From the root of the project, simply run
gradle --info test
if you do not have gradle installed, try:
./gradlew.bat --info test
The --info
switch will also output logging for the tests
Logging - slf4j top
slf4j is the logging framework used for this project. In order to set up a logging framework with this project, sample configurations are below:
Log4j top
You will need to include dependencies for this - note that the versions may need to be updated.
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.5</version>
<scope>runtime</scope>
</dependency>
dependencies {
...
runtime(group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.5', ext: 'jar')
runtime(group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.5', ext: 'jar')
...
}
dependencies {
...
runtime 'org.apache.logging.log4j:log4j-slf4j-impl:2.5'
runtime 'org.apache.logging.log4j:log4j-core:2.5'
...
}
A sample log4j2.xml
is below:
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
Artefact Publishing - Github top
This project publishes artefacts to GitHub
Note that the latest version can be found https://github.com/synapticloopltd/newznab-api/releases
As such, this is not a repository, but a location to download files from.
Artefact Publishing - Bintray top
This project publishes artefacts to bintray
Note that the latest version can be found https://bintray.com/synapticloop/maven/newznab-api/view
maven setup top
this comes from the jcenter bintray, to set up your repository:
<?xml version="1.0" encoding="UTF-8" ?>
<settings xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd' xmlns='http://maven.apache.org/SETTINGS/1.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray-plugins</name>
<url>http://jcenter.bintray.com</url>
</pluginRepository>
</pluginRepositories>
<id>bintray</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>bintray</activeProfile>
</activeProfiles>
</settings>
gradle setup top
Repository
repositories {
maven {
url "http://jcenter.bintray.com"
}
}
or just
repositories {
jcenter()
}
Dependencies - Gradle top
dependencies {
runtime(group: 'synapticloop', name: 'newznab-api', version: '1.4.1', ext: 'jar')
compile(group: 'synapticloop', name: 'newznab-api', version: '1.4.1', ext: 'jar')
}
or, more simply for versions of gradle greater than 2.1
dependencies {
runtime 'synapticloop:newznab-api:1.4.1'
compile 'synapticloop:newznab-api:1.4.1'
}
Dependencies - Maven top
<dependency>
<groupId>synapticloop</groupId>
<artifactId>newznab-api</artifactId>
<version>1.4.1</version>
<type>jar</type>
</dependency>
Dependencies - Downloads top
You will also need to download the following dependencies:
net.sourceforge.cobertura:cobertura:2.1.1
: (It may be available on one of: bintray mvn central)
org.apache.httpcomponents:httpclient:4.5.3
: (It may be available on one of: bintray mvn central)commons-io:commons-io:2.5
: (It may be available on one of: bintray mvn central)com.fasterxml.jackson.core:jackson-databind:2.8.5
: (It may be available on one of: bintray mvn central)org.slf4j:slf4j-api:1.7.21
: (It may be available on one of: bintray mvn central)org.json:json:20160810
: (It may be available on one of: bintray mvn central)
org.apache.httpcomponents:httpclient:4.5.3
: (It may be available on one of: bintray mvn central)commons-io:commons-io:2.5
: (It may be available on one of: bintray mvn central)com.fasterxml.jackson.core:jackson-databind:2.8.5
: (It may be available on one of: bintray mvn central)org.slf4j:slf4j-api:1.7.21
: (It may be available on one of: bintray mvn central)org.json:json:20160810
: (It may be available on one of: bintray mvn central)
junit:junit:4.12
: (It may be available on one of: bintray mvn central)org.mockito:mockito-all:2.0.2-beta
: (It may be available on one of: bintray mvn central)org.apache.logging.log4j:log4j-slf4j-impl:2.7
: (It may be available on one of: bintray mvn central)org.apache.logging.log4j:log4j-core:2.7
: (It may be available on one of: bintray mvn central)org.powermock:powermock:1.6.6
: (It may be available on one of: bintray mvn central)org.powermock:powermock-api-mockito:1.6.6
: (It may be available on one of: bintray mvn central)org.powermock:powermock-module-junit4:1.6.6
: (It may be available on one of: bintray mvn central)cglib:cglib:3.2.4
: (It may be available on one of: bintray mvn central)
junit:junit:4.12
: (It may be available on one of: bintray mvn central)org.mockito:mockito-all:2.0.2-beta
: (It may be available on one of: bintray mvn central)org.apache.logging.log4j:log4j-slf4j-impl:2.7
: (It may be available on one of: bintray mvn central)org.apache.logging.log4j:log4j-core:2.7
: (It may be available on one of: bintray mvn central)org.powermock:powermock:1.6.6
: (It may be available on one of: bintray mvn central)org.powermock:powermock-api-mockito:1.6.6
: (It may be available on one of: bintray mvn central)org.powermock:powermock-module-junit4:1.6.6
: (It may be available on one of: bintray mvn central)cglib:cglib:3.2.4
: (It may be available on one of: bintray mvn central)
NOTE: You may need to download any dependencies of the above dependencies in turn (i.e. the transitive dependencies)
--
This README.md file was hand-crafted with care utilising synapticloop
templar
->
documentr
--