tlapi

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2023 License: MIT Imports: 13 Imported by: 0

README

About

TL API. See: Go reference

Using:

go get github.com/moistari/tlapi

Example:

// example/example.go
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/moistari/tlapi"
)

func main() {
	// read PHPSESSID, tluid, and tlpass cookies from browser ... hint: use github.com/zellyn/kooky !
	cl := tlapi.New(tlapi.WithCreds("<PHPSESSID>", "<tluid>", "<tlpass>"))
	req := tlapi.Search("framestor", "2019")
	for req.Next(context.Background(), cl) {
		torrent := req.Cur()
		fmt.Printf("%d: %s\n", torrent.ID, torrent.Name)
	}
	if err := req.Err(); err != nil {
		log.Fatal(err)
	}
}

Documentation

Index

Constants

View Source
const (
	FacetAdded   = "added"
	FacetName    = "name"
	FacetSeeders = "seeders"
	FacetSize    = "size"
	FacetTags    = "tags"
)

Facet filter names.

View Source
const (
	OrderAsc  = "asc"
	OrderDesc = "desc"
)

Order values.

View Source
const (
	OrderByNameSort    = "nameSort"
	OrderByAdded       = "added"
	OrderByNumComments = "numComments"
	OrderBySize        = "size"
	OrderByCompleted   = "completed"
	OrderBySeeders     = "seeders"
	OrderByLeechers    = "leechers"
)

OrderBy values.

View Source
const (
	RangeLast2Weeks  = "[NOW/HOUR-14DAYS TO NOW/HOUR+1HOUR]"
	RangeLastMonth   = "[NOW/HOUR-1MONTH TO NOW/HOUR+1HOUR]"
	RangeLastWeek    = "[NOW/HOUR-7DAYS TO NOW/HOUR+1HOUR]"
	RangeLast24Hours = "[NOW/MINUTE-24HOURS TO NOW/MINUTE+1MINUTE]"
	RangeLast48Hours = "[NOW/MINUTE-48HOURS TO NOW/MINUTE+1MINUTE]"
	RangeLast72Hours = "[NOW/MINUTE-72HOURS TO NOW/MINUTE+1MINUTE]"
	Seeders0to50     = "[0 TO 50]"
	Seeders200Plus   = "[201 TO *]"
	Seeders50to200   = "[51 TO 200]"
	Size0to750MB     = "[0 TO 786432000]"
	Size1_5GBto4_5GB = "[1610612736 TO 4831838208]"
	Size15GBPlus     = "[16106127360 TO *]"
	Size4_5GBto15GB  = "[4831838208 TO 16106127360]"
	Size750MBto1_5GB = "[786432000 TO 1610612736]"
)

Facet filter values.

View Source
const (
	CategoryMoviesCam               = 8
	CategoryMoviesTSTC              = 9
	CategoryMoviesDVDRipDVDScreener = 11
	CategoryMoviesWebRip            = 37
	CategoryMoviesHDRip             = 43
	CategoryMoviesBluRayRip         = 14
	CategoryMoviesDVDR              = 12
	CategoryMoviesBluRay            = 13
	CategoryMovies4k                = 47
	CategoryMoviesBoxsets           = 15
	CategoryMoviesDocumentaries     = 29

	CategoryTVEpisodes   = 26
	CategoryTVEpisodesHD = 32
	CategoryTVBoxsets    = 27

	CategoryGamesPC             = 17
	CategoryGamesMac            = 42
	CategoryGamesXbox           = 18
	CategoryGamesXbox360        = 19
	CategoryGamesXboxOne        = 40
	CategoryGamesPS2            = 20
	CategoryGamesPS3            = 21
	CategoryGamesPS4            = 39
	CategoryGamesPS5            = 49
	CategoryGamesPSP            = 22
	CategoryGamesWii            = 28
	CategoryGamesNintendoDS     = 30
	CategoryGamesNintendoSwitch = 48

	CategoryAppsPCISO  = 23
	CategoryAppsMac    = 24
	CategoryAppsMobile = 25
	CategoryApps0Day   = 33

	CategoryEducation = 38

	CategoryAnimationAnime    = 34
	CategoryAnimationCartoons = 35

	CategoryBooksEbooks = 45
	CategoryBooksComics = 46

	CategoryMusicAudio  = 31
	CategoryMusicVideos = 16

	CategoryForeignMovies   = 36
	CategoryForeignTVSeries = 44
)

