Documentation
¶
Index ¶
- Variables
- type Auth
- type AvailableFile
- type Client
- func (c *Client) AddMagnet(ctx context.Context, magnet string) (string, error)
- func (c *Client) DeleteTorrent(ctx context.Context, id string) error
- func (c *Client) GetDownloads(ctx context.Context) ([]Download, error)
- func (c *Client) GetInstantAvailability(ctx context.Context, hashes ...string) (map[string]InstantAvailability, error)
- func (c *Client) GetStreamTranscodings(ctx context.Context, id string) (Transcodings, error)
- func (c *Client) GetTorrentInfo(ctx context.Context, id string) (TorrentInfo, error)
- func (c *Client) GetTorrentsInfo(ctx context.Context, activeFirst bool) ([]TorrentsInfo, 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 TorrentsInfo
- type Transcodings
- 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 ¶
This section is empty.
Types ¶
type Auth ¶
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 ¶
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) DeleteTorrent ¶
DeleteTorrent deletes a torrent from the user's torrents.
func (*Client) GetDownloads ¶
GetDownloads fetches and returns the user's downloads list this is flawed because it only fetches the first 50 responses
func (*Client) GetInstantAvailability ¶
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) GetStreamTranscodings ¶
GetStreamTranscodings fetches and returns transcodings (M3U8, Dash, etc.) for a file added to RD The ID must be the one returned from RealDebrid through /downloads or /unrestrict/link
func (*Client) GetTorrentInfo ¶
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) GetTorrentsInfo ¶
GetTorrentsInfo fetches and returns info about up to 100 torrents that were added to RealDebrid for a specific user. ActiveFirst leads to active torrents being the first in the returned list.
func (*Client) SelectFiles ¶
SelectFiles starts downloading the selected files from a torrent that was previously added to RealDebrid for the specific user.
func (*Client) Unrestrict ¶
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 ¶
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 ¶
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.
func SelectLargestFile ¶
func SelectLargestFile(info TorrentInfo) (File, error)
SelectLargestFile returns the file ID of the largest file in the torrent.
type InstantAvailability ¶
type InstantAvailability map[int]AvailableFile
InstantAvailability maps torrent file IDs to their availability.
type LegacyClient ¶
type LegacyClient struct {
// contains filtered or unexported fields
}
func NewLegacyClient ¶
func NewLegacyClient(opts LegacyClientOptions, tokenCache, availabilityCache debrid.Cache, logger *zap.Logger) (*LegacyClient, error)
func (*LegacyClient) CheckInstantAvailability ¶
func (*LegacyClient) GetStreamURL ¶
type LegacyClientOptions ¶
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 ¶
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 specific 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. It's similar to TorrentsInfo, but has some additional fields like OriginalFilename, OriginalBytes and Files.
type TorrentsInfo ¶
type TorrentsInfo struct { ID string `json:"id,omitempty"` Filename string `json:"filename,omitempty"` // SHA1 Hash of the torrent Hash string `json:"hash,omitempty"` // Size of selected files only Bytes int `json:"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"` // 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"` }
TorrentsInfo contains info about one element of a list of torrents 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. It's similar to TorrentInfo, but lacks some fields like OriginalFilename, OriginalBytes and Files.
type Transcodings ¶
type Transcodings struct { Apple struct { Full string `json:"full"` } `json:"apple"` Dash struct { Full string `json:"full"` } `json:"dash"` LiveMP4 struct { Full string `json:"full"` } `json:"liveMP4"` H264WebM struct { Full string `json:"full"` } `json:"h264WebM"` }
Transcoding represents the transcodings for a given stream
type User ¶
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.