mirror of
https://github.com/celogeek/go-qbittorrent-sync.git
synced 2025-05-26 00:42:35 +02:00
Compare commits
No commits in common. "f4d4f3075ead4b8620ecb63adc8fcc3a674c68da" and "5d16ff8424250f9951395850ec944efb63b45f3c" have entirely different histories.
f4d4f3075e
...
5d16ff8424
@ -25,8 +25,6 @@ Usage of go-qbittorrent-sync:
|
|||||||
Number of second to check new files to sync (default 30)
|
Number of second to check new files to sync (default 30)
|
||||||
-qbittorrent-password string
|
-qbittorrent-password string
|
||||||
Password of qbittorrent
|
Password of qbittorrent
|
||||||
-qbittorrent-password-file string
|
|
||||||
Password file with the password of qbittorrent
|
|
||||||
-qbittorrent-sync-tag string
|
-qbittorrent-sync-tag string
|
||||||
Tag of qbittorrent to copy (default "Sync")
|
Tag of qbittorrent to copy (default "Sync")
|
||||||
-qbittorrent-synced-tag string
|
-qbittorrent-synced-tag string
|
||||||
|
16
main.go
16
main.go
@ -1,10 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"flag"
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,7 +13,6 @@ func main() {
|
|||||||
flag.StringVar(&qbitoptions.Uri, "qbittorrent-uri", "http://localhost:8080", "URI of qbittorrent")
|
flag.StringVar(&qbitoptions.Uri, "qbittorrent-uri", "http://localhost:8080", "URI of qbittorrent")
|
||||||
flag.StringVar(&qbitoptions.Username, "qbittorrent-username", "", "Username of qbittorrent")
|
flag.StringVar(&qbitoptions.Username, "qbittorrent-username", "", "Username of qbittorrent")
|
||||||
flag.StringVar(&qbitoptions.Password, "qbittorrent-password", "", "Password of qbittorrent")
|
flag.StringVar(&qbitoptions.Password, "qbittorrent-password", "", "Password of qbittorrent")
|
||||||
flag.StringVar(&qbitoptions.PasswordFile, "qbittorrent-password-file", "", "Password file with the password of qbittorrent")
|
|
||||||
flag.StringVar(&qbitoptions.SyncTag, "qbittorrent-sync-tag", "Sync", "Tag of qbittorrent to copy")
|
flag.StringVar(&qbitoptions.SyncTag, "qbittorrent-sync-tag", "Sync", "Tag of qbittorrent to copy")
|
||||||
flag.StringVar(&qbitoptions.SyncedTag, "qbittorrent-synced-tag", "", "Tag of qbittorrent when copy finished")
|
flag.StringVar(&qbitoptions.SyncedTag, "qbittorrent-synced-tag", "", "Tag of qbittorrent when copy finished")
|
||||||
flag.StringVar(&rsyncoptions.Hostname, "rsync-hostname", "", "Rsync host")
|
flag.StringVar(&rsyncoptions.Hostname, "rsync-hostname", "", "Rsync host")
|
||||||
@ -25,19 +22,6 @@ func main() {
|
|||||||
flag.IntVar(&poolTime, "pool-time", 30, "Number of second to check new files to sync")
|
flag.IntVar(&poolTime, "pool-time", 30, "Number of second to check new files to sync")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if qbitoptions.PasswordFile != "" {
|
|
||||||
var b []byte
|
|
||||||
var ok bool
|
|
||||||
var err error
|
|
||||||
if b, err = os.ReadFile(qbitoptions.PasswordFile); err != nil {
|
|
||||||
log.Fatalf("[Qbit] Reading password file failed: %v", err)
|
|
||||||
}
|
|
||||||
if b, ok = bytes.CutSuffix(b, []byte{'\r', '\n'}); !ok {
|
|
||||||
b, _ = bytes.CutSuffix(b, []byte{'\n'})
|
|
||||||
}
|
|
||||||
qbitoptions.Password = string(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
if qbitoptions.Uri == "" ||
|
if qbitoptions.Uri == "" ||
|
||||||
qbitoptions.Username == "" ||
|
qbitoptions.Username == "" ||
|
||||||
qbitoptions.Password == "" ||
|
qbitoptions.Password == "" ||
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -10,12 +8,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type QBitTorrentOptions struct {
|
type QBitTorrentOptions struct {
|
||||||
Uri string
|
Uri string
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
PasswordFile string
|
SyncTag string
|
||||||
SyncTag string
|
SyncedTag string
|
||||||
SyncedTag string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type QBittorrentCli struct {
|
type QBittorrentCli struct {
|
||||||
@ -35,7 +32,7 @@ type Torrent struct {
|
|||||||
func NewQBittorrentCli(options *QBitTorrentOptions) (*QBittorrentCli, error) {
|
func NewQBittorrentCli(options *QBitTorrentOptions) (*QBittorrentCli, error) {
|
||||||
r := resty.New().SetBaseURL(fmt.Sprintf("%s/api/v2", options.Uri))
|
r := resty.New().SetBaseURL(fmt.Sprintf("%s/api/v2", options.Uri))
|
||||||
|
|
||||||
result, err := r.
|
_, err := r.
|
||||||
R().
|
R().
|
||||||
SetFormData(map[string]string{
|
SetFormData(map[string]string{
|
||||||
"username": options.Username,
|
"username": options.Username,
|
||||||
@ -47,10 +44,6 @@ func NewQBittorrentCli(options *QBitTorrentOptions) (*QBittorrentCli, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal(result.Body(), []byte("Ok.")) {
|
|
||||||
return nil, errors.New("auth failed")
|
|
||||||
}
|
|
||||||
|
|
||||||
cli := &QBittorrentCli{
|
cli := &QBittorrentCli{
|
||||||
SyncTag: options.SyncTag,
|
SyncTag: options.SyncTag,
|
||||||
SyncedTag: options.SyncedTag,
|
SyncedTag: options.SyncedTag,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user