Categories.

Variables

This section is empty.

Functions

func BuildJar added in v0.1.7

func BuildJar(sessID, uid, pass string) (http.CookieJar, error)

BuildJar creates a jar.

Types

type Client

type Client struct {
	Jar       http.CookieJar
	Transport http.RoundTripper
	// contains filtered or unexported fields
}

Client is a TL client.

func New

func New(opts ...Option) *Client

New creates a TL client.

func (*Client) Do

func (cl *Client) Do(ctx context.Context, req *http.Request, result interface{}) error

Do executes a request.

func (*Client) Search

func (cl *Client) Search(ctx context.Context, query ...string) (*SearchResponse, error)

Search searches for a query.

func (*Client) Torrent

func (cl *Client) Torrent(ctx context.Context, id int) ([]byte, error)

Torrent retrieves a torrent for the id.

type Facet

type Facet struct {
	Items map[string]Item `json:"items,omitempty"`
	Name  string          `json:"name,omitempty"`
	Title string          `json:"title,omitempty"`
	Type  string          `json:"type,omitempty"`
}

Facet is a facet.

type FacetID added in v0.2.0

type FacetID struct {
	Items map[string]int `json:"items,omitempty"`
	Name  string         `json:"name,omitempty"`
	Title string         `json:"title,omitempty"`
	Type  string         `json:"type,omitempty"`
}

FacetID is a facet id.

type Item

type Item struct {
	Label string `json:"label,omitempty"`
	Count int    `json:"count,omitempty"`
}

Item is search facet item.

type Option

type Option func(cl *Client)

Option is a TL client option.

func WithCreds added in v0.1.7

func WithCreds(sessID, uid, pass string) Option

WithCreds is a TL client option to set the PHPSESSID, tluid, and tlpass cookies used by the TL client.

func WithJar

func WithJar(jar http.CookieJar) Option

WithJar is an option to set the cookie jar used by the TL client.

func WithTransport

func WithTransport(transport http.RoundTripper) Option

WithTransport is a TL client option to set the http transport used by the TL client.

type SearchRequest

type SearchRequest struct {
	Categories []int
	Facets     map[string]string
	Query      []string
	Added      string
	OrderBy    string
	Order      string
	Page       int
	// contains filtered or unexported fields
}

SearchRequest is a search request.

func Search(query ...string) *SearchRequest

Search creates a search request.

func (*SearchRequest) All added in v0.2.1

func (req *SearchRequest) All(ctx context.Context, cl *Client) ([]Torrent, error)

All returns all results for the search request.

func (*SearchRequest) Cur added in v0.2.0

func (req *SearchRequest) Cur() Torrent

Cur returns the search response cursor's current torrent. Returns the same value until Next is called. Panics if called prior to Next.

See Next for an overview of using this method.

func (*SearchRequest) Do

func (req *SearchRequest) Do(ctx context.Context, cl *Client) (*SearchResponse, error)

Do executes the request against the client.

func (*SearchRequest) Err added in v0.2.0

func (req *SearchRequest) Err() error

Err returns the last error in the search response.

See Next for an overview of using this method.

func (*SearchRequest) Next added in v0.2.0

func (req *SearchRequest) Next(ctx context.Context, cl *Client) bool

Next returns true if there are search results available for the request.

Example:

req := tlapi.Search()
for req.Next(ctx, cl) {
	torrent := req.NextTorrent()
	/* ... */
}
if err := req.Err(); err != nil {
	/* ... */
}

func (SearchRequest) WithAdded added in v0.1.5

func (req SearchRequest) WithAdded(added string) *SearchRequest

WithAdded sets the search added filter.

func (SearchRequest) WithCategories

func (req SearchRequest) WithCategories(categories ...int) *SearchRequest

WithCategories adds search category filters.

func (SearchRequest) WithFacet added in v0.1.6

