torbox

package
v0.0.0-...-d5ce8da Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PlanFree = iota
	PlanEssential
	PlanPro
	PlanStandard
)

Variables

View Source
var DefaultHTTPClient = request.DefaultHTTPClient
View Source
var DefaultHTTPTransport = request.DefaultHTTPTransport

Functions

func TranslateErrorCode

func TranslateErrorCode(errorCode ErrorCode) core.ErrorCode

func UpstreamErrorWithCause

func UpstreamErrorWithCause(cause error) *core.UpstreamError

Types

type APIClient

type APIClient struct {
	BaseURL    *url.URL
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

func NewAPIClient

func NewAPIClient(conf *APIClientConfig) *APIClient

func (APIClient) CheckTorrentsCached

func (APIClient) ControlTorrent

func (c APIClient) ControlTorrent(params *ControlTorrentParams) (APIResponse[ControlTorrentData], error)

func (APIClient) CreateTorrent

func (c APIClient) CreateTorrent(params *CreateTorrentParams) (APIResponse[CreateTorrentData], error)

Possible Detail values:

  • Found Cached Torrent. Using Cached Torrent.

func (APIClient) GetTorrent

func (c APIClient) GetTorrent(params *GetTorrentParams) (APIResponse[GetTorrentData], error)

func (APIClient) GetTorrentInfo

func (c APIClient) GetTorrentInfo(params *GetTorrentInfoParams) (APIResponse[GetTorrentInfoData], error)

func (APIClient) GetUser

func (c APIClient) GetUser(params *GetUserParams) (APIResponse[GetUserData], error)

func (APIClient) ListTorrents

func (c APIClient) ListTorrents(params *ListTorrentsParams) (APIResponse[ListTorrentsData], error)

func (APIClient) Request

func (c APIClient) Request(method, path string, params request.Context, v ResponseEnvelop) (*http.Response, error)

type APIClientConfig

type APIClientConfig struct {
	BaseURL    string // default: https://api.torbox.app
	APIKey     string
	HTTPClient *http.Client
	UserAgent  string
}

type APIResponse

type APIResponse[T any] struct {
	Header     http.Header
	StatusCode int
	Data       T
	Detail     string
}

type CheckTorrentsCachedData

type CheckTorrentsCachedData []CheckTorrentsCachedDataItem

type CheckTorrentsCachedDataItem

type CheckTorrentsCachedDataItem struct {
	Name  string                            `json:"name"`
	Size  int                               `json:"size"`
	Hash  string                            `json:"hash"`
	Files []CheckTorrentsCachedDataItemFile `json:"files"`
}

type CheckTorrentsCachedDataItemFile

type CheckTorrentsCachedDataItemFile struct {
	Name string `json:"name"`
	Size int    `json:"size"`
}

type CheckTorrentsCachedParams

type CheckTorrentsCachedParams struct {
	Ctx
	Hashes    []string
	ListFiles bool
}

type ControlTorrentData

type ControlTorrentData struct {
}

type ControlTorrentOperation

type ControlTorrentOperation string
const (
	ControlTorrentOperationReannounce ControlTorrentOperation = "reannounce"
	ControlTorrentOperationDelete     ControlTorrentOperation = "delete"
	ControlTorrentOperationResume     ControlTorrentOperation = "resume"
	ControlTorrentOperationPause      ControlTorrentOperation = "pause"
)

type ControlTorrentParams

type ControlTorrentParams struct {
	Ctx
	TorrentId int                     `json:"torrent_id"`
	Operation ControlTorrentOperation `json:"operation"`
	All       bool                    `json:"all"`
}

type CreateTorrentData

type CreateTorrentData struct {
	TorrentId int    `json:"torrent_id"`
	Name      string `json:"name"`
	Hash      string `json:"hash"`
	AuthId    string `json:"auth_id"`
}

type CreateTorrentParams

type CreateTorrentParams struct {
	Ctx
	Magnet   string
	Seed     int
	AllowZip bool
	Name     string
}

type CreateTorrentParamsSeed

type CreateTorrentParamsSeed int
const (
	CreateTorrentParamsSeedAuto CreateTorrentParamsSeed = 1
	CreateTorrentParamsSeedYes  CreateTorrentParamsSeed = 2
	CreateTorrentParamsSeedNo   CreateTorrentParamsSeed = 3
)

type Ctx

type Ctx = request.Ctx

type ErrorCode

type ErrorCode string
const (
	ErrorCodeDatabaseError           ErrorCode = "DATABASE_ERROR"
	ErrorCodeUnknownError            ErrorCode = "UNKNOWN_ERROR"
	ErrorCodeNoAuth                  ErrorCode = "NO_AUTH"
	ErrorCodeBadToken                ErrorCode = "BAD_TOKEN"
	ErrorCodeAuthError               ErrorCode = "AUTH_ERROR"
	ErrorCodeInvalidOption           ErrorCode = "INVALID_OPTION"
	ErrorCodeRedirectError           ErrorCode = "REDIRECT_ERROR"
	ErrorCodeOAuthVerificationError  ErrorCode = "OAUTH_VERIFICATION_ERROR"
	ErrorCodeEndpointNotFound        ErrorCode = "ENDPOINT_NOT_FOUND"
	ErrorCodeItemNotFound            ErrorCode = "ITEM_NOT_FOUND"
	ErrorCodePlanRestrictedFeature   ErrorCode = "PLAN_RESTRICTED_FEATURE"
	ErrorCodeDuplicateItem           ErrorCode = "DUPLICATE_ITEM"
	ErrorCodeBozoRssFeed             ErrorCode = "BOZO_RSS_FEED"
	ErrorCodeSellixError             ErrorCode = "SELLIX_ERROR"
	ErrorCodeTooMuchData             ErrorCode = "TOO_MUCH_DATA"
	ErrorCodeDownloadTooLarge        ErrorCode = "DOWNLOAD_TOO_LARGE"
	ErrorCodeMissingRequiredOption   ErrorCode = "MISSING_REQUIRED_OPTION"
	ErrorCodeTooManyOptions          ErrorCode = "TOO_MANY_OPTIONS"
	ErrorCodeBozoTorrent             ErrorCode = "BOZO_TORRENT"
	ErrorCodeNoServersAvailableError ErrorCode = "NO_SERVERS_AVAILABLE_ERROR"
	ErrorCodeMonthlyLimit            ErrorCode = "MONTHLY_LIMIT"
	ErrorCodeCooldownLimit           ErrorCode = "COOLDOWN_LIMIT"
	ErrorCodeActiveLimit             ErrorCode = "ACTIVE_LIMIT"
	ErrorCodeDownloadServerError     ErrorCode = "DOWNLOAD_SERVER_ERROR"
	ErrorCodeBozoNzb                 ErrorCode = "BOZO_NZB"
	ErrorCodeSearchError             ErrorCode = "SEARCH_ERROR"
	ErrorCodeInvalidDevice           ErrorCode = "INVALID_DEVICE"
	ErrorCodeDiffIssue               ErrorCode = "DIFF_ISSUE"
	ErrorCodeLinkOffline             ErrorCode = "LINK_OFFLINE"
	ErrorCodeVendorDisabled          ErrorCode = "VENDOR_DISABLED"
)

type GetTorrentData

type GetTorrentData = Torrent

type GetTorrentInfoData

type GetTorrentInfoData = CheckTorrentsCachedDataItem

type GetTorrentInfoParams

type GetTorrentInfoParams struct {
	Ctx
	Hash    string
	Timeout int // default: 10
}

type GetTorrentParams

type GetTorrentParams struct {
	Ctx
	Id          int
	BypassCache bool
}

type GetUserData

type GetUserData struct {
	Id               int             `json:"id"`
	CreatedAt        string          `json:"created_at"`
	UpdatedAt        string          `json:"updated_at"`
	Email            string          `json:"email"`
	Plan             Plan            `json:"plan"`
	TotalDownloaded  int             `json:"total_downloaded"`
	Customer         string          `json:"customer"`
	Server           int             `json:"server"`
	IsSubscribed     bool            `json:"is_subscribed"`
	PremiumExpiresAt string          `json:"premium_expires_at"`
	CooldownUntil    string          `json:"cooldown_until"`
	AuthId           string          `json:"auth_id"`
	UserReferral     string          `json:"user_referral"`
	BaseEmail        string          `json:"base_email"`
	Settings         *map[string]any `json:"settings,omitempty"`
}

type GetUserParams

type GetUserParams struct {
	Ctx
	Settings bool // Allows you to retrieve user settings.
}

type ListTorrentsData

type ListTorrentsData []Torrent

type ListTorrentsParams

type ListTorrentsParams struct {
	Ctx
	BypassCache bool
	Offset      int // default: 0
	Limit       int // default: 1000
}
type LockedFileLink string

type Plan

type Plan int

type RequestDownloadLinkData

type RequestDownloadLinkData struct {
	Link string
}

type RequestDownloadLinkParams

type RequestDownloadLinkParams struct {
	Ctx
	TorrentId   int
	FileId      int
	ZipLink     bool
	TorrentFile bool
}

type Response

type Response[T any] struct {
	Success bool      `json:"success"`
	Data    T         `json:"data,omitempty"`
	Detail  string    `json:"detail"`
	Error   ErrorCode `json:"error,omitempty"`
}

func (Response[any]) GetError

func (r Response[any]) GetError() *ResponseError

func (Response[any]) IsSuccess

func (r Response[any]) IsSuccess() bool

type ResponseEnvelop

type ResponseEnvelop interface {
	IsSuccess() bool
	GetError() *ResponseError
}

type ResponseError

type ResponseError struct {
	Detail string    `json:"detail"`
	Err    ErrorCode `json:"error"`
}

func (*ResponseError) Error

func (e *ResponseError) Error() string

type ResponseStatus

type ResponseStatus string
const (
	ResponseStatusSuccess ResponseStatus = "success"
	ResponseStatusError   ResponseStatus = "error"
)

type StoreClient

type StoreClient struct {
	Name store.StoreName
	// contains filtered or unexported fields
}

func NewStoreClient

func NewStoreClient(config *StoreClientConfig) *StoreClient

func (*StoreClient) AddMagnet

func (c *StoreClient) AddMagnet(params *store.AddMagnetParams) (*store.AddMagnetData, error)

func (*StoreClient) CheckMagnet

func (c *StoreClient) CheckMagnet(params *store.CheckMagnetParams) (*store.CheckMagnetData, error)
func (c *StoreClient) GenerateLink(params *store.GenerateLinkParams) (*store.GenerateLinkData, error)

func (*StoreClient) GetMagnet

func (c *StoreClient) GetMagnet(params *store.GetMagnetParams) (*store.GetMagnetData, error)

func (*StoreClient) GetName

func (c *StoreClient) GetName() store.StoreName

func (*StoreClient) GetUser

func (c *StoreClient) GetUser(params *store.GetUserParams) (*store.User, error)

func (*StoreClient) ListMagnets

func (c *StoreClient) ListMagnets(params *store.ListMagnetsParams) (*store.ListMagnetsData, error)

func (*StoreClient) RemoveMagnet

func (c *StoreClient) RemoveMagnet(params *store.RemoveMagnetParams) (*store.RemoveMagnetData, error)

type StoreClientConfig

type StoreClientConfig struct {
	HTTPClient *http.Client
	UserAgent  string
}

type Torrent

type Torrent struct {
	Id               int                  `json:"id"`
	Hash             string               `json:"hash"`
	CreatedAt        string               `json:"created_at"`
	UpdatedAt        string               `json:"updated_at"`
	Magnet           string               `json:"magnet"`
	Size             int                  `json:"size"`
	Active           bool                 `json:"active"`
	AuthId           string               `json:"auth_id"`
	DownloadState    TorrentDownloadState `json:"download_state"`
	Seeds            int                  `json:"seeds"`
	Peers            int                  `json:"peers"`
	Ratio            float32              `json:"ratio"`
	Progress         int                  `json:"progress"`
	DownloadSpeed    int                  `json:"download_speed"`
	UploadSpeed      int                  `json:"upload_speed"`
	Name             string               `json:"name"`
	ETA              int                  `json:"eta"`
	Server           int                  `json:"server"`
	TorrentFile      bool                 `json:"torrent_file"`
	ExpiresAt        string               `json:"expires_at"`
	DownloadPresent  bool                 `json:"download_present"`
	DownloadFinished bool                 `json:"download_finished"`
	Files            []TorrentFile        `json:"files"`
	InactiveCheck    int                  `json:"inactive_check"`
	Availability     int                  `json:"availability"`
}

func (Torrent) GetAddedAt

func (t Torrent) GetAddedAt() time.Time

type TorrentDownloadState

type TorrentDownloadState string
const (
	TorrentDownloadStateDownloading        TorrentDownloadState = "downloading"        // The torrent is currently downloading
	TorrentDownloadStateUploading          TorrentDownloadState = "uploading"          // The torrent is currently seeding
	TorrentDownloadStatePaused             TorrentDownloadState = "paused"             // The torrent is paused
	TorrentDownloadStateCompleted          TorrentDownloadState = "completed"          // The torrent is completely downloaded. Do not use this for download completion status
	TorrentDownloadStateCached             TorrentDownloadState = "cached"             // The torrent is cached from the server
	TorrentDownloadStateMetaDL             TorrentDownloadState = "metaDL"             // The torrent is downloading metadata from the hoard
	TorrentDownloadStateCheckingResumeData TorrentDownloadState = "checkingResumeData" // The torrent is checking resumable data
)

type TorrentFile

type TorrentFile struct {
	Id        int    `json:"id"`
	MD5       string `json:"md5"`
	S3Path    string `json:"s3_path"`
	Name      string `json:"name"`
	Size      int    `json:"size"`
	MimeType  string `json:"mimetype"`
	ShortName string `json:"short_name"`
}

Jump to

Keyboard shortcuts

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