imdb2torrent

package module
v0.0.0-...-6f3ee1a Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2021 License: AGPL-3.0 Imports: 17 Imported by: 0

README

imdb2torrent

Go library for finding torrents for movies and TV shows by IMDb ID on YTS, The Pirate Bay, 1337x, RARBG and ibit

Usage

You can either use a site-specific client:

package main

import (
    "context"
    "fmt"

    "github.com/deflix-tv/imdb2torrent"
    "go.uber.org/zap"
)

func main() {
    // Create new client
    yts := imdb2torrent.NewYTSclient(imdb2torrent.DefaultYTSclientOpts, imdb2torrent.NewInMemoryCache(), zap.NewNop(), false)

    // Fetch torrents for a movie
    // Here we use the IMDb ID of "Night of the Living Dead" from 1968, which is in the public domain
    torrents, err := yts.FindMovie(context.Background(), "tt0063350")
    if err != nil {
        panic(err)
    }

    // Iterate through results and print their magnet URLs
    for _, torrent := range torrents {
        fmt.Printf("Found torrent: %v\n", torrent.MagnetURL)
    }
}

Or use the imdb2torrent.Client, which uses multiple site-specific clients concurrently.

For more detailed examples see examples.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultIbitClientOpts = IbitClientOptions{
	BaseURL:  "https://ibit.am",
	Timeout:  5 * time.Second,
	CacheAge: 24 * time.Hour,
}
View Source
var DefaultLeetxClientOpts = LeetxClientOptions{
	BaseURL:  "https://1337x.to",
	Timeout:  5 * time.Second,
	CacheAge: 24 * time.Hour,
}
View Source
var DefaultRARBGclientOpts = RARBGclientOptions{
	BaseURL:  "https://torrentapi.org",
	Timeout:  5 * time.Second,
	CacheAge: 24 * time.Hour,
}
View Source
var DefaultTPBclientOpts = TPBclientOptions{
	BaseURL:  "https://apibay.org",
	Timeout:  5 * time.Second,
	CacheAge: 24 * time.Hour,
}
View Source
var DefaultYTSclientOpts = YTSclientOptions{
	BaseURL:  "https://yts.mx",
	Timeout:  5 * time.Second,
	CacheAge: 24 * time.Hour,
}

Functions

func NewIbitClient

func NewIbitClient(opts IbitClientOptions, cache Cache, logger *zap.Logger, logFoundTorrents bool) *ibitClient

func NewLeetxClient

func NewLeetxClient(opts LeetxClientOptions, cache Cache, metaGetter MetaGetter, logger *zap.Logger, logFoundTorrents bool) *leetxClient

func NewRARBGclient

func NewRARBGclient(opts RARBGclientOptions, cache Cache, metaGetter MetaGetter, logger *zap.Logger, logFoundTorrents bool) *rarbgClient

func NewTPBclient

func NewTPBclient(opts TPBclientOptions, cache Cache, metaGetter MetaGetter, logger *zap.Logger, logFoundTorrents bool) (*tpbClient, error)

func NewYTSclient

func NewYTSclient(opts YTSclientOptions, cache Cache, logger *zap.Logger, logFoundTorrents bool) *ytsClient

Types

type Cache

type Cache interface {
	Set(key string, results []Result) error
	Get(key string) ([]Result, time.Time, bool, error)
}

Cache is the interface that the imdb2torrent clients use for caching results. A package user must pass an implementation of this interface. Usually you create a simple wrapper around an existing cache package. An example implementation is the InMemoryCache in this package.

type CacheItem

type CacheItem struct {
	Results []Result
	Created time.Time
}

CacheItem combines Result objects and a creation time in a single struct. This can be useful for implementing the Cache interface, but is not necessarily required. See the InMemoryCache example implementation of the Cache interface for its usage.

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(siteClients map[string]MagnetSearcher, timeout, slowTimeout time.Duration, logger *zap.Logger) *Client

The timeouts here are not the ones used in the site-specific clients (for their HTTP requests). Instead they're used as limit for waiting for individual clients' results, as all of the searches are started concurrently. So for example while the 1337x client makes multiple requests, each with their respective timeout, the timeout here will be the max time that this "multi"-client waits for a result.

timeout is the regular timeout for clients that are expected to respond quickly. slowTimeout is the timeout for clients that make themselves known as being slow. For example the RARBG rate limit is 2s, so when we don't do any request for 15m and thus need to renew the token, the client has to wait 2s for the actual torrent request, which might be longer than you want. Seeting it to 2s leads to only getting RARBG results when 1. the token is fresh and 2. no concurrent requests are done (the latter because requests to RARBG get queued so we don't exceed the rate limit with concurrent requests). You might wonder why not use a single timeout value, but the separation is useful for example if you *expect* the fast clients to respond in under a second in most cases, but want to allow them 5s for some irregular circumstances, while you know ibit can take 10s and more, but for the average case you only want to wait 2s max (and not 5s).

func (*Client) FindMovie

