transmission

package module
v0.0.0-...-42b7745 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2019 License: MIT Imports: 10 Imported by: 1

README

Go Transmission

Golang lib for Transmission API

Installation
$ go get github.com/matthazinski/transmission
Usage
package main

import (
	"log"

	"github.com/matthazinski/transmission"
)

func main() {
	client, err := transmission.New("http://127.0.0.1:9091/transmission/rpc", "admin", "hunter2")
    if err != nil {
        log.Panic(err)
    }

	torrents, err := client.GetTorrents()
	if err != nil {
		log.Panic(err)
	}

	for _, torrent := range torrents {
		log.Println("Torrent:")
		log.Println("   ID:            ", torrent.ID)
		log.Println("   Name:          ", torrent.Name)
		log.Println("   Status:        ", torrent.Status)
		log.Println("   LeftUntilDone: ", torrent.LeftUntilDone)
		log.Println("   Eta:           ", torrent.Eta)
		log.Println("   UploadRatio:   ", torrent.UploadRatio)
		log.Println("   RateDownload:  ", torrent.RateDownload)
		log.Println("   RateUpload:    ", torrent.RateUpload)
		log.Println("   DownloadDir:   ", torrent.DownloadDir)
		log.Println("   IsFinished:    ", torrent.IsFinished)
		log.Println("   PercentDone:   ", torrent.PercentDone)
		log.Println("   SeedRatioMode: ", torrent.SeedRatioMode)
	}
}
Original author

