[go: up one dir, main page]

Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

mfuentesg/transmission

Repository files navigation

transmission

This repository it's a wrapper for transmission RPC API.

Available methods

  • torrent-start
  • torrent-start-now
  • torrent-stop
  • torrent-verify
  • torrent-reannounce
  • torrent-set
  • torrent-get
  • torrent-add
  • torrent-remove
  • torrent-set-location
  • torrent-rename-path
  • session-close
  • session-get
  • session-set
  • session-stats
  • queue-move-top
  • queue-move-up
  • queue-move-down
  • queue-move-bottom
  • free-space
  • port-test
  • blocklist-update

For more information read spec file.

Installation

go get -u github.com/mfuentesg/transmission

Examples

Check connectivity with transmission service

package main

import (
    "context"
    "log"

    "github.com/mfuentesg/transmission"
)

func main() {
    client := transmission.New(
	transmission.WithURL("http://service-url.com/tranmission/rpc"),
	transmission.WithBasicAuth("username", "password"),
    )

    // this method is not part of the spec (it just check connectivity)
    if err := client.Ping(context.Background()); err != nil {
        log.Fatalf("could not connect to transmission service: %+v", err)
    }

    log.Println("connected to the transmission service")
}

Get list of torrents

package main

import (
    "context"
    "fmt"
    "log"

    "github.com/mfuentesg/transmission"
)

func main() {
    client := transmission.New(
        transmission.WithURL("http://service-url.com/tranmission/rpc"),
	transmission.WithBasicAuth("username", "password"),
    )

    // get list of torrents
    // For know more about the available fields, take a look to the below link
    // https://github.com/transmission/transmission/blob/20119f006ca0f3a13245b379c74254c92f372910/extras/rpc-spec.txt#L111
    torrents, err := client.TorrentGet(context.Background(), transmission.TorrentGet{
        Ids: 17, // search by id, you can use hashString as well
        Fields: []string{"id", "hashString"},
    })

    if err != nil {
        log.Fatalf("could not get torrent list: %+v", err)
    }

    for _, torrent := range torrents {
    	fmt.Printf("torrent with id %d and hashString %s\n", torrent.ID, torrent.HashString)
    }
}

TODO

  • Improve README file
  • Add documentation to each function and reference to transmission fields