Documentation ¶
Overview ¶
Package putio is the Put.io API v2 client for Go.
The go-putio package does not directly handle authentication. Instead, when creating a new client, pass an http.Client that can handle authentication for you. The easiest and recommended way to do this is using the golang.org/x/oauth2 library, but you can always use any other library that provides an http.Client. If you have an OAuth2 access token (for example, a personal API token), you can use it with the oauth2 library using:
package main import ( "context" "golang.org/x/oauth2" "github.com/igungor/go-putio/putio" ) func main() { ctx := context.Background() tokenSource := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: "<YOUR-TOKEN-HERE>"}, ) oauthClient := oauth2.NewClient(ctx, tokenSource) client := putio.NewClient(oauthClient) // get root directory root, err := client.Files.Get(ctx, 0) }
Note that when using an authenticated Client, all calls made by the client will include the specified OAuth token. Therefore, authenticated clients should almost never be shared between different users.
Index ¶
- Constants
- type AccountInfo
- type AccountService
- type Client
- type Error
- type ErrorResponse
- type Event
- type EventsService
- type File
- type FilesService
- func (f *FilesService) Convert(ctx context.Context, id int64) error
- func (f *FilesService) CreateFolder(ctx context.Context, name string, parent int64) (File, error)
- func (f *FilesService) Delete(ctx context.Context, files ...int64) error
- func (f *FilesService) DeleteVideoPosition(ctx context.Context, id int64) error
- func (f *FilesService) Download(ctx context.Context, id int64, useTunnel bool, headers http.Header) (io.ReadCloser, error)
- func (f *FilesService) DownloadSubtitle(ctx context.Context, id int64, key string, format string) (io.ReadCloser, error)
- func (f *FilesService) Get(ctx context.Context, id int64) (File, error)
- func (f *FilesService) HLSPlaylist(ctx context.Context, id int64, subtitleKey string) (io.ReadCloser, error)
- func (f *FilesService) List(ctx context.Context, id int64) ([]File, File, error)
- func (f *FilesService) Move(ctx context.Context, parent int64, files ...int64) error
- func (f *FilesService) Rename(ctx context.Context, id int64, newname string) error
- func (f *FilesService) Search(ctx context.Context, query string, page int64) (Search, error)
- func (f *FilesService) SetVideoPosition(ctx context.Context, id int64, t int) error
- func (f *FilesService) Subtitles(ctx context.Context, id int64) ([]Subtitle, error)
- func (f *FilesService) Upload(ctx context.Context, r io.Reader, filename string, parent int64) (Upload, error)
- type Friend
- type FriendsService
- func (f *FriendsService) Approve(ctx context.Context, username string) error
- func (f *FriendsService) Deny(ctx context.Context, username string) error
- func (f *FriendsService) List(ctx context.Context) ([]Friend, error)
- func (f *FriendsService) Request(ctx context.Context, username string) error
- func (f *FriendsService) Unfriend(ctx context.Context, username string) error
- func (f *FriendsService) WaitingRequests(ctx context.Context) ([]Friend, error)
- type Search
- type Settings
- type Subtitle
- type Time
- type Transfer
- type TransfersService
- func (t *TransfersService) Add(ctx context.Context, urlStr string, parent int64, callbackURL string) (Transfer, error)
- func (t *TransfersService) Cancel(ctx context.Context, ids ...int64) error
- func (t *TransfersService) Clean(ctx context.Context) error
- func (t *TransfersService) Get(ctx context.Context, id int64) (Transfer, error)
- func (t *TransfersService) List(ctx context.Context) ([]Transfer, error)
- func (t *TransfersService) Retry(ctx context.Context, id int64) (Transfer, error)
- type Upload
- type Zip
- type ZipsService
Constants ¶
const ( ErrResourceNotFound = Error("resource does not exist") ErrPaymentRequired = Error("payment required") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountInfo ¶
type AccountInfo struct { AccountActive bool `json:"account_active"` AvatarURL string `json:"avatar_url"` DaysUntilFilesDeletion int `json:"days_until_files_deletion"` DefaultSubtitleLanguage string `json:"default_subtitle_language"` Disk struct { Avail int64 `json:"avail"` Size int64 `json:"size"` Used int64 `json:"used"` } `json:"disk"` HasVoucher bool `json:"has_voucher"` Mail string `json:"mail"` PlanExpirationDate string `json:"plan_expiration_date"` Settings Settings `json:"settings"` SimultaneousDownloadLimit int `json:"simultaneous_download_limit"` SubtitleLanguages []string `json:"subtitle_languages"` UserID int64 `json:"user_id"` Username string `json:"username"` }
AccountInfo represents user's account information.
type AccountService ¶
type AccountService struct {
// contains filtered or unexported fields
}
AccountService is the service to gather information about user account.
func (*AccountService) Info ¶
func (a *AccountService) Info(ctx context.Context) (AccountInfo, error)
Info retrieves user account information.
type Client ¶
type Client struct { // Base URL for API requests BaseURL *url.URL // User agent for client UserAgent string // Services used for communicating with the API Account *AccountService Files *FilesService Transfers *TransfersService Zips *ZipsService Friends *FriendsService Events *EventsService // contains filtered or unexported fields }
Client manages communication with Put.io v2 API.
func NewClient ¶
NewClient returns a new Put.io API client, using the htttpClient, which must be a new Oauth2 enabled http.Client. If httpClient is not defined, default HTTP client is used.
func (*Client) Do ¶
Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. Response body is closed at all cases except v is nil. If v is nil, response body is not closed and the body can be used for streaming.
type ErrorResponse ¶
type ErrorResponse struct { Response *http.Response `json:"-"` Message string `json:"error_message"` Type string `json:"error_type"` }
ErrorResponse reports the error caused by an API request.
func (*ErrorResponse) Error ¶
func (e *ErrorResponse) Error() string
type Event ¶
type Event struct { ID int64 `json:"id"` FileID int64 `json:"file_id"` Source string `json:"source"` Type string `json:"type"` TransferName string `json:"transfer_name"` TransferSize int64 `json:"transfer_size"` CreatedAt *Time `json:"created_at"` }
Event represents a Put.io event. It could be a transfer or a shared file.
type EventsService ¶
type EventsService struct {
// contains filtered or unexported fields
}
EventsService is the service to gather information about user's events.
type File ¶
type File struct { ID int64 `json:"id"` Name string `json:"name"` Size int64 `json:"size"` ContentType string `json:"content_type"` CreatedAt *Time `json:"created_at"` FirstAccessedAt *Time `json:"first_accessed_at"` ParentID int64 `json:"parent_id"` Screenshot string `json:"screenshot"` OpensubtitlesHash string `json:"opensubtitles_hash"` IsMP4Available bool `json:"is_mp4_available"` Icon string `json:"icon"` CRC32 string `json:"crc32"` StartFrom int `json:"start_from"` }
File represents a Put.io file.
type FilesService ¶
type FilesService struct {
// contains filtered or unexported fields
}
FilesService is a general service to gather information about user files, such as listing, searching, creating new ones, or just fetching a single file.
func (*FilesService) Convert ¶
func (f *FilesService) Convert(ctx context.Context, id int64) error
Convert starts a conversion of the given file to MP4 format, which is playable in most media players.
func (*FilesService) CreateFolder ¶
CreateFolder creates a new folder under parent.
func (*FilesService) Delete ¶
func (f *FilesService) Delete(ctx context.Context, files ...int64) error
Delete deletes given files.
func (*FilesService) DeleteVideoPosition ¶
func (f *FilesService) DeleteVideoPosition(ctx context.Context, id int64) error
DeleteVideoPosition deletes video position for a video file.
func (*FilesService) Download ¶
func (f *FilesService) Download(ctx context.Context, id int64, useTunnel bool, headers http.Header) (io.ReadCloser, error)
Download fetches the contents of the given file. Callers can pass additional useTunnel parameter to fetch the file from nearest tunnel server. Storage servers accept Range requests, so a range header can be provided by headers parameter.
Download request is done by the client which is provided to the NewClient constructor. Additional client tunings are taken into consideration while downloading a file, such as Timeout etc.
func (*FilesService) DownloadSubtitle ¶
func (f *FilesService) DownloadSubtitle(ctx context.Context, id int64, key string, format string) (io.ReadCloser, error)
DownloadSubtitle sends the contents of the subtitle file. If the key is empty string, `default` key is used. This key is used to search for a subtitle in the following order and returns the first match: - A subtitle file that has identical parent folder and name with the video. - Subtitle file extracted from video if the format is MKV. - First match from OpenSubtitles.org.
func (*FilesService) HLSPlaylist ¶
func (f *FilesService) HLSPlaylist(ctx context.Context, id int64, subtitleKey string) (io.ReadCloser, error)
HLSPlaylist serves a HLS playlist for a video file. Use “all” as subtitleKey to get available subtitles for user’s preferred languages.
func (*FilesService) Search ¶
Search makes a search request with the given query. Servers return 50 results at a time. The URL for the next 50 results are in Next field. If page is -1, all results are returned.
func (*FilesService) SetVideoPosition ¶
SetVideoPosition sets default video position for a video file.
func (*FilesService) Subtitles ¶
Subtitles lists available subtitles for the given file for user's prefered subtitle language.
func (*FilesService) Upload ¶
func (f *FilesService) Upload(ctx context.Context, r io.Reader, filename string, parent int64) (Upload, error)
Upload reads from given io.Reader and uploads the file contents to Put.io servers under directory given by parent. If parent is negative, user's prefered folder is used.
If the uploaded file is a torrent file, Put.io will interpret it as a transfer and Transfer field will be present to represent the status of the tranfer. Likewise, if the uploaded file is a regular file, Transfer field would be nil and the uploaded file will be represented by the File field.
This method reads the file contents into the memory, so it should be used for <150MB files.
type Friend ¶
type Friend struct { ID int64 `json:"id"` Name string `json:"name"` AvatarURL string `json:"avatar_url"` }
Friend represents Put.io user's friend.
type FriendsService ¶
type FriendsService struct {
// contains filtered or unexported fields
}
FriendsService is the service to operate on user friends.
func (*FriendsService) Approve ¶
func (f *FriendsService) Approve(ctx context.Context, username string) error
Approve approves a friend request from the given username.
func (*FriendsService) Deny ¶
func (f *FriendsService) Deny(ctx context.Context, username string) error
Deny denies a friend request from the given username.
func (*FriendsService) List ¶
func (f *FriendsService) List(ctx context.Context) ([]Friend, error)
List lists users friends.
func (*FriendsService) Request ¶
func (f *FriendsService) Request(ctx context.Context, username string) error
Request sends a friend request to the given username.
func (*FriendsService) Unfriend ¶
func (f *FriendsService) Unfriend(ctx context.Context, username string) error
Unfriend removed friend from user's friend list.
func (*FriendsService) WaitingRequests ¶
func (f *FriendsService) WaitingRequests(ctx context.Context) ([]Friend, error)
WaitingRequests lists user's pending friend requests.
type Settings ¶
type Settings struct { CallbackURL string `json:"callback_url"` DefaultDownloadFolder int64 `json:"default_download_folder"` DefaultSubtitleLanguage string `json:"default_subtitle_language"` DownloadFolderUnset bool `json:"download_folder_unset"` IsInvisible bool `json:"is_invisible"` Nextepisode bool `json:"nextepisode"` PrivateDownloadHostIP interface{} `json:"private_download_host_ip"` PushoverToken string `json:"pushover_token"` Routing string `json:"routing"` Sorting string `json:"sorting"` SSLEnabled bool `json:"ssl_enabled"` StartFrom bool `json:"start_from"` SubtitleLanguages []string `json:"subtitle_languages"` }
Settings represents user's personal settings.
type Time ¶
Time is a wrapper around time.Time that can be unmarshalled from a JSON string formatted as "2016-04-19T15:44:42". All methods of time.Time can be called on Time.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Transfer ¶
type Transfer struct { Availability int `json:"availability"` CallbackURL string `json:"callback_url"` CreatedAt *Time `json:"created_at"` CreatedTorrent bool `json:"created_torrent"` ClientIP string `json:"client_ip"` DownloadSpeed int `json:"down_speed"` Downloaded int64 `json:"downloaded"` DownloadID int64 `json:"download_id"` ErrorMessage string `json:"error_message"` EstimatedTime int64 `json:"estimated_time"` Extract bool `json:"extract"` FileID int64 `json:"file_id"` FinishedAt *Time `json:"finished_at"` ID int64 `json:"id"` IsPrivate bool `json:"is_private"` MagnetURI string `json:"magneturi"` Name string `json:"name"` PeersConnected int `json:"peers_connected"` PeersGettingFromUs int `json:"peers_getting_from_us"` PeersSendingToUs int `json:"peers_sending_to_us"` PercentDone int `json:"percent_done"` SaveParentID int64 `json:"save_parent_id"` SecondsSeeding int `json:"seconds_seeding"` Size int `json:"size"` Source string `json:"source"` Status string `json:"status"` StatusMessage string `json:"status_message"` SubscriptionID int `json:"subscription_id"` TorrentLink string `json:"torrent_link"` TrackerMessage string `json:"tracker_message"` Trackers string `json:"tracker"` Type string `json:"type"` UploadSpeed int `json:"up_speed"` Uploaded int64 `json:"uploaded"` }
Transfer represents a Put.io transfer state.
type TransfersService ¶
type TransfersService struct {
// contains filtered or unexported fields
}
TransfersService is the service to operate on torrent transfers, such as adding a torrent or magnet link, retrying a current one etc.
func (*TransfersService) Add ¶
func (t *TransfersService) Add(ctx context.Context, urlStr string, parent int64, callbackURL string) (Transfer, error)
Add creates a new transfer. A valid torrent or a magnet URL is expected. Parent is the folder where the new transfer is downloaded to. If a negative value is given, user's preferred download folder is used. CallbackURL is used to send a POST request after the transfer is finished downloading.
func (*TransfersService) Cancel ¶
func (t *TransfersService) Cancel(ctx context.Context, ids ...int64) error
Cancel deletes given transfers.
func (*TransfersService) Clean ¶
func (t *TransfersService) Clean(ctx context.Context) error
Clean removes completed transfers from the transfer list.
type Upload ¶
Upload represents a Put.io upload. If the uploaded file is a torrent file, Transfer field will represent the status of the transfer.
type Zip ¶
type Zip struct { ID int64 `json:"id"` CreatedAt *Time `json:"created_at"` Size int64 `json:"size"` Status string `json:"status"` URL string `json:"url"` }
Zip represents Put.io zip file.
type ZipsService ¶
type ZipsService struct {
// contains filtered or unexported fields
}
ZipsService is the service manage zip streams.
func (*ZipsService) Create ¶
Create creates zip files for given file IDs. If the operation is successful, a zip ID will be returned to keep track of zip process.