Code Monkey home page Code Monkey logo

go-libdeluge's Introduction

go-libdeluge

Go library for native RPC connection to a Deluge daemon; it uses go-rencode for the RPC protocol serialization/deserialization.

Release blog post.

License

GNU GPL version 2

How to build

This project uses Go modules. You can build it with make:

make

How to use

The library by itself is a Go package and needs to be embedded in an UI or CLI application.

	// you can use NewV1 to create a client for Deluge v1.3
	deluge := delugeclient.NewV2(delugeclient.Settings{
		Hostname:              "localhost",
		Port:                  58846,
		Login:                 "localclient",
		Password:              "*************",
	})

	// perform connection to Deluge server
	err := deluge.Connect()

	// ... use the client methods

To debug the library you may want to set DebugServerResponses to true.

Example CLI application

An example CLI application is available through:

go get github.com/gdm85/go-libdeluge/delugecli

Example usage:

DELUGE_PASSWORD="mypassword" bin/delugecli -add magnet:?xt=urn:btih:C1939CA413B9AFCC34EA0CF3C128574E93FF6CB0&tr=http%3A%2F%2Ftorrent.ubuntu.com%3A6969%2Fannounce

This will start downloading the latest Ubuntu 14.04 LTS server ISO. Multiple magnet URIs are supported as command-line arguments; run bin/delugecli alone to see all available options and their description.

Supported deluge versions

Both deluge v2.0+ and v1.3+ are supported with the two different constructors NewV2 and NewV1.

RPC API supported methods

  • daemon.login
  • daemon.info
  • daemon.authorized_call
  • daemon.get_method_list
  • daemon.get_version
  • daemon.shutdown
  • core.add_torrent_file
  • core.add_torrent_file_async
  • core.add_torrent_files
  • core.add_torrent_magnet
  • core.add_torrent_url
  • core.connect_peer
  • core.create_account
  • core.create_torrent
  • core.disable_plugin
  • core.enable_plugin
  • core.force_reannounce
  • core.force_recheck
  • core.get_auth_levels_mappings
  • core.get_available_plugins
  • core.get_completion_paths
  • core.get_config
  • core.get_config_value
  • core.get_config_values
  • core.get_enabled_plugins
  • core.get_external_ip
  • core.get_filter_tree
  • core.get_free_space
  • core.get_known_accounts
  • core.get_libtorrent_version
  • core.get_listen_port
  • core.get_path_size
  • core.get_proxy
  • core.get_session_state
  • core.get_session_status
  • core.get_torrent_status
  • core.get_torrents_status
  • core.glob
  • core.is_session_paused
  • core.move_storage
  • core.pause_session
  • core.pause_torrent
  • core.pause_torrents
  • core.prefetch_magnet_metadata
  • core.queue_bottom
  • core.queue_down
  • core.queue_top
  • core.queue_up
  • core.remove_account
  • core.remove_torrent
  • core.remove_torrents
  • core.rename_files
  • core.rename_folder
  • core.rescan_plugins
  • core.resume_session
  • core.resume_torrent
  • core.resume_torrents
  • core.set_config
  • core.set_torrent_options
  • core.set_torrent_trackers
  • core.test_listen_port
  • core.update_account
  • core.upload_plugin

Plugins

Plugins can be used by calling the relative method and checking if the result is not nil, example:

	p, err := deluge.LabelPlugin()
	if err != nil {
		panic(err)
	}
	if p == nil {
		println("Label plugin not available")
		return
	}

	// call plugin methods
	labelsByTorrent, err := p.GetTorrentsLabels(delugeclient.StateUnspecified, nil)

Label

RPC API supported methods

  • label.add
  • label.get_config
  • label.get_labels
  • label.get_options
  • label.remove
  • label.set_config
  • label.set_options
  • label.set_torrent

go-libdeluge's People

Contributors

ailox avatar gdm85 avatar jasonrhansen avatar josiahwhite avatar kslr avatar l3uddz avatar liut avatar relvacode avatar sgtsquiggs avatar xanarin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

go-libdeluge's Issues

Proposal: Convert to native go datatypes

This library is acting as a way of interfacing go with deluge, and is doing a fantastic job.
I was thinking that it would be nice to automatically convert some of the values into something more usable, therefore I'd like to propose the following type changes for attributes of the TorrentStatus:

  • ActiveTime: int64 → time.Duration
  • AddedTime: float32 → time.Time
  • CompletedTime: int64 → time.Time
  • ETA: int64 → time.Duration
  • NextAnnounce: int64 → time.Duration
  • SeedingTime: int64 → time.Duration
  • State: string → enum

For Peer:

  • Seed: int64 → bool

and (optionally), since they don't really need to be int64:

  • NumSeeds: int64 → int
  • NumPeers: int64 → int
  • NumPieces: int64 → int
  • TotalPeers: int64 → int
  • TotalSeeds: int64 → int
  • File.Index: int64 → int