Long Nguyen (https://github.com/longnguyen11288/go-transmission)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiClient

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

func NewClient

func NewClient(url, username, password string) *ApiClient

func (*ApiClient) CreateClient

func (ac *ApiClient) CreateClient(apiToken string)

func (*ApiClient) Post

func (ac *ApiClient) Post(body string) ([]byte, error)

type Command

type Command struct {
	Method    string    `json:"method,omitempty"`
	Arguments arguments `json:"arguments,omitempty"`
	Result    string    `json:"result,omitempty"`
}

func NewAddCmd

func NewAddCmd() *Command

func NewAddCmdByFile

func NewAddCmdByFile(file string) (*Command, error)

func NewAddCmdByFilename

func NewAddCmdByFilename(filename string) *Command

func NewAddCmdByURL

func NewAddCmdByURL(url string) *Command

URL or magnet

func NewGetTorrentsCmd

func NewGetTorrentsCmd() *Command

func (*Command) SetDownloadDir

func (cmd *Command) SetDownloadDir(dir string)

type Priority

type Priority int8
const (
	Low Priority = iota - 1
	Normal
	High
)

func (Priority) String

func (i Priority) String() string

type Sorting

type Sorting int
const (
	SortID Sorting = iota
	SortRevID
	SortName
	SortRevName
	SortAge
	SortRevAge
	SortSize
	SortRevSize
	SortProgress
	SortRevProgress
	SortDownSpeed
	SortRevDownSpeed
	SortUpSpeed
	SortRevUpSpeed
	SortDownloaded
	SortRevDownloaded
	SortUploaded
	SortRevUploaded
	SortRatio
	SortRevRatio
)

type Stats

type Stats struct {
	ActiveTorrentCount int
	CumulativeStats    cumulativeStats
	CurrentStats       currentStats
	DownloadSpeed      uint64
	PausedTorrentCount int
	TorrentCount       int
	UploadSpeed        uint64
}

session-stats

func (*Stats) CumulativeActiveTime

func (s *Stats) CumulativeActiveTime() string

func (*Stats) CurrentActiveTime

func (s *Stats) CurrentActiveTime() string

type Status

type Status int
const (
	Stopped Status = iota
	CheckPending
	Checking
	DownloadPending
	Downloading
	SeedPending
	Seeding
)

func (Status) String

func (i Status) String() string

type Torrent

type Torrent struct {
	ID             int           `json:"id"`
	Name           string        `json:"name"`
	Status         Status        `json:"status"`
	AddedDate      int64         `json:"addedDate"`
	LeftUntilDone  uint64        `json:"leftUntilDone"`
	SizeWhenDone   uint64        `json:"sizeWhenDone"`
	Eta            time.Duration `json:"eta"`
	UploadRatio    float64       `json:"uploadRatio"`
	RateDownload   uint64        `json:"rateDownload"`
	RateUpload     uint64        `json:"rateUpload"`
	DownloadDir    string        `json:"downloadDir"`
	DownloadedEver uint64        `json:"downloadedEver"`
	UploadedEver   uint64        `json:"uploadedEver"`
	HaveUnchecked  uint64        `json:"haveUnchecked"`
	HaveValid      uint64        `json:"haveValid"`
	IsFinished     bool          `json:"isFinished"`
	PercentDone    float64       `json:"percentDone"`
	SeedRatioMode  int           `json:"seedRatioMode"`
	Trackers       []tracker     `json:"trackers"`
	Error          int           `json:"error"`
	ErrorString    string        `json:"errorString"`
	Files          []file        `json:"files"`
	FileStats      []fileStat    `json:"fileStats"`
	TrackerStats   []trackerStat `json:"trackerStats"`
	Peers          []peer        `json:"peers"`
	Hash           string        `json:"hashString"`
}

Torrent struct for torrents

func (*Torrent) ETA

func (t *Torrent) ETA() string

ETA returns the time left for the download to finish

func (*Torrent) GetTrackers

func (t *Torrent) GetTrackers() string

GetTrackers combines the torrent's trackers in one string

func (*Torrent) Have

func (t *Torrent) Have() uint64

Have returns haveValid + haveUnchecked

func (*Torrent) Ratio

func (t *Torrent) Ratio() string

Ratio returns the upload ratio of the torrent

type TorrentAdded

type TorrentAdded struct {
	HashString string `json:"hashString"`
	ID         int    `json:"id"`
	Name       string `json:"name"`
}

TorrentAdded data returning

type Torrents

type Torrents []*Torrent

Torrents represent []Torrent

func (Torrents) GetIDs

func (t Torrents) GetIDs() []int

GetIDs returns []int of all the ids

func (Torrents) SortAge

func (t Torrents) SortAge(reverse bool)

func (Torrents) SortDownSpeed

func (t Torrents) SortDownSpeed(reverse bool)

func (Torrents) SortDownloaded

func (t Torrents) SortDownloaded(reverse bool)

func (Torrents) SortID

func (t Torrents) SortID(reverse bool)

func (Torrents) SortName

func (t Torrents) SortName(reverse bool)

func (Torrents) SortProgress

func (t Torrents) SortProgress(reverse bool)

func (Torrents) SortRatio

func (t Torrents) SortRatio(reverse bool)

func (Torrents) SortSize

func (t Torrents) SortSize(reverse bool)

func (Torrents) SortUpSpeed

func (t Torrents) SortUpSpeed(reverse bool)

func (Torrents) SortUploaded

func (t Torrents) SortUploaded(reverse bool)

type TransmissionClient

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

TransmissionClient to talk to transmission

func New

func New(url string, username string, password string) (*TransmissionClient, error)

New create new transmission torrent

func (*TransmissionClient) Add

func (ac *TransmissionClient) Add(fn string, dndir string) (TorrentAdded, error)

func (*TransmissionClient) DeleteTorrent

func (ac *TransmissionClient) DeleteTorrent(id int, wd bool) (string, error)

Delete takes a bool, if true it will delete with data; returns the name of the deleted torrent if it succeed

func (*TransmissionClient) ExecuteAddCommand

func (ac *TransmissionClient) ExecuteAddCommand(addCmd *Command) (TorrentAdded, error)

func (*TransmissionClient) ExecuteCommand

func (ac *TransmissionClient) ExecuteCommand(cmd *Command) (*Command, error)

func (*TransmissionClient) GetStats

func (ac *TransmissionClient) GetStats() (*Stats, error)

GetStats returns "session-stats"

func (*TransmissionClient) GetTorrent

func (ac *TransmissionClient) GetTorrent(id int) (*Torrent, error)

GetTorrent takes an id and returns *Torrent

func (*TransmissionClient) GetTorrents

func (ac *TransmissionClient) GetTorrents() (Torrents, error)

GetTorrents get a list of torrents

func (*TransmissionClient) Rename

func (ac *TransmissionClient) Rename(id int, sn, dn string) (resp Command, err error)

func (*TransmissionClient) SetSort

func (ac *TransmissionClient) SetSort(st Sorting)

SetSort takes a 'Sorting' to set 'sortType'

func (*TransmissionClient) StartAll

func (ac *TransmissionClient) StartAll() error

StartAll starts all the torrents

func (*TransmissionClient) StartTorrent

func (ac *TransmissionClient) StartTorrent(id int) (string, error)

StartTorrent start the torrent

func (*TransmissionClient) StopAll

func (ac *TransmissionClient) StopAll() error

StopAll stops all torrents

func (*TransmissionClient) StopTorrent

func (ac *TransmissionClient) StopTorrent(id int) (string, error)

StopTorrent start the torrent

func (*TransmissionClient) VerifyAll

func (ac *TransmissionClient) VerifyAll() error

VerifyAll verfies all torrents

func (*TransmissionClient) VerifyTorrent

func (ac *TransmissionClient) VerifyTorrent(id int) (string, error)

VerifyTorrent verifies a torrent

func (*TransmissionClient) Version

func (ac *TransmissionClient) Version() string

Version returns transmission's version

Jump to

Keyboard shortcuts

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