func (req SearchRequest) WithFacet(name string, values ...string) *SearchRequest

WithFacet adds a single search facet name filter, joining values with a ','.

func (SearchRequest) WithFacets

func (req SearchRequest) WithFacets(facets ...string) *SearchRequest

WithFacets adds search facet filters as string pairs (name, value...).

func (SearchRequest) WithNextDelay added in v0.2.0

func (req SearchRequest) WithNextDelay(d time.Duration) *SearchRequest

WithNextDelay sets the next delay, for use if user class is rate limited.

func (SearchRequest) WithOrder added in v0.1.5

func (req SearchRequest) WithOrder(order string) *SearchRequest

WithOrder sets the search order parameter (see Order constants).

func (SearchRequest) WithOrderBy added in v0.1.5

func (req SearchRequest) WithOrderBy(orderBy string) *SearchRequest

WithOrderBy sets the search orderBy parameter (see OrderBy constants).

func (SearchRequest) WithPage added in v0.1.2

func (req SearchRequest) WithPage(page int) *SearchRequest

WithPage sets the search page filter.

type SearchResponse

type SearchResponse struct {
	Facets struct {
		CategoryID FacetID `json:"categoryID,omitempty"`
		Added      Facet   `json:"added,omitempty"`
		Name       Facet   `json:"name,omitempty"`
		Seeders    Facet   `json:"seeders,omitempty"`
		Size       Facet   `json:"size,omitempty"`
		Tags       Tags    `json:"tags,omitempty"`
	} `json:"facets,omitempty"`
	Facetswoc      map[string]Tags `json:"facetswoc,omitempty"`
	LastBrowseTime Time            `json:"lastBrowseTime,omitempty"`
	NumFound       int             `json:"numFound,omitempty"`
	OrderBy        string          `json:"orderBy,omitempty"`
	Order          string          `json:"order,omitempty"`
	Page           int             `json:"page,omitempty"`
	PerPage        int             `json:"perPage,omitempty"`
	TorrentList    []Torrent       `json:"torrentList,omitempty"`
	UserTimeZone   string          `json:"userTimeZone,omitempty"`
}

SearchResponse is a search response.

type Tags

type Tags struct {
	Items map[string]int `json:"items,omitempty"`
	Name  string         `json:"name,omitempty"`
	Title string         `json:"title,omitempty"`
	Type  string         `json:"type,omitempty"`
}

Tags are tags.

type Time

type Time struct {
	time.Time
}

Time is a time value.

func (Time) String

func (t Time) String() string

String satisfies the fmt.Stringer interface.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(buf []byte) error

UnmarshalJSON satisfies the json.Unmarshaler interface.

type Torrent

type Torrent struct {
	AddedTimestamp     time.Time `json:"addedTimestamp,omitempty"`
	CategoryID         int       `json:"categoryID,omitempty"`
	Completed          int       `json:"completed,omitempty"`
	DownloadMultiplier int       `json:"download_multiplier,omitempty"`
	ID                 int       `json:"id,omitempty"`
	Filename           string    `json:"filename,omitempty"`
	Genres             []string  `json:"genres,omitempty"`
	IgdbID             string    `json:"igdbID,omitempty"`
	ImdbID             string    `json:"imdbID,omitempty"`
	Leechers           int       `json:"leechers,omitempty"`
	Name               string    `json:"name,omitempty"`
	New                bool      `json:"new,omitempty"`
	NumComments        int       `json:"numComments,omitempty"`
	Rating             float64   `json:"rating,omitempty"`
	Seeders            int       `json:"seeders,omitempty"`
	Size               int64     `json:"size,omitempty"`
	Tags               []string  `json:"tags,omitempty"`
	TvmazeID           string    `json:"tvmazeID,omitempty"`
	Uploader           string    `json:"uploader,omitempty"`
}

Torrent is a torrent.

func (*Torrent) UnmarshalJSON added in v0.1.3

func (t *Torrent) UnmarshalJSON(buf []byte) error

UnmarshalJSON satisfies the json.Unmarshaler interface.

Directories

Path Synopsis
example/example.go
example/example.go

Jump to

Keyboard shortcuts

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