aria2go

package module
v0.0.0-...-de16e07 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

README

Aria2go

Go bindings for libaria2.

Usage

  • If you are using go module, add the flowing:
required (
	"github.com/coolerfall/aria2go"
)

or you can just use:

$ go get github.com/coolerfall/aria2go
  • Prepare libaria2, be sure you have installed gcc:
$ cd path/to/aria2go
$ ./prepare.sh

or if you want to compile to arm, be sure you have installed gnueabihf cross compiler:

$ ./prepare-arm.sh
  • Now you can check the example to run.

License

Copyright (C) 2019 Vincent Cheung (coolingfall@gmail.com)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aria2

type Aria2 struct {
	// contains filtered or unexported fields
}

Type definition for lib aria2, it holds a notifier.

func NewAria2

func NewAria2(config Config) *Aria2

NewAria2 creates a new instance of aria2.

func (*Aria2) AddTorrent

func (a *Aria2) AddTorrent(filepath string, options Options) (gid string, err error)

AddTorrent adds a MetaInfo download with given torrent file path. This will return gid and files in torrent file if add successfully. User can choose specified files to download, change directory and so on.

func (*Aria2) AddUri

func (a *Aria2) AddUri(uri string, options Options) (gid string, err error)

AddUri adds a new download. The uris is an array of HTTP/FTP/SFTP/BitTorrent URIs (strings) pointing to the same resource. When adding BitTorrent Magnet URIs, uris must have only one element and it should be BitTorrent Magnet URI.

func (*Aria2) ChangeGlobalOptions

func (a *Aria2) ChangeGlobalOptions(options Options) error

ChangeGlobalOptions changes global options. See available options in https://aria2.github.io/manual/en/html/aria2c.html#input-file except for `checksum`, `index-out`, `out`, `pause` and `select-file`.

func (*Aria2) ChangeOptions

func (a *Aria2) ChangeOptions(gid string, options Options) error

ChangeOptions can change the options for aria2. See available options in https://aria2.github.io/manual/en/html/aria2c.html#input-file.

func (*Aria2) GetDownloadInfo

func (a *Aria2) GetDownloadInfo(gid string) DownloadInfo

GetDownloadInfo gets current download information for given gid.

func (*Aria2) GetGlobalOptions

func (a *Aria2) GetGlobalOptions() Options

GetGlobalOptions gets all global options of aria2.

func (*Aria2) GetOptions

func (a *Aria2) GetOptions(gid string) Options

GetOptions gets all options for given gid.

func (*Aria2) Pause

func (a *Aria2) Pause(gid string) bool

Pause pauses an active download for given gid. The status of the download will become `DOWNLOAD_PAUSED`. Use `Resume` to restart download.

func (*Aria2) Remove

func (a *Aria2) Remove(gid string) bool

Remove removes download no matter what status it was. This will stop downloading and stop seeding(for torrent).

func (*Aria2) Resume

func (a *Aria2) Resume(gid string) bool

Resume resumes an paused download for given gid.

func (*Aria2) Run

func (a *Aria2) Run()

Run starts event pooling. Note this will block current thread.

func (*Aria2) SetNotifier

func (a *Aria2) SetNotifier(notifier Notifier)

SetNotifier sets notifier to receive download notification from aria2.

func (*Aria2) Shutdown

func (a *Aria2) Shutdown() int

Shutdown aria2, this must be invoked when process exit(signal handler is not used), so aria2 will be able to save session config.

type Config

type Config struct {
	Options  Options
	Notifier Notifier
}

Type definition of configuration for aria2.

type DefaultNotifier

type DefaultNotifier struct{}

Type definition for default notifier which dose nothing.

func (DefaultNotifier) OnComplete

func (n DefaultNotifier) OnComplete(gid string)

OnComplete implements Notifier interface.

func (DefaultNotifier) OnError

func (n DefaultNotifier) OnError(gid string)

OnError implements Notifier interface.

func (DefaultNotifier) OnPause

func (n DefaultNotifier) OnPause(gid string)

OnPause implements Notifier interface.

func (DefaultNotifier) OnStart

func (n DefaultNotifier) OnStart(gid string)

OnStart implements Notifier interface.

func (DefaultNotifier) OnStop

func (n DefaultNotifier) OnStop(gid string)

OnPause implements Notifier interface.

type DownloadInfo

type DownloadInfo struct {
	Status         int
	TotalLength    int64
	BytesCompleted int64
	BytesUpload    int64
	DownloadSpeed  int
	UploadSpeed    int
	NumPieces      int
	Connections    int
	BitField       string
	InfoHash       string
	MetaInfo       MetaInfo
	Files          []File
	ErrorCode      int
	FollowedByGid  string
}

Type definition for download information.

type File

type File struct {
	Index           int
	Name            string
	Length          int64
	CompletedLength int64
	Selected        bool
}

Type definition for file in torrent.

type MetaInfo

type MetaInfo struct {
	Name         string
	AnnounceList []string
	Comment      string
	CreationUnix int64
	Mode         string
}

Type definition for BitTorrent meta information.

type Notifier

type Notifier interface {
	// OnStart will be invoked when aria2 started to download
	OnStart(gid string)

	// OnPause will be invoked when aria2 paused one download
	OnPause(gid string)

	// OnPause will be invoked when aria2 stopped one download
	OnStop(gid string)

	// OnComplete will be invoked when download completed
	OnComplete(gid string)

	// OnError will be invoked when an error occoured
	OnError(gid string)
}

Type definition for notifier which can be used in aria2c json rpc notification.

type Options

type Options map[string]string

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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