alldebrid

package
v0.0.0-...-b762e23 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Bad request.
	// Corresponds to AllDebrid 400 status code.
	ErrorBadRequest = errors.New("bad request")
	// Authentication error.
	// Corresponds to AllDebrid 401 status code.
	ErrorUnauthorized = errors.New("unauthorized")
	// Too many requests hit the API too quickly, see https://docs.alldebrid.com/#rate-limiting.
	// Corresponds to AllDebrid 429 status code.
	ErrorTooManyRequests = errors.New("too many requests")
	// Something went wrong on Alldebrid's end.
	// Corresponds to AllDebrid 500, 502, 503 and 504 status codes.
	ErrorServerError = errors.New("server error")
)
View Source
var DefaultClientOpts = ClientOptions{
	BaseURL: "https://api.alldebrid.com/v4",
	Timeout: 5 * time.Second,
}

DefaultClientOpts are ClientOptions with reasonable default values.

View Source
var DefaultLegacyClientOpts = LegacyClientOptions{
	BaseURL:  "https://api.alldebrid.com",
	Timeout:  5 * time.Second,
	CacheAge: 24 * time.Hour,
}

Functions

This section is empty.

Types

type Client

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

Client represents a AllDebrid client.

func NewClient

func NewClient(opts ClientOptions, apiKey string, logger *zap.Logger) *Client

NewClient returns a new AllDebrid client. The logger param can be nil.

func (*Client) DeleteMagnet

func (c *Client) DeleteMagnet(ctx context.Context, id int) error

DeleteMagnet deletes a magnet from the user's magnets. The ID must be the one returned from AllDebrid when adding the magnet or getting status info about it.

func (*Client) GetInstantAvailability

func (c *Client) GetInstantAvailability(ctx context.Context, hashes ...string) (map[string]struct{}, error)

GetInstantAvailability fetches and returns info about the instant availability of a torrent. The hashes can actually also be magnet URLs. The returned map contains the hashes / magnet URLs of the torrents that are instantly available.

func (*Client) GetStatus

func (c *Client) GetStatus(ctx context.Context) ([]Status, error)

GetStatus fetches and returns the status of all torrents that were added to AllDebrid for a specific user. The ID must be the one returned from AllDebrid when adding the torrent to AllDebrid.

func (*Client) GetStatusByID

func (c *Client) GetStatusByID(ctx context.Context, id int) (Status, error)

GetStatusByID fetches and returns the status of a specific torrent that was added to AllDebrid for a specific user. The ID must be the one returned from AllDebrid when adding the torrent to AllDebrid.

func (*Client) GetUser

func (c *Client) GetUser(ctx context.Context) (User, error)

GetUser fetches and returns the user object from AllDebrid.

func (*Client) Unlock

func (c *Client) Unlock(ctx context.Context, link string) (Download, error)

Unlock unlocks a link. For torrents, the torrent must first be added to AllDebrid, which then leads to such a hoster link (either instantly or after it was downloaded by AllDebrid).

func (*Client) UploadMagnet

func (c *Client) UploadMagnet(ctx context.Context, magnet string) (Magnet, error)

UploadMagnet adds a torrent to AllDebrid via magnet URL. The magnet string can actually also be a hash.

type ClientOptions

type ClientOptions struct {
	// Base URL for HTTP requests. This will also be used when making a request to a link that's read from a AllDebrid response by replacing its base URL.
	BaseURL string
	// Timeout for HTTP requests
	Timeout time.Duration
	// Extra headers to set for HTTP requests
	ExtraHeaders map[string]string
}

ClientOptions are options for the client.

type Download

type Download struct {
	// Requested link, simplified if it was not in canonical form
	Link string `json:"link,omitempty"`
	// Link's file filename
	Filename string `json:"filename,omitempty"`
	// Link host minified
	Host string `json:"host,omitempty"`
	// List of alternative links with other resolutions for some video links
	Streams []Stream `json:"streams,omitempty"`
	// Unused
	Paws bool `json:"paws,omitempty"`
	// Filesize of the link's file
	Filesize int `json:"filesize,omitempty"`
	// Generation ID
	ID string `json:"id,omitempty"`
	// Matched host main domain
	HostDomain string `json:"hostDomain,omitempty"`
	// Delayed ID if link need time to generate
	Delayed int `json:"delayed,omitempty"`
}

Download represents an unlocked link.

type LegacyClient

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

func NewLegacyClient

func NewLegacyClient(opts LegacyClientOptions, apiKeyCache, availabilityCache debrid.Cache, logger *zap.Logger) (*LegacyClient, error)

func (*LegacyClient) CheckInstantAvailability

func (c *LegacyClient) CheckInstantAvailability(ctx context.Context, apiKey string, infoHashes ...string) []string

func (*LegacyClient) GetStreamURL

func (c *LegacyClient) GetStreamURL(ctx context.Context, magnetURL, apiKey string) (string, error)

