transmission

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

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

Go to latest
Published: Jul 11, 2017 License: MIT Imports: 6 Imported by: 1

README

Go Transmission

Golang lib for Transmission API

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

import (
	"log"

	"github.com/tubbebubbe/transmission"
)

func main() {
	client := transmission.New("http://127.0.0.1:9091", "", "")

	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

View Source
const (
	StatusPaused       = 0
	StatusWait         = 1
	StatusCheck        = 2
	StatusDownloadWait = 3
	StatusDownload     = 4
	StatisSeedWait     = 5
	StatusSeed         = 6
)

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 string,
	username string, 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, error)

func NewAddCmdByFile

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

func NewAddCmdByFilename

func NewAddCmdByFilename(filename string) (*Command, error)

func NewAddCmdByMagnet

func NewAddCmdByMagnet(magnetLink string) (*Command, error)

func NewAddCmdByURL

func NewAddCmdByURL(url string) (*Command, error)

func NewDelCmd

func NewDelCmd(id int, removeFile bool) (*Command, error)

func NewGetTorrentsCmd

func NewGetTorrentsCmd() (*Command, error)

func (*Command) SetDownloadDir

func (cmd *Command) SetDownloadDir(dir string)

type Torrent

type Torrent struct {
	ID            int     `json:"id"`
	Name          string  `json:"name"`
	Status        int     `json:"status"`
	AddedDate     int     `json:"addedDate"`
	LeftUntilDone int     `json:"leftUntilDone"`
	Eta           int     `json:"eta"`
	UploadRatio   float64 `json:"uploadRatio"`
	RateDownload  int     `json:"rateDownload"`
	RateUpload    int     `json:"rateUpload"`
	DownloadDir   string  `json:"downloadDir"`
	IsFinished    bool    `json:"isFinished"`
	PercentDone   float64 `json:"percentDone"`
	SeedRatioMode int     `json:"seedRatioMode"`
	HashString    string  `json:"hashString"`
	Error         int     `json:"error"`
	ErrorString   string  `json:"errorString"`
}

Torrent struct for torrents

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) SortByAddedDate

func (t Torrents) SortByAddedDate(reverse bool)

func (Torrents) SortByID

func (t Torrents) SortByID(reverse bool)

methods of 'Torrents' to sort by ID, Name or AddedDate

func (Torrents) SortByName

func (t Torrents) SortByName(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

New create new transmission torrent

func (*TransmissionClient) ExecuteAddCommand

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

func (*TransmissionClient) ExecuteCommand

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

func (*TransmissionClient) GetTorrents

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

GetTorrents get a list of torrents

func (*TransmissionClient) StartTorrent

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

StartTorrent start the torrent

func (*TransmissionClient) StopTorrent

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

StopTorrent start the torrent

Jump to

Keyboard shortcuts

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