aria2

package
v0.0.0-...-746aa3e Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2020 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// URLTask 从URL添加的任务
	URLTask = iota
	// TorrentTask 种子任务
	TorrentTask
)
View Source
const (
	// Ready 准备就绪
	Ready = iota
	// Downloading 下载中
	Downloading
	// Paused 暂停中
	Paused
	// Error 出错
	Error
	// Complete 完成
	Complete
	// Canceled 取消/停止
	Canceled
	// Unknown 未知状态
	Unknown
)

Variables

View Source
var (
	// ErrNotEnabled 功能未开启错误
	ErrNotEnabled = serializer.NewError(serializer.CodeNoPermissionErr, "离线下载功能未开启", nil)
	// ErrUserNotFound 未找到下载任务创建者
	ErrUserNotFound = serializer.NewError(serializer.CodeNotFound, "无法找到任务创建者", nil)
)
View Source
var EventNotifier = &Notifier{}

EventNotifier 任务状态更新通知处理器

Lock Instance的读写锁

View Source
var MAX_RETRY = 10

Functions

func Init

func Init(isReload bool)

Init 初始化

func NewMonitor

func NewMonitor(task *model.Download)

NewMonitor 新建上传状态监控

Types

type Aria2

type Aria2 interface {
	// CreateTask 创建新的任务
	CreateTask(task *model.Download, options map[string]interface{}) error
	// 返回状态信息
	Status(task *model.Download) (rpc.StatusInfo, error)
	// 取消任务
	Cancel(task *model.Download) error
	// 选择要下载的文件
	Select(task *model.Download, files []int) error
}

Aria2 离线下载处理接口

var Instance Aria2 = &DummyAria2{}

Instance 默认使用的Aria2处理实例

type DummyAria2

type DummyAria2 struct {
}

DummyAria2 未开启Aria2功能时使用的默认处理器

func (*DummyAria2) Cancel

func (instance *DummyAria2) Cancel(task *model.Download) error

Cancel 返回未开启错误

func (*DummyAria2) CreateTask

func (instance *DummyAria2) CreateTask(model *model.Download, options map[string]interface{}) error

CreateTask 创建新任务,此处直接返回未开启错误

func (*DummyAria2) Select

func (instance *DummyAria2) Select(task *model.Download, files []int) error

Select 返回未开启错误

func (*DummyAria2) Status

func (instance *DummyAria2) Status(task *model.Download) (rpc.StatusInfo, error)

Status 返回未开启错误

type Monitor

type Monitor struct {
	Task     *model.Download
	Interval time.Duration
	// contains filtered or unexported fields
}

Monitor 离线下载状态监控

func (*Monitor) Complete

func (monitor *Monitor) Complete(status rpc.StatusInfo) bool

Complete 完成下载,返回是否中断监控

func (*Monitor) Error

func (monitor *Monitor) Error(status rpc.StatusInfo) bool

Error 任务下载出错处理,返回是否中断监控

func (*Monitor) Loop

func (monitor *Monitor) Loop()

Loop 开启监控循环

func (*Monitor) RemoveTempFolder

func (monitor *Monitor) RemoveTempFolder()

RemoveTempFolder 清理下载临时目录

func (*Monitor) Update

func (monitor *Monitor) Update() bool

Update 更新状态,返回值表示是否退出监控

func (*Monitor) UpdateTaskInfo

func (monitor *Monitor) UpdateTaskInfo(status rpc.StatusInfo) error

UpdateTaskInfo 更新数据库中的任务信息

func (*Monitor) ValidateFile

func (monitor *Monitor) ValidateFile() error

ValidateFile 上传过程中校验文件大小、文件名

type Notifier

type Notifier struct {
	Subscribes sync.Map
}

Notifier aria2实践通知处理

func (*Notifier) Notify

func (notifier *Notifier) Notify(events []rpc.Event, status int)

Notify 发送通知

func (*Notifier) OnBtDownloadComplete

func (notifier *Notifier) OnBtDownloadComplete(events []rpc.Event)

OnBtDownloadComplete BT下载完成

func (*Notifier) OnDownloadComplete

func (notifier *Notifier) OnDownloadComplete(events []rpc.Event)

OnDownloadComplete 下载完成

func (*Notifier) OnDownloadError

func (notifier *Notifier) OnDownloadError(events []rpc.Event)

OnDownloadError 下载出错

func (*Notifier) OnDownloadPause

func (notifier *Notifier) OnDownloadPause(events []rpc.Event)

OnDownloadPause 下载暂停

func (*Notifier) OnDownloadStart

func (notifier *Notifier) OnDownloadStart(events []rpc.Event)

OnDownloadStart 下载开始

func (*Notifier) OnDownloadStop

func (notifier *Notifier) OnDownloadStop(events []rpc.Event)

OnDownloadStop 下载停止

func (*Notifier) Subscribe

func (notifier *Notifier) Subscribe(target chan StatusEvent, gid string)

Subscribe 订阅事件通知

func (*Notifier) Unsubscribe

func (notifier *Notifier) Unsubscribe(gid string)

Unsubscribe 取消订阅事件通知

type RPCService

type RPCService struct {
	Caller rpc.Client
	// contains filtered or unexported fields
}

RPCService 通过RPC服务的Aria2任务管理器

func (*RPCService) Cancel

func (client *RPCService) Cancel(task *model.Download) error

Cancel 取消下载

func (*RPCService) CreateTask

func (client *RPCService) CreateTask(task *model.Download, groupOptions map[string]interface{}) error

CreateTask 创建新任务

func (*RPCService) Init

func (client *RPCService) Init(server, secret string, timeout int, options map[string]interface{}) error

Init 初始化

func (*RPCService) Select

func (client *RPCService) Select(task *model.Download, files []int) error

Select 选取要下载的文件

func (*RPCService) Status

func (client *RPCService) Status(task *model.Download) (rpc.StatusInfo, error)

Status 查询下载状态

type StatusEvent

type StatusEvent struct {
	GID    string
	Status int
}

StatusEvent 状态改变事件

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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