Documentation ¶
Index ¶
- Variables
- func SelectLargestFile(info TorrentInfo) (int, error)
- type Auth
- type AvailableFile
- type Client
- func (c *Client) AddMagnet(ctx context.Context, magnet string) (string, error)
- func (c *Client) GetInstantAvailability(ctx context.Context, hashes ...string) (map[string]InstantAvailability, error)
- func (c *Client) GetTorrentInfo(ctx context.Context, id string) (TorrentInfo, error)
- func (c *Client) GetUser(ctx context.Context) (User, error)
- func (c *Client) SelectFiles(ctx context.Context, torrentID string, fileIDs ...int) error
- func (c *Client) Unrestrict(ctx context.Context, link string, remote bool) (Download, error)
- type ClientOptions
- type Download
- type File
- type InstantAvailability
- type LegacyClient
- type LegacyClientOptions
- type TorrentInfo
- type User
Constants ¶
This section is empty.
Variables ¶
var ( // Bad request. // Corresponds to RealDebrid 400 status code. ErrorBadRequest = errors.New("bad request") // Expired, invalid. // Corresponds to RealDebrid 401 status code. ErrorBadToken = errors.New("bad token") // Account locked, not premium. // Corresponds to RealDebrid 403 status code. ErrorPermissionDenied = errors.New("permission denied") // Wrong parameter (invalid file id(s)) / Unknown ressource (invalid id) // Corresponds to RealDebrid 404 status code. ErrorInvalidID = errors.New("invalid ID") // Corresponds to RealDebrid 503 status code. ErrorServiceUnavailable = errors.New("service unavailable") )
var DefaultClientOpts = ClientOptions{ BaseURL: "https://api.real-debrid.com/rest/1.0", Timeout: 5 * time.Second, }
DefaultClientOpts are ClientOptions with reasonable default values.
var DefaultLegacyClientOpts = LegacyClientOptions{ BaseURL: "https://api.real-debrid.com", Timeout: 5 * time.Second, CacheAge: 24 * time.Hour, }
Functions ¶
func SelectLargestFile ¶ added in v0.2.0
func SelectLargestFile(info TorrentInfo) (int, error)
SelectLargestFile returns the file ID of the largest file in the torrent.
Types ¶
type Auth ¶ added in v0.2.0
type Auth struct { // Long lasting API key or expiring OAuth2 access token KeyOrToken string // The user's original IP. Only required if ClientOptions.ForwardOriginIP is true. IP string }
Auth carries authentication/authorization info for RealDebrid.
type AvailableFile ¶ added in v0.2.0
type AvailableFile struct { Filename string `json:"filename,omitempty"` Filesize int `json:"filesize,omitempty"` }
AvailableFile represents an instantly available file.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a RealDebrid client.
func NewClient ¶
func NewClient(opts ClientOptions, auth Auth, logger *zap.Logger) *Client
NewClient returns a new RealDebrid client. The logger param can be nil.
func (*Client) GetInstantAvailability ¶ added in v0.2.0
func (c *Client) GetInstantAvailability(ctx context.Context, hashes ...string) (map[string]InstantAvailability, error)
GetInstantAvailability fetches and returns info about the instant availability of a torrent.
func (*Client) GetTorrentInfo ¶ added in v0.2.0
GetTorrentInfo fetches and returns info about a torrent that was added to RealDebrid for a specific user. The ID must be the one returned from RealDebrid when adding the torrent to RealDebrid.
func (*Client) GetUser ¶ added in v0.2.0
GetUser fetches and returns the user object from RealDebrid.
func (*Client) SelectFiles ¶ added in v0.2.0
SelectFiles starts downloading the selected files from a torrent that was previously added to RealDebrid for the specific user.
func (*Client) Unrestrict ¶ added in v0.2.0
Unrestrict unrestricts a hoster link. For torrents, the torrent must first be added to RealDebrid and a file selected for download, which then leads to such a hoster link. When remote is true, account sharing restrictions are lifted, but it requires separately purchased "sharing traffic".
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 RealDebrid 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 // When setting this to true, the user's original IP address is read from Auth.IP and forwarded to RealDebrid for all POST requests. // Only required if the library is used in an app on a machine // whose outgoing IP is different from the machine that's going to request the cached file/stream URL. ForwardOriginIP bool }
ClientOptions are options for the client.
type Download ¶ added in v0.2.0
type Download struct { ID string `json:"id,omitempty"` Filename string `json:"filename,omitempty"` // Mime Type of the file, guessed by the file extension MimeType string `json:"mimeType,omitempty"` // Filesize in bytes, 0 if unknown Filesize int `json:"filesize,omitempty"` // Original link Link string `json:"link,omitempty"` // Host main domain Host string `json:"host,omitempty"` // Max Chunks allowed Chunks int `json:"chunks,omitempty"` // Disable / enable CRC check CRC int `json:"crc,omitempty"` // Generated link Download string `json:"download,omitempty"` // Is the file streamable on website Streamable int `json:"streamable,omitempty"` }
Download represents an unrestricted link.
type File ¶ added in v0.2.0
type File struct { ID int `json:"id,omitempty"` // Path to the file inside the torrent, starting with "/" Path string `json:"path,omitempty"` Bytes int `json:"bytes,omitempty"` // 0 or 1 Selected int `json:"selected,omitempty"` }
File represents a file in a torrent.
type InstantAvailability ¶ added in v0.2.0
type InstantAvailability map[int]AvailableFile
InstantAvailability maps torrent file IDs to their availability.
type LegacyClient ¶ added in v0.2.0
type LegacyClient struct {
// contains filtered or unexported fields
}
func NewLegacyClient ¶ added in v0.2.0
func NewLegacyClient(opts LegacyClientOptions, tokenCache, availabilityCache debrid.Cache, logger *zap.Logger) (*LegacyClient, error)
func (*LegacyClient) CheckInstantAvailability ¶ added in v0.2.0
func (*LegacyClient) GetStreamURL ¶ added in v0.2.0
type LegacyClientOptions ¶ added in v0.2.0
type LegacyClientOptions struct { BaseURL string Timeout time.Duration CacheAge time.Duration ExtraHeaders []string // When setting this to true, the user's original IP address is read from Auth.IP and forwarded to RealDebrid for all POST requests. // Only required if the library is used in an app on a machine // whose outgoing IP is different from the machine that's going to request the cached file/stream URL. ForwardOriginIP bool }
type TorrentInfo ¶ added in v0.2.0
type TorrentInfo struct { ID string `json:"id,omitempty"` Filename string `json:"filename,omitempty"` // Original name of the torrent OriginalFilename string `json:"original_filename,omitempty"` // SHA1 Hash of the torrent Hash string `json:"hash,omitempty"` // Size of selected files only Bytes int `json:"bytes,omitempty"` // Total size of the torrent OriginalBytes int `json:"original_bytes,omitempty"` // Host main domain Host string `json:"host,omitempty"` // Split size of links Split int `json:"split,omitempty"` // Possible values: 0 to 100 Progress int `json:"progress,omitempty"` // Current status of the torrent: magnet_error, magnet_conversion, waiting_files_selection, queued, downloading, downloaded, error, virus, compressing, uploading, dead Status string `json:"status,omitempty"` Added time.Time `json:"added,omitempty"` Files []File `json:"files,omitempty"` // Host URLs Links []string `json:"links,omitempty"` // !! Only present when finished, jsonDate Ended string `json:"ended,omitempty"` // !! Only present in "downloading", "compressing", "uploading" status Speed int `json:"speed,omitempty"` // !! Only present in "downloading", "magnet_conversion" status Seeders int `json:"seeders,omitempty"` }
TorrentInfo contains info about a torrent that was added to RealDebrid for a specific user. It contains download info (progress, selected files) after one or more files of the torrent were selected to be downloaded.
type User ¶ added in v0.2.0
type User struct { ID int `json:"id,omitempty"` Username string `json:"username,omitempty"` Email string `json:"email,omitempty"` // Fidelity points Points int `json:"points,omitempty"` // User language Locale string `json:"locale,omitempty"` Avatar string `json:"avatar,omitempty"` // "premium" or "free" Type string `json:"type,omitempty"` // seconds left as a Premium user Premium int `json:"premium,omitempty"` Expiration time.Time `json:"expiration,omitempty"` }
User represents a RealDebrid user.