deluge

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

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

Go to latest
Published: Sep 20, 2018 License: MIT Imports: 16 Imported by: 0

README

go-deluge

A lightweight deluge library for Go

Example

package main

import (
	"fmt"
	"os"

	"github.com/naposproject/go-deluge"
)

func main() {
	c, err := deluge.NewClient(&deluge.Client{
		API:      "http://localhost:8112/json",
		Username: "admin",
		Password: os.Getenv("TORRENT_PASSWORD"),
	})

	if err != nil {
		fmt.Printf("%s\n", err.Error())
	}

	fmt.Printf("Getting torrents..\n")
	torrents, err := c.GetTorrents()
	if err != nil {
		fmt.Printf("%s\n", err.Error())
	}

	for _, torrent := range torrents {
		fmt.Printf("Name: %s, Added: %d, Completed: %d, Filepath: %s\n", torrent.Name, torrent.AddedOn, torrent.CompletedOn, torrent.FilePath)
	}

	os.Exit(0)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TorrentProperties string = "" /* 327-byte string literal not displayed */

TorrentProperties is a string containing the json keys to grab via JSONRPC it vastly speeds up the call due to only grabbing the required values

Functions

This section is empty.

Types

type ArrayResponse

type ArrayResponse struct {
	Id     int      `json:"id"`
	Result []string `json:"result"`
	Error  RpcError `json:"error"`
}

type BoolResponse

type BoolResponse struct {
	Id     int      `json:"id"`
	Result bool     `json:"result"`
	Error  RpcError `json:"error"`
}

type Client

type Client struct {
	API      string
	Username string
	Password string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(c *Client) (*Client, error)

func (*Client) AddTorrent

func (c *Client) AddTorrent(url string) error

AddTorrent adds the torrent specified by url or magnet link

func (*Client) AddTorrentFile

func (c *Client) AddTorrentFile(torrentpath string) error

AddTorrentFile adds the torrent specified by a file on disk

func (*Client) GetTorrent

func (c *Client) GetTorrent(hash string) (Torrent, error)

GetTorrent gets a specific torrent by info hash

func (*Client) GetTorrents

func (c *Client) GetTorrents() ([]Torrent, error)

GetTorrents returns a list of Torrent structs containing all of the torrents added to the deluge/Bittorrent server

func (*Client) PauseTorrent

func (c *Client) PauseTorrent(hash string) error

PauseTorrent pauses the torrent specified by info hash

func (*Client) QueueBottom

func (c *Client) QueueBottom(hash string) error

QueueTop sends the torrent to the bottom of the download queue

func (*Client) QueueDown

func (c *Client) QueueDown(hash string) error

QueueUp moves the torrent down the download queue

func (*Client) QueueTop

func (c *Client) QueueTop(hash string) error

QueueTop sends the torrent to the top of the download queue

func (*Client) QueueUp

func (c *Client) QueueUp(hash string) error

QueueUp moves the torrent up the download queue

func (*Client) RecheckTorrent

func (c *Client) RecheckTorrent(hash string) error

RecheckTorrent rechecks the torrent specified by info hash

func (*Client) RemoveTorrent

func (c *Client) RemoveTorrent(hash string) error

RemoveTorrent removes the torrent specified by info hash

func (*Client) RemoveTorrentAndData

func (c *Client) RemoveTorrentAndData(hash string) error

RemoveTorrentAndData removes the torrent and associated data specified by info hash

func (*Client) SetTorrentLabel

func (c *Client) SetTorrentLabel(hash string, label string) error

SetTorrentLabel sets the label for the given torrent

func (*Client) SetTorrentSeedRatio

func (c *Client) SetTorrentSeedRatio(hash string, ratio float64) error

SetTorrentSeedRatio sets the seed ratio for the given torrent

func (*Client) SetTorrentSeedTime

func (c *Client) SetTorrentSeedTime(hash string, time int) error

SetTorrentSeedTime sets the seed time for the given torrent

func (*Client) StartTorrent

func (c *Client) StartTorrent(hash string) error

StartTorrent starts the torrent specified by info hash

func (*Client) StopTorrent

func (c *Client) StopTorrent(hash string) error

StopTorrent stops the torrent specified by info hash

func (*Client) UnPauseTorrent

func (c *Client) UnPauseTorrent(hash string) error

UnPauseTorrent unpauses the torrent specified by info hash

type RpcError

type RpcError struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

type StringResponse

type StringResponse struct {
	Id     int      `json:"id"`
	Result string   `json:"result"`
	Error  RpcError `json:"error"`
}

type Torrent

type Torrent struct {
	Hash            string  `json:"hash"`
	StatusCode      int     `json:"status_code"`
	Name            string  `json:"name"`
	Size            int     `json:"total_size"`
	PercentProgress float64 `json:"progress"`
	Downloaded      int     `json:"all_time_download"`
	Uploaded        int     `json:"total_uploaded"`
	Ratio           float64 `json:"ratio"`
	UploadSpeed     int     `json:"upload_payload_rate"`
	DownloadSpeed   int     `json:"download_payload_rate"`
	ETA             int     `json:"eta"`
	Label           string  `json:"label"`
	PeersConnected  int     `json:"num_peers"`
	PeersTotal      int     `json:"total_peers"`
	SeedsConnected  int     `json:"num_seeds"`
	SeedsTotal      int     `json:"total_seeds"`
	Availability    float64 `json:"seeds_peers_ratio"`
	QueueOrder      int     `json:"queue"`
	Remaining       int     `json:"remaining"`
	Status          string  `json:"state"`
	AddedOn         int     `json:"added_on"`
	CompletedOn     int     `json:"completed_on"`
	FilePath        string  `json:"move_on_completed_path"`
	AddedRaw        float64 `json:"time_added"`
}

type TorrentResponse

type TorrentResponse struct {
	Index   int      `json:"id"`
	Torrent Torrent  `json:"result"`
	Error   RpcError `json:"error"`
}

TorrentResponse is an interface that allows unmarshalling of the deluge/Bittorrent api into proper golang compatible Torrent structs.

type TorrentsResponse

type TorrentsResponse struct {
	Index       int                `json:"id"`
	RawTorrents map[string]Torrent `json:"result"`
	Torrents    []Torrent
	Error       RpcError `json:"error"`
}

TorrentsResponse is an interface that allows unmarshalling of the deluge/Bittorrent api into proper golang compatible Torrent structs.

func (*TorrentsResponse) UnmarshalJSON

func (torrents *TorrentsResponse) UnmarshalJSON(b []byte) error

UnmarshallJSON is a custom unmarshaller for torrent lists. Necessary due to the fact uTorrent/Bittorrent does not implement a proper json api.

Directories

Path Synopsis
examples
add_torrent command
delete_torrent command
list_torrents command
pause_unpause command
recheck command
set_properties command
start_stop command

Jump to

Keyboard shortcuts

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