eztv

package module
v0.0.0-...-bb0e158 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: MIT Imports: 10 Imported by: 0

README

GO client for EZTV API

This package provides a simple API client for to the public EZTV API.


Download

go get github.com/PauliusLozys/eztv

Example usage

package main

import (
	"context"
	"fmt"

	"github.com/PauliusLozys/eztv"
)

func main() {
	client := eztv.New() // Create new client
	page, err := client.GetTorrents(context.TODO(), eztv.URLOptions{
		Limit:  10,
		Page:   1,
		ImdbID: "0944947",
	})
	if err != nil {
		panic(err)
	}
	for _, t := range page.Torrents {
		fmt.Println(t.Title)
	}
}

Example torrent stream usage

package main

import (
	"context"
	"fmt"

	"github.com/PauliusLozys/eztv"
)

func main() {
	client := eztv.New()
	for s := range client.TorrentStream(context.Background(), eztv.StreamOptions{LastTorrentID: 0, ImdbID: "tt7908628"}) {
		if s.Err != nil {
			fmt.Println("Error:", s.Err)
			continue
		}
		fmt.Println(s.Torrent.ID, s.Torrent.Title)
	}
}

Documentation

Index

Constants

View Source
const (
	EZTVBaseURL           = "https://eztv.re/api"
	StreamRecheckInterval = 5 * time.Minute
	MaxEZTVAPILimit       = 100
)

Variables

View Source
var ErrMissingImdbID = errors.New("missing imdbID")

Functions

This section is empty.

Types

type Client

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

Client is the EZTV API client. It can make requests to the EZTV API to retrieve data.

func New

func New(ops ...Option) *Client

New returns a new Client with a default http.Client.

Custom options can be passed to set different behaviour.

func (*Client) GetTorrents

func (c *Client) GetTorrents(ctx context.Context, urlOptions URLOptions) (*Page, error)

GetTorrents returns a Page of torrents from the EZTV API.

URLOptions allow to customize the data that is retrieved. API has a hard limit of max 100 torrents per page. More than that will default to 30.

func (*Client) TorrentStream

func (c *Client) TorrentStream(ctx context.Context, streamOptions StreamOptions) <-chan StreamTorrent

TorrentStream returns a channel that will push new torrents as they are added to the EZTV API.

StreamOptions allow to specify LastTorrentID from which to start the stream. If LastTorrentID is 0, it will do a full re-sync of all torrents for the given ImdbID.

If no ImdID is specified, it will return ErrMissingImdbID error from stream and close it.

If no RecheckInterval is specified, it will default to StreamRecheckInterval constant.

type Option

type Option func(*Client)

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL sets the base URL that will be used to make requests.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets the http.Client that will be used to make requests.

type Page

type Page struct {
	ImdbID        string    `json:"imdb_id"`
	TorrentsCount int       `json:"torrents_count"`
	Limit         int       `json:"limit"`
	Page          int       `json:"page"`
	Torrents      []Torrent `json:"torrents"`
}

type StreamOptions

type StreamOptions struct {
	// Specifies what shows torrents to fetch.
	ImdbID string
	// Specifies from which torrent ID to start the stream.
	LastTorrentID int
	// Specifies how often to re-check for new torrents.
	RecheckInterval time.Duration
}

StreamOptions allow to customize the behaviour of the TorrentStream.

type StreamTorrent

type StreamTorrent struct {
	Torrent

	Err error
}

type Torrent

type Torrent struct {
	ID                 int    `json:"id"`
	Hash               string `json:"hash"`
	Filename           string `json:"filename"`
	EpisodeURL         string `json:"episode_url"`
	TorrentURL         string `json:"torrent_url"`
	MagnetURL          string `json:"magnet_url"`
	Title              string `json:"title"`
	ImdbID             string `json:"imdb_id"`
	Season             string `json:"season"`
	Episode            string `json:"episode"`
	SmallScreenshotURL string `json:"small_screenshot"`
	LargeScreenshotURL string `json:"large_screenshot"`
	Seeds              int    `json:"seeds"`
	Peers              int    `json:"peers"`
	DateReleasedUnix   int    `json:"date_released_unix"`
	SizeBytes          string `json:"size_bytes"`
}

type URLOptions

type URLOptions struct {
	// Specifies the page number to retrieve. Default is 1.
	Page int
	// Specifies the number of torrents to retrieve. Default is 30.
	// API has a hard limit of 100 torrents per page and minimum limit of 1.
	Limit int
	// ImdbID tag will retrieve torrents only for that exact show.
	ImdbID string
}

URLOptions are the options that can be passed into EZTV API for custom data retrieval.

Jump to

Keyboard shortcuts

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