utorrent

package module
v0.0.0-...-709a04e Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2018 License: MIT Imports: 12 Imported by: 0

README

go-utorrent

A lightweight uTorrent library for Go

Example

package main

import (
	"fmt"
	"os"

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

func main() {
	c, err := utorrent.NewClient(&utorrent.Client{
		API:      "http://localhost:8085/gui",
		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

This section is empty.

Functions

This section is empty.

Types

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 uTorrent/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) SetTorrentProperty

func (c *Client) SetTorrentProperty(hash string, property string, value string) error

SetTorrentProperty sets a property 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 Torrent

type Torrent struct {
	Hash            string `json:"hash"`
	StatusCode      int    `json:"status_code"`
	Name            string `json:"name"`
	Size            int    `json:"size"`
	PercentProgress int    `json:"percent_progress"`
	Downloaded      int    `json:"downloaded"`
	Uploaded        int    `json:"uploaded"`
	Ratio           int    `json:"ratio"`
	UploadSpeed     int    `json:"upload_speed"`
	DownloadSpeed   int    `json:"download_speed"`
	ETA             int    `json:"eta"`
	Label           string `json:"label"`
	PeersConnected  int    `json:"peers_connected"`
	PeersTotal      int    `json:"peers_total"`
	SeedsConnected  int    `json:"seeds_connected"`
	SeedsTotal      int    `json:"seeds_total"`
	Availability    int    `json:"availability"`
	QueueOrder      int    `json:"queue_order"`
	Remaining       int    `json:"remaining"`
	Status          string `json:"status"`
	AddedOn         int    `json:"added_on"`
	CompletedOn     int    `json:"completed_on"`
	FilePath        string `json:"filepath"`
}

type TorrentList

type TorrentList struct {
	Build        int             `json:"build"`
	RawTorrents  [][]interface{} `json:"torrents"`
	Torrents     []Torrent
	TorrentCache string `json:"torrentc"`
}

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

func (*TorrentList) UnmarshalJSON

func (torrents *TorrentList) 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

Jump to

Keyboard shortcuts

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