func (*LegacyClient) TestAPIkey

func (c *LegacyClient) TestAPIkey(ctx context.Context, apiKey string) error

type LegacyClientOptions

type LegacyClientOptions struct {
	BaseURL      string
	Timeout      time.Duration
	CacheAge     time.Duration
	ExtraHeaders []string
}
type Link struct {
	// Download link
	Link string `json:"link,omitempty"`
	// File name
	Filename string `json:"filename,omitempty"`
	// File size
	Size int `json:"size,omitempty"`
	// different format depending of version property
	Files []interface{} `json:"files,omitempty"`
}

Link represents a file in a torrent.

func SelectLargestFile

func SelectLargestFile(status Status) (Link, error)

SelectLargestFile returns the link of the largest file in the torrent.

type Magnet

type Magnet struct {
	// Magnet sent
	Magnet string `json:"magnet,omitempty"`
	// Magnet filename, or 'noname' if could not parse it
	Name string `json:"name,omitempty"`
	// Magnet id, used to query status
	ID int `json:"id,omitempty"`
	// Magnet hash
	Hash string `json:"hash,omitempty"`
	// Magnet files size
	Size int `json:"size,omitempty"`
	// Whether the magnet is already available
	Ready bool `json:"ready,omitempty"`
}

Magnet represents a magnet that was added to AllDebrid.

type Status

type Status struct {
	// Magnet id
	ID int `json:"id,omitempty"`
	// Magnet filename
	Filename string `json:"filename,omitempty"`
	// Magnet filesize
	Size int `json:"size,omitempty"`
	// Status in plain English
	Status string `json:"status,omitempty"`
	// Status code
	StatusCode StatusCode `json:"statusCode,omitempty"`
	// Downloaded data so far
	Downloaded int `json:"downloaded,omitempty"`
	// Uploaded data so far
	Uploaded int `json:"uploaded,omitempty"`
	// Seeders count
	Seeders int `json:"seeders,omitempty"`
	// Download speed
	DownloadSpeed int `json:"downloadSpeed,omitempty"`
	// Upload speed
	UploadSpeed int `json:"uploadSpeed,omitempty"`
	// Timestamp of the date of the magnet upload
	UploadDate int `json:"uploadDate,omitempty"`
	// Timestamp of the date of the magnet completion
	CompletionDate int `json:"completionDate,omitempty"`
	// an array of link objects
	Links []Link `json:"links,omitempty"`
	// files array format
	Version int `json:"version,omitempty"`
}

Status contains status info about a torrent that was previously uploaded to AllDebrid for a specific user.

type StatusCode

type StatusCode int

StatusCode indicates in which status an added torrent is.

const (
	StatusCode_InQueue StatusCode = iota
	StatusCode_Downloading
	StatusCode_CompressingMoving
	StatusCode_Uploading
	StatusCode_Ready
	StatusCode_UploadFail
	StatusCode_InternalErrorOnUnpacking
	StatusCode_NotDownloadedIn20Min
	StatusCode_FileTooBig
	StatusCode_InternalError
	StatusCode_DownloadTookMoreThan72h
	StatusCode_DeletedOnTheHosterWebsite
)

type Stream

type Stream struct {
	// Resolution, e.g. `480` if the resolution is 480p.
	Quality int `json:"quality,omitempty"`
	// E.g. "mp4"
	Ext string `json:"ext,omitempty"`
	// File size in bytes
	Filesize int    `json:"filesize,omitempty"`
	Name     string `json:"name,omitempty"`
	// Streamable direct link to the file
	Link string `json:"link,omitempty"`
	ID   string `json:"id,omitempty"`
}

Stream is an alternative stream with a different resolution than the original one.

type User

type User struct {
	// User username
	Username string `json:"username"`
	// User email
	Email string `json:"email"`
	// true is premium, false if not
	IsPremium bool `json:"isPremium"`
	// true is user has active subscription, false if not
	IsSubscribed bool `json:"isSubscribed"`
	// true is account is in freedays trial, false if not
	IsTrial bool `json:"isTrial"`
	// 0 if user is not premium, or timestamp until user is premium
	PremiumUntil int `json:"premiumUntil"`
	// Language used by the user on Alldebrid, eg. 'en', 'fr'. Default to fr
	Lang string `json:"lang"`
	// Preferer TLD used by the user, eg. 'fr', 'es'. Default to fr
	PreferredDomain string `json:"preferedDomain"`
	// Number of fidelity points
	FidelityPoints int `json:"fidelityPoints"`
	// Remaining quotas for the limited hosts (in MB)
	LimitedHostersQuotas map[string]int `json:"limitedHostersQuotas"`
	// When in trial mode, remaining global traffic quota available (in MB)
	RemainingTrialQuota int `json:"remainingTrialQuota,omitempty"`
}

User represents an AllDebrid user.

Jump to

Keyboard shortcuts

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