wip: adapt qBittorrent
This commit is contained in:
@ -164,10 +164,6 @@ func InitialSettings() []model.SettingItem {
|
||||
{Key: conf.SSODefaultDir, Value: "/", Type: conf.TypeString, Group: model.SSO, Flag: model.PRIVATE},
|
||||
{Key: conf.SSODefaultPermission, Value: "0", Type: conf.TypeNumber, Group: model.SSO, Flag: model.PRIVATE},
|
||||
{Key: conf.SSOCompatibilityMode, Value: "false", Type: conf.TypeBool, Group: model.SSO, Flag: model.PUBLIC},
|
||||
|
||||
// qbittorrent settings
|
||||
{Key: conf.QbittorrentUrl, Value: "http://admin:adminadmin@localhost:8080/", Type: conf.TypeString, Group: model.SINGLE, Flag: model.PRIVATE},
|
||||
{Key: conf.QbittorrentSeedtime, Value: "0", Type: conf.TypeNumber, Group: model.SINGLE, Flag: model.PRIVATE},
|
||||
}
|
||||
initialSettingItems = append(initialSettingItems, tool.Tools.Items()...)
|
||||
if flags.Dev {
|
||||
|
@ -2,4 +2,5 @@ package offline_download
|
||||
|
||||
import (
|
||||
_ "github.com/alist-org/alist/v3/internal/offline_download/aria2"
|
||||
_ "github.com/alist-org/alist/v3/internal/offline_download/qbit"
|
||||
)
|
||||
|
80
internal/offline_download/qbit/qbit.go
Normal file
80
internal/offline_download/qbit/qbit.go
Normal file
@ -0,0 +1,80 @@
|
||||
package qbit
|
||||
|
||||
import (
|
||||
"github.com/alist-org/alist/v3/internal/conf"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/internal/offline_download/tool"
|
||||
"github.com/alist-org/alist/v3/internal/qbittorrent"
|
||||
"github.com/alist-org/alist/v3/internal/setting"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type QBittorrent struct {
|
||||
client qbittorrent.Client
|
||||
}
|
||||
|
||||
func (a *QBittorrent) Items() []model.SettingItem {
|
||||
// aria2 settings
|
||||
return []model.SettingItem{
|
||||
{Key: conf.QbittorrentUrl, Value: "http://admin:adminadmin@localhost:8080/", Type: conf.TypeString, Group: model.OFFLINE_DOWNLOAD, Flag: model.PRIVATE},
|
||||
{Key: conf.QbittorrentSeedtime, Value: "0", Type: conf.TypeNumber, Group: model.OFFLINE_DOWNLOAD, Flag: model.PRIVATE},
|
||||
}
|
||||
}
|
||||
|
||||
func (a *QBittorrent) Init() (string, error) {
|
||||
a.client = nil
|
||||
url := setting.GetStr(conf.QbittorrentUrl)
|
||||
qbClient, err := qbittorrent.New(url)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
a.client = qbClient
|
||||
return "ok", nil
|
||||
}
|
||||
|
||||
func (a *QBittorrent) IsReady() bool {
|
||||
return a.client != nil
|
||||
}
|
||||
|
||||
func (a *QBittorrent) AddURL(args *tool.AddUrlArgs) (string, error) {
|
||||
err := a.client.AddFromLink(args.Url, args.TempDir, args.UID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return args.UID, nil
|
||||
}
|
||||
|
||||
func (a *QBittorrent) Remove(tid string) error {
|
||||
err := a.client.Delete(tid, true)
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *QBittorrent) Status(tid string) (*tool.Status, error) {
|
||||
info, err := a.client.GetInfo(tid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s := &tool.Status{}
|
||||
s.Progress = float64(info.Completed) / float64(info.Size) * 100
|
||||
switch info.State {
|
||||
case qbittorrent.UPLOADING, qbittorrent.PAUSEDUP, qbittorrent.QUEUEDUP, qbittorrent.STALLEDUP, qbittorrent.FORCEDUP, qbittorrent.CHECKINGUP:
|
||||
s.Completed = true
|
||||
case qbittorrent.ALLOCATING, qbittorrent.DOWNLOADING, qbittorrent.METADL, qbittorrent.PAUSEDDL, qbittorrent.QUEUEDDL, qbittorrent.STALLEDDL, qbittorrent.CHECKINGDL, qbittorrent.FORCEDDL, qbittorrent.CHECKINGRESUMEDATA, qbittorrent.MOVING:
|
||||
s.Status = "[qBittorrent] downloading"
|
||||
case qbittorrent.ERROR, qbittorrent.MISSINGFILES, qbittorrent.UNKNOWN:
|
||||
s.Err = errors.Errorf("[qBittorrent] failed to download %s, error: %s", tid, info.State)
|
||||
default:
|
||||
s.Err = errors.Errorf("[qBittorrent] unknown error occurred downloading %s", tid)
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (a *QBittorrent) GetFiles(tid string) []tool.File {
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ tool.Tool = (*QBittorrent)(nil)
|
||||
|
||||
func init() {
|
||||
tool.Tools.Add("qBittorrent", &QBittorrent{})
|
||||
}
|
Reference in New Issue
Block a user