JohnDoee / deluge-streaming

Streaming plugin for deluge, making it possible to read torrents and download required parts on-demand.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

deluge-console support

wjtk4444 opened this issue · comments

I don't know if it's technically possible to do via deluge plugin system, but I'd like to see an option to start streaming a torrent using deluge-console. For example:

deluge-console --add path/to/my.torrent --start-streaming
Url to stream: http://127.0.0.1:12345/streaming/file/myFile.mkv
deluge-console --start-streaming torrent-id
Url to stream: http://127.0.0.1:12345/streaming/file/myFile.mkv

As far as I remember, you can't modify the deluge-console interface via plugins.

BUT, doing that is a ~10 line Python script or you can use the built-in HTTP API (known as remote control in settings). The HTTP API can probably be done with something like curl.

I'd be happy to whip up an example for any of those.

Such script would be a really nice addition to this plugin, the more automation the better. I'm currently working on a mpv script that allows user to open a torrent file/link from clipboard, starts sequential download using deluge daemon and plays the file. I'd like to use your plugin instead of sequential download as it's definitely a better option for streaming torrents, but I can't see a way to communicate with it from lua script.

I believe that a solution made in python would be better, as it would allow me to make my script work on all platforms with python installed. I believe that curl isn't available,on windows, at least not without some nasty hacks.

Make a virtual environment and install dependency

virtualenv venv
venv/bin/pip install deluge-client

Create your simple script

import argparse

from deluge_client import DelugeRPCClient

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Stream something.')
    parser.add_argument('username', type=str, help='Deluge username')
    parser.add_argument('password', type=str, help='Deluge password')
    parser.add_argument('path', type=str, help='Path to torrent')

    args = parser.parse_args()

    with open(args.path, 'rb') as f:
        filedata = f.read()

    client = DelugeRPCClient('127.0.0.1', 58846, args.username, args.password)
    client.connect()

    result = client.streaming.stream_torrent(None, None, filedata, None, None, True)
    print(result['url'])

You can bundle deluge-client with your project when you distribute it simply by putting the python library in the same folder.

Logic to automatically find Deluge Daemon connection information can be found here: https://github.com/JohnDoee/autotorrent/blob/develop/autotorrent/clients/deluge.py#L55-L98

Cool, thanks. That's exactly what I wanted to add, but I had no idea how to make deluge take both urls and files as an argument.

filedata = urllib.urlopen(args.path_or_url).read()

I think that the issue can be closed now, but I'll leave the decision up to you.

If you're happy, I'm happy !

One more question regarding the case: How would one go about passing a magnet link as an argument? It's neither a file or an url. I mean, it technically is an url, but not for Python's urllib at least.
I tried to add another case, but it doesn't seem to work.

elif args.path_or_url.startswith('magnet:'):
    filedata = args.path_or_url

The plugin doesn't support magnet links, at least not yet. Feel free to open a ticket about it.

To add a bit to this, the benefit of this client versus the 100 others (like the one used in popcorn time or by kodi-elementum) is that it is can be used on private tracker.

That's also why I added multi-rar streaming support.

Just to clarify things - is it your plugin or the deluge-client python package that doesn't support magnet urls? I find it weird either way, deluge itself and deluge-console seems to support everything out of the box.

The streaming plugin doesn't support adding them because it has an additional step, wait for Deluge to download the .torrent file.