(PieceLength also falls in that category, but since it is given in bytes it is probably more idiomatic to keep it int64)

Since this is a greater breaking change, and it might (depending on implementation) require modifications to the gdm85/rencode project, I wanted to ask for your opinion about this first. Do you think it is worth it to abstract the API to be more "friendly", or should go-libdeluge stay a slim wrapper around the RPC methods?

Save Path not working w/ Deluge v1

hi there - thank you for this library 😺.

We're using options.DownloadLocation to set the save path, however a multitude of users (mostly on Discord) have reported this doesn't actually set the path for them with Deluge v1 (works w/ v2). Are you seeing the same thing?

Here's where we run the client:
https://github.com/autobrr/autobrr/blob/ca196f0bf1a83d4ec5edc1006c982ca0fcaa7490/internal/action/deluge.go#L89

and the variable set:
https://github.com/autobrr/autobrr/blob/ca196f0bf1a83d4ec5edc1006c982ca0fcaa7490/internal/action/deluge.go#L316

Here's the user report: autobrr/autobrr#727

core.pause_torrent fails on 1.3.15

See below log message:

[2020-04-18T19:22:25+02:00]  INFO manage        : Hard removing: "xxxxxxxxxxxxxxxxx.mkv" - 3.4 GiB - 0.00 GB
[2020-04-18T19:22:25+02:00]  INFO manage        : Ratio: 1.801 / Seed days: 1.256 / Seeds: 76 / Label: sonarrimported / Tracker: XXXXX / Tracker Status: "XXXXX: Announce OK"
[2020-04-18T19:22:25+02:00] FATAL manage        : Failed removing torrent: {Hash:da8a43ece27548933d533a32af786bb81a4079e7 Name:xxxxxxxxxxxxxx.mkv Path: TotalBytes:3675936559 DownloadedBytes:3675936559 State:Seeding Files:[xxxxxxxxxxxxxx.mkv] Downloaded:true Seeding:true Ratio:1.8010296 AddedSeconds:110685 AddedHours:30.745832 AddedDays:1.2810763 SeedingSeconds:108522 SeedingHours:30.144999 SeedingDays:1.2560416 Label:sonarrimported Seeds:76 Peers:0 FreeSpaceGB:0x925c40 FreeSpaceSet:true TrackerName:XXXXX TrackerStatus:XXXXX: Announce OK} error=RPC error KeyError('d')
Traceback:   File "/usr/lib/python2.7/dist-packages/deluge/core/rpcserver.py", line 301, in dispatch
    ret = self.factory.methods[method](*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/deluge/core/core.py", line 403, in pause_torrent
    if not self.torrentmanager[torrent_id].pause():
  File "/usr/lib/python2.7/dist-packages/deluge/core/torrentmanager.py", line 287, in __getitem__
    return self.torrents[torrent_id]

failed pausing torrent: "da8a43ece27548933d533a32af786bb81a4079e7"
github.com/l3uddz/tqm/client.(*Deluge).RemoveTorrent
        github.com/l3uddz/tqm/client/deluge.go:211
github.com/l3uddz/tqm/cmd.removeEligibleTorrents
        github.com/l3uddz/tqm/cmd/helpers.go:77
github.com/l3uddz/tqm/cmd.glob..func1
        github.com/l3uddz/tqm/cmd/manage.go:97
github.com/spf13/cobra.(*Command).execute
        github.com/spf13/[email protected]/command.go:846
github.com/spf13/cobra.(*Command).ExecuteC
        github.com/spf13/[email protected]/command.go:950
github.com/spf13/cobra.(*Command).Execute
        github.com/spf13/[email protected]/command.go:887
github.com/l3uddz/tqm/cmd.Execute
        github.com/l3uddz/tqm/cmd/root.go:41
main.main
        github.com/l3uddz/tqm/main.go:8
runtime.main
        runtime/proc.go:203
runtime.goexit
        runtime/asm_amd64.s:1373

From the above RPC error, it would appear the full hash is not being sent.

This is on v0.5.2.

I dont have a buffer example but will try to get one if that will help.

Deluge 2.0 TorrentsStatus error

Hi,

Nice package.

I have an issue however trying to work with a V2 daemon.

The following error is being returned for the TorrentsStatus method:

strconv.Atoi: parsing "1E04.Facing.the.Hangman.1080p.NF.WEB-DL.DDP5.1.x264-NTG.mkv\x84sizeA\x00\x00\x00\x00\x9d\xa93\x0e\x86offsetA\x00\x00\x00\x01ƾ\xc9 j\x85index\x04\x84path134": invalid syntax

This only appears to happen when DebugSaveInteractions is false, if its true it works as expected.

ETA Cannot Convert

I'm using the V1 client.

2021/01/06 23:22:36 Failed to populate torrent list: field "ETA": value 3405705413: cannot convert from int64 into *float32

Add 'Darwin' Support

When this library is built on Darwin/OS X/macos, the following error occurs:

$ go build .
# github.com/gdm85/go-libdeluge
./keep_alive.go:50:89: undefined: syscall.TCP_KEEPIDLE
./keep_alive.go:54:89: undefined: syscall.TCP_KEEPCNT
./keep_alive.go:58:89: undefined: syscall.TCP_KEEPINTVL

I believe this is because these constants in the syscall package are OS-dependent, and are not exposed on the Darwin platform.

Find good structure for options type

In commit e1f610e the Options object was changed from a hashmap to a strongly typed struct. This is a change I liked, but i quickly noticed that it makes the API a little more difficult to use.
When passing options, now all values need to be defined, as their null empty values will overwrite deluge's defaults.

Ignoring the empty values is also not a solution, or the user will become unable to set values such as '0' (int) or 'false' (bool).

Adding pointers to all the attributes will make the initialization harder.

sql.NullString, sql.NullInt… could be used, but on second thought it seems a little strange to import the sql package to initialize the deluge client.

Reverting back to the hashmap will require a lot of magic strings, but will make the version handling easier to implement (since it is then left to the user to provide valid option name keys).

Original comment was here e1f610e#r36456065

Feature: Label included in the TorrentStatus struct

Hi,

Would it be possible for the torrents label to be included in the returned TorrentStatus struct?

This piece of information is vital for any applications that may be using your package to discover torrents that meet certain criteria’s.

The property was there previously, however has since been removed.

Thanks

Error parsing Deluge Output: "ETA" field

Error: field "ETA": value 3.935657e+08: cannot convert from float32 into *int64

I tried changing the type for ETA to various different things, like float64, float32, int. Nothing seems to work out. I'd like to use this as a library, but I'm not sure how to pull the torrent list. Any ideas or help is appreciated.

This is the output when trying other types:

Error: field "ETA": value 1.9893198e+08: cannot convert from float32 into *int
Error: field "ETA": value 848147.25: cannot convert from float32 into *int64
Error: field "ETA": value 0: cannot convert from int8 into *float32
Error: field "ETA": value 0: cannot convert from int8 into *float64
Error: field "ETA": value 1.1388818e+06: cannot convert from float32 into *int8

Thanks for looking!

Local daemon connections failing to establish

Hey great library!

I'm trying to connect to the daemon locally:

	deluge := delugeclient.NewV2(delugeclient.Settings{
		Hostname:             "127.0.0.1",
		Port:                 58846,
		Login:                "localclient",
		Password:             "deluge",
		DebugServerResponses: true,
	})

	// perform connection to Deluge server
	err := deluge.Connect()
	if err != nil {
		log.Fatal(err)
	}

The port is open and exposed, can confirm via lsof -i :58846.

Connection fails with no context printing EOF. I'm not sure why. I'm debugging into the connection into the code and it fails around L336 of delugeclient on this line:

_, err = c.safeConn.Write(header[:])

What am I missing?

doesn't work with Go 1.7

after upgrading to Go 1.7, running the example with DEUBG

DELUGE: delugeclient.go:245: connected to localhost:58846
DELUGE: delugeclient.go:141: flushed zlib buffer
DELUGE: delugeclient.go:152: written 42 bytes to RPC connection
ERROR: connection failed: EOF
exit status 3

running it with Go 1.6.3 works fine. so it must be something Go 1.7 introduced.

Feature: Windows support

Hi,

Is Windows support planned?

Currently, builds fail for Windows with:

⨯ release failed after 99.97s error=failed to build for windows_amd64: # github.com/gdm85/go-libdeluge


/go/pkg/mod/github.com/gdm85/[email protected]/keep_alive.go:42:11: undefined: setIdle
/go/pkg/mod/github.com/gdm85/[email protected]/keep_alive.go:46:11: undefined: setCount
/go/pkg/mod/github.com/gdm85/[email protected]/keep_alive.go:50:11: undefined: setInterval
make: *** [Makefile:85: snapshot] Error 1
ERROR: Job failed: exit code 2```

Should type of TorrentStatus.state be TorrentState instead of string?

This may be a dumb question, but I saw that you went to the trouble of defining a TorrentState type and constants for each of the possible torrent states, so I tried to do an == comparison but couldn't because TorrentStatus.State is a string and the state constants are type TorrentState. Shouldn't TorrentStatus.State be type TorrentState?

// this should work but doesn't
tors, _ := d.client.TorrentsStatus(delugeclient.StateUnspecified, nil)
if tors[0].State == delugeclient.StateSeeding {
  // seeding!
}

This works if I cast the TorrentState constant to a string ( string(delugeclient.StateSeeding) ) or cast the torrent state from string to TorrentState ( delugeclient.TorrentState(tors[0].State) ) but it seems like they should already be the same type.

Integer overflow in SessionStatus

If TotalDownload or TotalUpload is larger than int32 then calling SessionStatus fails with

field \"TotalDownload\": value 3577491204: conversion from \"int64\" to \"int32\" would overflow integer size

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.