Searching

Search for indexed releases through a variety of methods.

Basic Search

The basic search method newzNabApi.search(String query) will return a list of all of the matching releases that contains the query in a variety of fields and attributes (i.e. metadata).

By default all searches return 100 results, to iterate through them, the API allows an offset parameter to retrieve further results.

import java.io.IOException;
import java.util.List;

import synapticloop.newznab.api.NewzNabApi;
import synapticloop.newznab.api.exception.NewzNabApiException;
import synapticloop.newznab.api.response.SearchResponse;
import synapticloop.newznab.api.response.model.Item;

public class SearchIteration {

	public static void main(String[] args) throws IOException, NewzNabApiException {
		NewzNabApi newzNabApi = new NewzNabApi("YOUR_API_URL", "YOUR_API_KEY");
		SearchResponse searchResponse = null; 

		// get the total number of results
		Long total = Long.MAX_VALUE;
		int offset = 0;
		while(offset < total) {
			searchResponse = newzNabApi.search("something", offset);
			printResults(searchResponse);
			total = searchResponse.getTotal();
			offset = offset + 100;
		}
	}

	private static void printResults(SearchResponse searchResponse) {
		List items = searchResponse.getItems();
		for (Item item : items) {
			System.out.println("Found an item: " + item.getTitle());
		}
	}

}
see SearchIteration.java

To search with a category (or multiple categories) invoke the newzNabApi.search(String query, int offset, int[] categories) method.

import java.io.IOException;

import synapticloop.newznab.api.Category;
import synapticloop.newznab.api.NewzNabApi;
import synapticloop.newznab.api.exception.NewzNabApiException;
import synapticloop.newznab.api.response.SearchResponse;

public class Search {

	public static void main(String[] args) throws IOException, NewzNabApiException {
		NewzNabApi newzNabApi = new NewzNabApi("YOUR_API_URL", "YOUR_API_KEY");
		SearchResponse searchResponse = newzNabApi.search("something", 0, new int[] { 
				Category.CATEGORY_AUDIO_AUDIOBOOK, 
				Category.CATEGORY_AUDIO_VIDEO}
				);

		// now do something with the results
	}
}
see Search.java

Specific Search

Some indexers also support more specific (or targeted searches) with additional options that are only pertinent to the category.

this relies on the functionality of the indexer to be present, and that the lookups on the releases can be found.

Book

The book search allows search by title and author

Music

The music search allows search by year, label, album, artist and track

TV

The TV search allows search by episode and season numbers along with identifiers from popular TV index sites (TV Rage, TV Maze, TVDB)

Movie

The movie search allows search by genre and the IMBD id

import java.io.IOException;

import synapticloop.newznab.api.NewzNabApi;
import synapticloop.newznab.api.exception.NewzNabApiException;
import synapticloop.newznab.api.response.SearchResponse;

public class SpecificSearch {

	public static void main(String[] args) throws IOException, NewzNabApiException {
		NewzNabApi newzNabApi = new NewzNabApi("YOUR_API_URL", "YOUR_API_KEY");

		// use the Book Search
		SearchResponse searchBook = newzNabApi.searchBook(
				"query", // the search term
				0, // the offset for the result
				100, // the maximum number of results to return
				"this is the title", // the title of the book
				"author's name", // the author
				100, // the maximum number of days to search back for
				false, // whether to delete from the cart 
				false // whether to return extended attributes in the results
				);

		// use the Movies Search
		newzNabApi.searchMovie(
				"query", // the search term
				"genre", // the genre of the film 
				0, // the offset for the result
				100, // the maximum number of results to return
				100, // the maximum number of days to search back for
				"imdbId", // the imdbId
				false, // whether to delete from the cart 
				false // whether to return extended attributes in the results
				);

		// use the TV Search 
		newzNabApi.searchTv(
				"query", // the search term
				1, // the season
				1,// the episode 
				0, // the offset for the result
				100, // the maximum number of results to return
				100, // the maximum number of days to search back for
				100, // the rage Id, 
				100, // the tvdb Id, 
				100, // the tv Maze Id, 
				false, // whether to delete from the cart 
				false // whether to return extended attributes in the results
				);

		newzNabApi.searchMusic(
				"query", // the search term
				0, // the offset for the result
				100, // the maximum number of results to return
				"album", // the album
				"artist", // the artist
				"label", // the label
				"track", // the track 
				2000, // the year of release
				new String[0], // the genres to search within
				new int[0] , // the array of categories
				100, // the maximum number of days to search back for
				false, // whether to delete from the cart 
				false // whether to return extended attributes in the results
				);

	}
}
see SpecificSearch.java