Documentation
¶
Overview ¶
aria2 is a go library to communicate with the aria2 rpc interface.
aria2 is a utility for downloading files. The supported protocols are HTTP(S), FTP, SFTP, BitTorrent, and Metalink. aria2 can download a file from multiple sources/protocols and tries to utilize your maximum download bandwidth. It supports downloading a file from HTTP(S)/FTP /SFTP and BitTorrent at the same time, while the data downloaded from HTTP(S)/FTP/SFTP is uploaded to the BitTorrent swarm. Using Metalink chunk checksums, aria2 automatically validates chunks of data while downloading a file.
Index ¶
- func URIs(uris ...string) []string
- type BittorrentStatus
- type BittorrentStatusInfo
- type Client
- func (c *Client) AddUri(uris []string, options *Options) (GID, error)
- func (c *Client) ChangePosition(gid string, pos int, how PositionSetBehaviour) (int, error)
- func (c *Client) Close() error
- func (c *Client) Delete(gid string) (err error)
- func (c *Client) Download(uris []string, options *Options) (status Status, err error)
- func (c *Client) DownloadWithContext(ctx context.Context, uris []string, options *Options) (status Status, err error)
- func (c *Client) ForcePause(gid string) error
- func (c *Client) ForcePauseAll() error
- func (c *Client) ForceRemove(gid string) error
- func (c *Client) GetFiles(gid string) ([]File, error)
- func (c *Client) GetGID(gid string) GID
- func (c *Client) GetURIs(gid string) ([]URI, error)
- func (c *Client) Pause(gid string) error
- func (c *Client) PauseAll() error
- func (c *Client) Remove(gid string) error
- func (c *Client) String() string
- func (c *Client) Subscribe(name string, listener EventListener)
- func (c *Client) TellStatus(gid string, keys ...string) (Status, error)
- func (c *Client) Unpause(gid string) error
- func (c *Client) UnpauseAll() error
- func (c *Client) WaitForDownload(gid string) error
- type DownloadEvent
- type EventListener
- type ExitStatus
- type File
- type GID
- func (gid *GID) Delete() error
- func (gid *GID) ForcePause() error
- func (gid *GID) ForceRemove() error
- func (gid *GID) GetFiles() ([]File, error)
- func (gid *GID) GetURIs() ([]URI, error)
- func (gid *GID) Pause() error
- func (gid *GID) Remove() error
- func (gid *GID) String() string
- func (gid *GID) TellStatus(keys ...string) (Status, error)
- func (gid *GID) Unpause() error
- func (gid *GID) WaitForDownload() error
- type Options
- type PositionSetBehaviour
- type Status
- type StatusName
- type UNIXTime
- type URI
- type URIStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BittorrentStatus ¶
type BittorrentStatus struct { AnnounceList []URI Comment string CreationDateUNIX UNIXTime `json:",string"` Mode string Info BittorrentStatusInfo }
type BittorrentStatusInfo ¶
type BittorrentStatusInfo struct {
Name string
}
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) AddUri ¶
AddUri adds a new download. uris is a slice of HTTP/FTP/SFTP/BitTorrent URIs (strings) pointing to the same resource. If you mix URIs pointing to different resources, then the download may fail or be corrupted without aria2 complaining.
When adding BitTorrent Magnet URIs, uris must have only one element and it should be BitTorrent Magnet URI.
The new download is appended to the end of the queue. This method returns the GID of the newly registered download.
func (*Client) ChangePosition ¶
ChangePosition changes the position of the download denoted by gid in the queue. If how is SetPositionStart, it moves the download to a position relative to the beginning of the queue. If how is SetPositionRelative, it moves the download to a position relative to the current position. If how is SetPositionEnd, it moves the download to a position relative to the end of the queue. If the destination position is less than 0 or beyond the end of the queue, it moves the download to the beginning or the end of the queue respectively. The response is an integer denoting the resulting position.
func (*Client) Close ¶
Close closes the connection to the aria2 rpc interface. The client becomes unusable after that point.
func (*Client) Delete ¶
Delete removes the download denoted by gid and deletes all corresponding files.
func (*Client) Download ¶
Download adds a new download and waits for it to complete. It returns the status of the finished download.
func (*Client) DownloadWithContext ¶
func (c *Client) DownloadWithContext(ctx context.Context, uris []string, options *Options) (status Status, err error)
DownloadWithContext adds a new download and waits for it to complete. The passed context can be used to cancel the download. It returns the status of the finished download.
func (*Client) ForcePause ¶
ForcePause pauses the download denoted by gid. This method behaves just like Pause() except that this method pauses downloads without performing any actions which take time, such as contacting BitTorrent trackers to unregister the download first.
func (*Client) ForcePauseAll ¶
ForcePauseAll is equal to calling ForcePause() for every active/waiting download.
func (*Client) ForceRemove ¶
ForceRemove removes the download denoted by gid. This method behaves just like Remove() except that this method removes the download without performing any actions which take time, such as contacting BitTorrent trackers to unregister the download first.
func (*Client) GetFiles ¶
GetFiles returns the file list of the download denoted by gid. The response is a slice of File.
func (*Client) GetGID ¶
GetGID creates a GID struct which you can use to interact with the download directly
func (*Client) GetURIs ¶
GetURIs returns the URIs used in the download denoted by gid. The response is a slice of URI.
func (*Client) Pause ¶
Pause pauses the download denoted by gid. The status of paused download becomes paused. If the download was active, the download is placed in the front of the queue. While the status is paused, the download is not started. To change status to waiting, use the Unpause() method.
func (*Client) Remove ¶
Remove removes the download denoted by gid. If the specified download is in progress, it is first stopped. The status of the removed download becomes removed.
func (*Client) Subscribe ¶
func (c *Client) Subscribe(name string, listener EventListener)
Subscribe registers the given listener for an event. The listener will be called every time the event occurs.
func (*Client) TellStatus ¶
TellStatus returns the progress of the download denoted by gid. If specified, the response only contains only the keys passed to the method. If keys is empty, the response contains all keys. This is useful when you just want specific keys and avoid unnecessary transfers.
func (*Client) Unpause ¶
Unpause changes the status of the download denoted by gid from paused to waiting, making the download eligible to be restarted.
func (*Client) UnpauseAll ¶
UnpauseAll is equal to calling Unpause() for every paused download.
func (*Client) WaitForDownload ¶
WaitForDownload waits for a download denoted by its gid to finish.
type DownloadEvent ¶
type DownloadEvent struct {
GID string
}
DownloadEvent represents the event emitted by aria2 concerning downloads. It only contains the gid of the download.
func (*DownloadEvent) String ¶
func (e *DownloadEvent) String() string
type EventListener ¶
type EventListener func(event *DownloadEvent)
type ExitStatus ¶
type ExitStatus uint8
Integer returned by aria2 for failed downloads. Please see https://aria2.github.io/manual/en/html/aria2c.html#exit-status
const ( // All downloads were successful. Success ExitStatus = iota // An unknown error occurred. UnknownError // Time out occurred. Timeout // A resource was not found. ResourceNotFound // aria2 saw the specified number of “resource not found” error. See --max-file-not-found option. ResourceNotFoundReached // A download aborted because download speed was too slow. See --lowest-speed-limit option. DownloadSpeedTooSlow // Network problem occurred. NetworkError // There were unfinished downloads. // This error is only reported if all finished downloads were successful and there were unfinished // downloads in a queue when aria2 exited by pressing Ctrl-C by an user or sending TERM or INT signal. UnfinishedDownloads // Remote server did not support resume when resume was required to complete download. RemoteNoResume // There was not enough disk space available. NotEnoughDiskSpace // Piece length was different from one in .aria2 control file. See --allow-piece-length-change option. PieceLengthMismatch // aria2 was downloading same file at that moment. SameFileBeingDownloaded // aria2 was downloading same info hash torrent at that moment. SameInfoHashBeingDownloaded // File already existed. See --allow-overwrite option. FileAlreadyExists // Renaming file failed. See --auto-file-renaming option. RenamingFailed // aria2 could not open existing file. CouldNotOpenExistingFile // aria2 could not create new file or truncate existing file. CouldNotCreateNewFile // File I/O error occurred. FileIOError // aria2 could not create directory. CouldNotCreateDirectory // Name resolution failed. NameResolutionFailed // aria2 could not parse Metalink document. MetalinkParsingFailed // FTP command failed. FTPCommandFailed // HTTP response header was bad or unexpected. HTTPResponseHeaderBad // Too many redirects occurred. TooManyRedirects // HTTP authorization failed. HttpAuthorizationFailed // aria2 could not parse bencoded file (usually “.torrent” file). BencodedFileParseError // “.torrent” file was corrupted or missing information that aria2 needed. TorrentFileCorrupt // Magnet URI was bad. MagnetURIBad // The remote server was unable to handle the request due to a temporary overloading or maintenance. RemoteServerHandleRequestError // aria2 could not parse JSON-RPC request. JSONRPCParseError // Reserved. Not used. If you get this error then the library is probably out-of-date, // or the universe is breaking down. Reserved // Checksum validation failed. ChecksumValidationFailed )
type GID ¶
type GID struct { GID string // contains filtered or unexported fields }
GID provides an object oriented approach to aria2. Instead of calling the methods on the client directly, you can call them on the GID instance.
func (*GID) ForcePause ¶
ForcePause pauses the download. This method behaves just like Pause() except that this method pauses downloads without performing any actions which take time, such as contacting BitTorrent trackers to unregister the download first.
func (*GID) ForceRemove ¶
ForceRemove removes the download. This method behaves just like Remove() except that this method removes the download without performing any actions which take time, such as contacting BitTorrent trackers to unregister the download first.
func (*GID) GetFiles ¶
GetFiles returns the file list of the download. The response is a slice of File.
func (*GID) GetURIs ¶
GetURIs returns the URIs used in the download. The response is a slice of URI.
func (*GID) Pause ¶
Pause pauses the download. The status of paused download becomes paused. If the download was active, the download is placed in the front of the queue. While the status is paused, the download is not started. To change status to waiting, use the Unpause() method.
func (*GID) Remove ¶
Remove removes the download. If the specified download is in progress, it is first stopped. The status of the removed download becomes removed.
func (*GID) TellStatus ¶
TellStatus returns the progress of the download. If specified, the response only contains only the keys passed to the method. If keys is empty, the response contains all keys. This is useful when you just want specific keys and avoid unnecessary transfers.
func (*GID) Unpause ¶
Unpause changes the status of the download from paused to waiting, making the download eligible to be restarted.
func (*GID) WaitForDownload ¶
WaitForDownload waits for the download to finish.
type Options ¶
type Options struct { AllProxy string `json:"all-proxy,omitempty"` AllProxyPassword string `json:"all-proxy-passwd,omitempty"` AllProxyUser string `json:"all-proxy-user,omitempty"` AllowOverwrite bool `json:"allow-overwrite,omitempty,string"` AllowPieceLengthChange bool `json:"allow-piece-length-change,omitempty,string"` AlwaysResume bool `json:"always-resume,omitempty,string"` AsyncDNS bool `json:"async-dns,omitempty,string"` AutoFileRenaming bool `json:"auto-file-renaming,omitempty,string"` BtEnableHookAfterHashCheck bool `json:"bt-enable-hook-after-hash-check,omitempty,string"` BtEnableLpd bool `json:"bt-enable-lpd,omitempty,string"` BtExcludeTracker string `json:"bt-exclude-tracker,omitempty"` BtExternalIP string `json:"bt-external-ip,omitempty"` BtForceEncryption bool `json:"bt-force-encryption,omitempty,string"` BtHashCheckSeed bool `json:"bt-hash-check-seed,omitempty,string"` BtLoadSavedMetadata bool `json:"bt-load-saved-metadata,omitempty,string"` BtMaxPeers uint `json:"bt-max-peers,omitempty,string"` BtMetadataOnly bool `json:"bt-metadata-only,omitempty,string"` BtMinCryptoLevel string `json:"bt-min-crypto-level,omitempty"` BtPrioritizePiece string `json:"bt-prioritize-piece,omitempty"` BtRemoveUnselectedFile bool `json:"bt-remove-unselected-file,omitempty,string"` BtRequestPeerSpeedLimit string `json:"bt-request-peer-speed-limit,omitempty"` BtRequireCrypto bool `json:"bt-require-crypto,omitempty,string"` BtSaveMetadata bool `json:"bt-save-metadata,omitempty,string"` BtSeedUnverified bool `json:"bt-seed-unverified,omitempty,string"` BtStopTimeout uint `json:"bt-stop-timeout,omitempty,string"` BtTracker string `json:"bt-tracker,omitempty"` BtTrackerConnectTimeout uint `json:"bt-tracker-connect-timeout,omitempty,string"` BtTrackerInterval uint `json:"bt-tracker-interval,omitempty,string"` BtTrackerTimeout uint `json:"bt-tracker-timeout,omitempty,string"` CheckIntegrity bool `json:"check-integrity,omitempty,string"` Checksum string `json:"checksum,omitempty"` ConditionalGet bool `json:"conditional-get,omitempty,string"` ConnectTimeout uint `json:"connect-timeout,omitempty,string"` ContentDispositionDefaultUtf8 bool `json:"content-disposition-default-utf8,omitempty,string"` Continue bool `json:"continue,omitempty,string"` Dir string `json:"dir,omitempty"` DryRun bool `json:"dry-run,omitempty,string"` EnableHttpKeepAlive bool `json:"enable-http-keep-alive,omitempty,string"` EnableHttpPipelining bool `json:"enable-http-pipelining,omitempty,string"` EnableMmap bool `json:"enable-mmap,omitempty,string"` EnablePeerExchange bool `json:"enable-peer-exchange,omitempty,string"` FileAllocation string `json:"file-allocation,omitempty"` FollowMetalink bool `json:"follow-metalink,omitempty,string"` FollowTorrent bool `json:"follow-torrent,omitempty,string"` ForceSave bool `json:"force-save,omitempty,string"` FtpPasswd string `json:"ftp-passwd,omitempty"` FtpPasv bool `json:"ftp-pasv,omitempty,string"` FtpProxy string `json:"ftp-proxy,omitempty"` FtpProxyPasswd string `json:"ftp-proxy-passwd,omitempty"` FtpProxyUser string `json:"ftp-proxy-user,omitempty"` FtpReuseConnection bool `json:"ftp-reuse-connection,omitempty,string"` FtpType string `json:"ftp-type,omitempty"` FtpUser string `json:"ftp-user,omitempty"` GID string `json:"gid,omitempty"` HashCheckOnly bool `json:"hash-check-only,omitempty,string"` Header string `json:"header,omitempty"` HttpAcceptGzip bool `json:"http-accept-gzip,omitempty,string"` HttpAuthChallenge bool `json:"http-auth-challenge,omitempty,string"` HttpNoCache bool `json:"http-no-cache,omitempty,string"` HttpPasswd string `json:"http-passwd,omitempty"` HttpProxy string `json:"http-proxy,omitempty"` HttpProxyPasswd string `json:"http-proxy-passwd,omitempty"` HttpProxyUser string `json:"http-proxy-user,omitempty"` HttpUser string `json:"http-user,omitempty"` HttpsProxy string `json:"https-proxy,omitempty"` HttpsProxyPasswd string `json:"https-proxy-passwd,omitempty"` HttpsProxyUser string `json:"https-proxy-user,omitempty"` IndexOut uint `json:"index-out,omitempty,string"` LowestSpeedLimit uint `json:"lowest-speed-limit,omitempty,string"` MaxConnectionPerServer uint `json:"max-connection-per-server,omitempty,string"` MaxDownloadLimit uint `json:"max-download-limit,omitempty,string"` MaxFileNotFound uint `json:"max-file-not-found,omitempty,string"` MaxMmapLimit uint `json:"max-mmap-limit,omitempty,string"` MaxResumeFailureTries uint `json:"max-resume-failure-tries,omitempty,string"` MaxTries uint `json:"max-tries,omitempty,string"` MaxUploadLimit uint `json:"max-upload-limit,omitempty,string"` MetalinkBaseUri string `json:"metalink-base-uri,omitempty"` MetalinkEnableUniqueProtocol bool `json:"metalink-enable-unique-protocol,omitempty,string"` MetalinkLanguage string `json:"metalink-language,omitempty"` MetalinkLocation string `json:"metalink-location,omitempty"` MetalinkOs string `json:"metalink-os,omitempty"` MetalinkPreferredProtocol string `json:"metalink-preferred-protocol,omitempty"` MetalinkVersion string `json:"metalink-version,omitempty"` MinSplitSize uint `json:"min-split-size,omitempty,string"` NoFileAllocationLimit bool `json:"no-file-allocation-limit,omitempty,string"` NoNetrc bool `json:"no-netrc,omitempty,string"` NoProxy bool `json:"no-proxy,omitempty,string"` Out string `json:"out,omitempty"` ParameterizedUri string `json:"parameterized-uri,omitempty"` Pause bool `json:"pause,omitempty,string"` PauseMetadata bool `json:"pause-metadata,omitempty,string"` PieceLength string `json:"piece-length,omitempty"` ProxyMethod string `json:"proxy-method,omitempty"` RealtimeChunkChecksum string `json:"realtime-chunk-checksum,omitempty"` Referer string `json:"referer,omitempty"` RemoteTime bool `json:"remote-time,omitempty,string"` RemoveControlFile string `json:"remove-control-file,omitempty"` RetryWait uint `json:"retry-wait,omitempty,string"` ReuseUri bool `json:"reuse-uri,omitempty,string"` RpcSaveUploadMetadata string `json:"rpc-save-upload-metadata,omitempty"` SeedRatio float32 `json:"seed-ratio,omitempty,string"` SeedTime uint `json:"seed-time,omitempty,string"` SelectFile bool `json:"select-file,omitempty,string"` Split uint `json:"split,omitempty,string"` SshHostKeyMd string `json:"ssh-host-key-md,omitempty"` StreamPieceSelector string `json:"stream-piece-selector,omitempty"` Timeout uint `json:"timeout,omitempty,string"` UriSelector string `json:"uri-selector,omitempty"` UseHead bool `json:"use-head,omitempty,string"` UserAgent string `json:"user-agent,omitempty"` }
type PositionSetBehaviour ¶
type PositionSetBehaviour string
const ( SetPositionStart PositionSetBehaviour = "POS_SET" SetPositionEnd PositionSetBehaviour = "POS_END" SetPositionRelative PositionSetBehaviour = "POS_CUR" )
type Status ¶
type Status struct { GID string Status StatusName TotalLength uint `json:",string"` CompletedLength uint `json:",string"` UploadLength uint `json:",string"` BitField string DownloadSpeed uint `json:",string"` UploadSpeed uint `json:",string"` InfoHash string NumSeeders uint `json:",string"` Seeder bool `json:",string"` PieceLength uint `json:",string"` NumPieces uint `json:",string"` Connections uint `json:",string"` ErrorCode ExitStatus `json:",string"` ErrorMessage string FollowedBy []string Following string BelongsTo string Dir string Files []File Bittorrent BittorrentStatus VerifiedLength uint `json:",string"` VerifyIntegrityPending bool `json:",string"` }
type StatusName ¶
type StatusName string
const ( StatusActive StatusName = "active" StatusWaiting StatusName = "waiting" StatusPaused StatusName = "paused" StatusError StatusName = "error" StatusCompleted StatusName = "completed" StatusRemoved StatusName = "removed" )