Git Product home page Git Product logo

newznab-api's Introduction

This project requires JVM version of at least 1.8

newznab-api top

NewzNab API in java

Table of Contents top

The NewzNab API for java

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.

Maven

<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>

Gradle < 2.1

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')
	...
}

Gradle >= 2.1

dependencies {
	...
	runtime 'org.apache.logging.log4j:log4j-slf4j-impl:2.5'
	runtime 'org.apache.logging.log4j:log4j-core:2.5'
	...
}

Setting up the logging:

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:

cobertura dependencies

  • net.sourceforge.cobertura:cobertura:2.1.1: (It may be available on one of: bintray mvn central)

compile dependencies

runtime dependencies

testCompile dependencies

testRuntime dependencies

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 synapticlooptemplar->documentr

--

newznab-api's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

newznab-api's Issues

Error Conflicting getter definitions

Nice library dude, but looks like there is a conflict with your getters in the Item modal.

ERROR synapticloop.newznab.api.NewzNabApi - Error 'Conflicting getter definitions for property "guid": synapticloop.newznab.api.response.model.Item#getGuid(0 params) vs synapticloop.newznab.api.response.model.Item#getDetailsLink(0 params)

I'm not doing anything fancy, just calling a simple call with a query

public List<Item> getMovies(String query) {
    try {
        return newzNabApi.search(query).getItems();
    } catch (NewzNabApiException | IOException e) {
        log.error("search failed {}", e.getMessage());
    }
    return null;
}

And I've wired up newzNabApi as follows

@Configuration
public class NewznabConfig {
    private static final String API_KEY = "***";

    private static final String NEWZNAB_API = "***";

    @Bean
    public NewzNabApi NewzNabApi() {
        return new NewzNabApi(NEWZNAB_API, API_KEY);
    }
}

Any insight?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.