torrentapi

package module
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2021 License: OSL-3.0 Imports: 8 Imported by: 0

README

Torrentapi

Module to access RARBG Torrent API

https://pkg.go.dev/github.com/89z/torrentapi

When querying the api please use the app_id parameter with your app name so we can generate statistics for it. All responses are in json by default. Api endpoint is - https://torrentapi.org/pubapi_v2.php

To use this api you will need to first to get yourself a token get_token=get_token. Tokens automaticly expire in 15 minutes. The api has a 1req/2s limit.

Listing torrents

mode=list&token=xxxx

Searching torrents

mode=search&search_string=Test%20Search&token=xxxx

Searching by imdb

mode=search&search_imdb=tt123456&token=xxxx

Searching by tvdb

mode=search&search_tvdb=123456&token=xxxx

Searching by themoviedb

mode=search&search_themoviedb=123456&token=xxxx

Category filtering

You can use both categories from the site and strings to filter by category. There are 2 categories available in the api by string - tv and movies.

mode=search&search_imdb=tt123456&category=tv&token=xxxx

If you want to filter by categories from the site just append the category parameter which you can see from the search form on https://rarbg.com/torrents.php

mode=search&search_imdb=tt123456&category=18;41;49&token=xxxx

Limiting

limit parameter to anything will limit the results to 25,50 or 100. Default is 25

mode=search&search_imdb=tt123456&limit=100&token=xxxx

Sorting

sort parameter will sort the results by seeders,leechers,last. Default is last uploaded

mode=search&search_imdb=tt123456&sort=last&token=xxxx

Minimum seeders/leechers

You can specify the minimum amount of seeders and leechers using the min_seeders and min_leechers parameter.

mode=search&search_imdb=tt123456&min_seeders=50&token=xxxx
mode=search&search_imdb=tt123456&min_leechers=50&token=xxxx
mode=search&search_imdb=tt123456&min_seeders=50&min_leechers=50&token=xxxx

Result format

format parameter will return the results in the requested format - available formats are json and json_extended. Default is json. format json_extended returns a lot more info about the torrent.

mode=search&search_imdb=tt123456&format=json&token=xxxx

By default the api will return only ranked torrents ( internal ) , scene releases + -rarbg releases + -rartv releases. If you want other groups included in the results use the ranked parameter with a value of 0 to get them included.

mode=search&search_imdb=tt123456&ranked=0&token=xxxx

All api times are returned in UTC. All parameters can be mixed together.

Documentation

Overview

Package torrentapi provides simple and easy Golang interface for RARBG Torrent API v2 (https://torrentapi.org)

Index

Constants

View Source
const (
	// Version of supported torrentapi.
	Version = 2.0
	// DefaultAPIURL is a default value for APIURL option.
	DefaultAPIURL = "https://torrentapi.org/pubapi_v2.php?"
	// Defaulta.tokenExpiration is a default value for TokenExpiration option
	// (TorrentAPI exprires after 15 min, but let's expire it after 890 seconds
	// just to be safe.
	DefaultTokenExpiration = time.Second * 890
	// DefaultRequestDelay is a default delay between requests.
	DefaultRequestDelay = time.Second * 2
	// DefaultMaxRetries is a default value for MaxRetries option.
	DefaultMaxRetries = 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	APIToken Token
	Query    string
	// contains filtered or unexported fields
}

API provides interface to access Torrent API.

func New

func New(appID string, opts ...Option) (*API, error)

Init Initializes API object, fetches new token and returns API instance.

func (*API) Category

func (a *API) Category(category int) *API

Category adds category to search query.

func (*API) Format

func (a *API) Format(format string) *API

Format requests different results format, possible values json, json_extended. Please note that whith json format not all fields are populated in TorrentResult.

func (*API) Limit

func (a *API) Limit(limit int) *API

Limit adds limit to number of results.

func (*API) MinLeechers

func (a *API) MinLeechers(minLeech int) *API

MinLeechers specify minimum number of leechers.

func (*API) MinSeeders

func (a *API) MinSeeders(minSeed int) *API

MinSeeders specify minimum number of seeders.

func (*API) Ranked

func (a *API) Ranked(ranked bool) *API

Ranked sets if returned results should be ranked.

func (*API) Search

func (a *API) Search() ([]TorrentResult, error)

Search performs search, this has to be last function in chain.

func (*API) SearchString

func (a *API) SearchString(query string) *API

SearchString adds search string to search query.

func (*API) Sort

func (a *API) Sort(sort string) *API

Sort results based on seeders, leechers or last(default).

type APIResponse

type APIResponse struct {
	Error           string
	Error_Code      int
	Torrent_Results json.RawMessage
}

APIResponse from Torrent API.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is an interface used to set various options for API.

type Token

type Token struct {
	Expires time.Time `json:"-"`
	Token   string
}

Token keeps token and it's expiration date.

func (*Token) IsValid

func (t *Token) IsValid() bool

IsValid Check if token is still valid.

type TorrentResult

type TorrentResult struct {
	Category  string
	Download  string
	Filename  string
	Info_Page string
	Leechers  int
	PubDate   string
	Ranked    int
	Seeders   int
	Size      uint64
	Title     string
}

TorrentResult keeps information about single torrent returned from TorrentAPI. Some of the fields may be empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL