torrentapi

package module
v1.0.3 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

A simple library to access RARBG Torrentapi

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

good
https://torrentapi.org/pubapi_v2.php?get_token=get_token&app_id=1

bad
https://torrentapi.org/pubapi_v2.php?mode=search&token=51o6g0csth&search_string=2020

usage The API at torrentapi.org asks you to provide an application id.

torrentapi.AppID = "insert your app name here"

docs Below is a copy of the torrentapi.org documentation, that somehow does

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 DEPRECATED as of 12.09.2015 Searching by tvrage : mode=search&search_tvrage=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) List

func (a *API) List() (TorrentResults, error)

List lists the newest torrrents, this has to be last function in chain.

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() (TorrentResults, 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          `json:"error"`
	ErrorCode int             `json:"error_code"`
	Torrents  json.RawMessage `json:"torrent_results"`
}

APIResponse from Torrent API.

type EpisodeInfo

type EpisodeInfo struct {
	AirDate    string `json:"airdate"`
	EpisodeNum string `json:"epnum"`
	ImDB       string `json:"imdb"`
	SeasonNum  string `json:"seasonnum"`
	TheMovieDb string `json:"themoviedb"`
	Title      string `json:"title"`
	TvDB       string `json:"tvdb"`
	TvRage     string `json:"tvrage"`
}

EpisodeInfo keepsinformation from "episode_info" key from results. Some of the fields may be empty.

type Option

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

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

func APIURL

func APIURL(url string) Option

APIURL sets URL for TorrentAPI.

func MaxRetries

func MaxRetries(r int) Option

MaxRetries sets maximum retries after 429 Too Many Requests response.

func RequestDelay

func RequestDelay(d time.Duration) Option

RequestDelay sets delay between requests.

func TokenExpiration

func TokenExpiration(d time.Duration) Option

TokenExpiration sets time after token expires.

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      `json:"category"`
	Download    string      `json:"download"`
	EpisodeInfo EpisodeInfo `json:"episode_info"`
	Filename    string      `json:"filename"`
	InfoPage    string      `json:"info_page"`
	Leechers    int         `json:"leechers"`
	PubDate     string      `json:"pubdate"`
	Ranked      int         `json:"ranked"`
	Seeders     int         `json:"seeders"`
	Size        uint64      `json:"size"`
	Title       string      `json:"title"`
}

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

type TorrentResults

type TorrentResults []TorrentResult

TorrentResults represents multiple results.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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