func (c *Client) FindMovie(ctx context.Context, imdbID string) ([]Result, error)

FindMovie tries to find magnet URLs for the movie identified by the given IMDb ID. It only returns 720p, 1080p, 1080p 10bit, 2160p and 2160p 10bit videos. It caches results once they're found. It can return an empty slice and no error if no actual error occurred (for example if torrents where found but no >=720p videos).

func (*Client) FindTVShow

func (c *Client) FindTVShow(ctx context.Context, imdbID string, season, episode int) ([]Result, error)

FindTVShow tries to find magnet URLs for the TV show identified by the given IMDb ID + season + episode. It only returns 720p, 1080p, 1080p 10bit, 2160p and 2160p 10bit videos. It caches results once they're found. It can return an empty slice and no error if no actual error occurred (for example if torrents where found but no >=720p videos).

func (*Client) GetMagnetSearchers

func (c *Client) GetMagnetSearchers() map[string]MagnetSearcher

type IbitClientOptions

type IbitClientOptions struct {
	// Typically "https://ibit.am"
	BaseURL  string
	Timeout  time.Duration
	CacheAge time.Duration
}

func NewIbitClientOpts

func NewIbitClientOpts(baseURL string, timeout, cacheAge time.Duration) IbitClientOptions

type InMemoryCache

type InMemoryCache struct {
	// contains filtered or unexported fields
}

InMemoryCache is an example implementation of the Cache interface. It doesn't persist its data, so it's not suited for production use of the imdb2torrent package.

func NewInMemoryCache

func NewInMemoryCache() *InMemoryCache

NewInMemoryCache creates a new InMemoryCache.

func (*InMemoryCache) Get

func (c *InMemoryCache) Get(key string) ([]Result, time.Time, bool, error)

Get returns Result objects and the time they were cached from the cache. The boolean return value signals if the value was found in the cache.

func (*InMemoryCache) Set

func (c *InMemoryCache) Set(key string, results []Result) error

Set stores Result objects and the current time in the cache.

type LeetxClientOptions

type LeetxClientOptions struct {
	// Typically "https://1337x.to"
	BaseURL  string
	Timeout  time.Duration
	CacheAge time.Duration
}

func NewLeetxClientOpts

func NewLeetxClientOpts(baseURL string, timeout, cacheAge time.Duration) LeetxClientOptions

type MagnetSearcher

type MagnetSearcher interface {
	FindMovie(ctx context.Context, imdbID string) ([]Result, error)
	FindTVShow(ctx context.Context, imdbID string, season, episode int) ([]Result, error)
	IsSlow() bool
}

type Meta

type Meta struct {
	Title string
	Year  int
}

type MetaGetter

type MetaGetter interface {
	GetMovieSimple(ctx context.Context, imdbID string) (Meta, error)
	GetTVShowSimple(ctx context.Context, imdbID string, season, episode int) (Meta, error)
}

type RARBGclientOptions

type RARBGclientOptions struct {
	// Typically "https://torrentapi.org"
	BaseURL  string
	Timeout  time.Duration
	CacheAge time.Duration
}

func NewRARBGclientOpts

func NewRARBGclientOpts(baseURL string, timeout, cacheAge time.Duration) RARBGclientOptions

type Result

type Result struct {
	// Name of the torrent, as given on the torrent site.
	// E.g. "Night of the Living Dead (1968) [BluRay] [1080p] [YTS] [YIFY]"
	// Or "Night.Of.The.Living.Dead.1968.720p.BluRay.x264-CtrlHD [PublicHD]"
	Name string
	// Movie title, e.g. "Night of the Living Dead"
	Title string
	// Video resolution and source, e.g. "720p" or "720p (web)"
	Quality string
	// Torrent info_hash. Lowercase.
	InfoHash string
	// MagnetURL, usually containing the info_hash (can be uppercase), torrent name and a list of torrent trackers
	MagnetURL string
	// True if the client didn't do the search via IMDb ID but title, which can lead to inaccurate results
	Fuzzy bool
	// Size in bytes. 0 if it couldn't be determined.
	Size int
	// Number of seeders according to the torrent site
	Seeders int
}

type TPBclientOptions

type TPBclientOptions struct {
	// Typically "https://apibay.org" when connecting via clearnet.
	// Typically "http://piratebayztemzmv.onion" when connecting via Tor.
	BaseURL        string
	SocksProxyAddr string
	Timeout        time.Duration
	CacheAge       time.Duration
}

func NewTPBclientOpts

func NewTPBclientOpts(baseURL, socksProxyAddr string, timeout, cacheAge time.Duration) TPBclientOptions

type YTSclientOptions

type YTSclientOptions struct {
	// Typically "https://yts.mx"
	BaseURL  string
	Timeout  time.Duration
	CacheAge time.Duration
}

func NewYTSclientOpts

func NewYTSclientOpts(baseURL string, timeout, cacheAge time.Duration) YTSclientOptions

Directories

Path Synopsis
examples
yts

Jump to

Keyboard shortcuts

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