func (c *Client) GetTorrentMap() (TorrentMap, error) {
	torrents, err := c.GetTorrents()
	if err != nil {
		return nil, err
	}
	tm := make(TorrentMap)
	for _, t := range torrents {
		tm[t.HashString] = t
	}
	return tm, nil
}
GetTorrentMap returns a map of torrents indexed by torrent hash.
package transmission
import (
	"bytes"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
)
var (
	ErrDuplicateTorrent = errors.New("Torrent already added")
)
type Config struct {
	Address  string
	User     string
	Password string
	HTTPClient *http.Client
}
type Client struct {
	Session   *Session
	sessionID string
	*Config
}
type AddTorrentArg struct {
	Cookies string `json:"cookies,omitempty"`
	DownloadDir string `json:"download-dir,omitempty"`
	Filename string `json:"filename,omitempty"`
	Metainfo string `json:"metainfo,omitempty"`
	Paused bool `json:"paused,omitempty"`
	PeerLimit int `json:"peer-limit,omitempty"`
	BandwidthPriority int   `json:",omitempty"`
	FilesWanted       []int `json:"files-wanted,omitempty"`
	FilesUnwanted     []int `json:"files-unwanted,omitempty"`
	PriorityHigh      []int `json:"priority-high,omitempty"`
	PriorityLow       []int `json:"priority-low,omitempty"`
	PriorityNormal    []int `json:"priority-normal,omitempty"`
}
type Request struct {
	Method    string      `json:"method"`
	Arguments interface{} `json:"arguments"`
}
type Response struct {
	Arguments interface{} `json:"arguments"`
	Result    string      `json:"result"`
}
func (c *Client) Do(req *http.Request, retry bool) (*http.Response, error) {
	if c.User != "" || c.Password != "" {
		req.SetBasicAuth(c.User, c.Password)
	}
	if c.sessionID != "" {
		req.Header.Del("X-Transmission-Session-Id")
		req.Header.Add("X-Transmission-Session-Id", c.sessionID)
	}
	b, err := ioutil.ReadAll(req.Body)
	if err != nil {
		return nil, err
	}
	req.Body.Close()
	req.Body = ioutil.NopCloser(bytes.NewBuffer(b))
	resp, err := c.HTTPClient.Do(req)
	if err != nil {
		return nil, err
	}
	if resp.StatusCode == http.StatusConflict && retry {
		c.sessionID = resp.Header.Get("X-Transmission-Session-Id")
		req.Body = ioutil.NopCloser(bytes.NewBuffer(b))
		io.Copy(ioutil.Discard, resp.Body)
		resp.Body.Close()
		return c.Do(req, false)
	}
	return resp, nil
}
func (c *Client) request(tReq *Request, tResp *Response) error {
	data, err := json.Marshal(tReq)
	if err != nil {
		return err
	}
	req, err := http.NewRequest("POST", c.Address, bytes.NewReader(data))
	if err != nil {
		return err
	}
	resp, err := c.Do(req, true)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	if resp.StatusCode < 200 || resp.StatusCode > 299 {
		return fmt.Errorf("got http error %s", resp.Status)
	}
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	err = json.Unmarshal(body, tResp)
	if err != nil {
		return err
	}
	if tResp.Result != "success" {
		return fmt.Errorf("transmission: request response %q", tResp.Result)
	}
	return nil
}
func (c *Client) GetTorrents() ([]*Torrent, error) {
	type arg struct {
		Fields []string `json:"fields,omitempty"`
		Ids    []int    `json:"ids,omitempty"`
	}
	tReq := &Request{
		Arguments: arg{
			Fields: torrentGetFields,
		},
		Method: "torrent-get",
	}
	r := &Response{Arguments: &Torrents{}}
	err := c.request(tReq, r)
	if err != nil {
		return nil, err
	}
	t := r.Arguments.(*Torrents).Torrents
	for i := range t {
		t[i].Client = c
	}
	return t, nil
}