From 3417b109eca5c2685dd56ceddefc65412382cfb5 Mon Sep 17 00:00:00 2001 From: Anders Jensen Date: Sat, 25 Aug 2018 10:20:20 +0200 Subject: [PATCH 1/4] Added example --- examples/cli-stream/README.md | 23 +++++++++++++++++++++++ examples/cli-stream/stream-cli.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 examples/cli-stream/README.md create mode 100644 examples/cli-stream/stream-cli.py diff --git a/examples/cli-stream/README.md b/examples/cli-stream/README.md new file mode 100644 index 0000000..c60b1b8 --- /dev/null +++ b/examples/cli-stream/README.md @@ -0,0 +1,23 @@ +# Commandline Tool to stream + +Stream from the commandline. + +## Requirements + +* Python +* deluge_client python package + +## Installation example + +```bash +virtualenv cli-example +cli-example/bin/pip install deluge_client +``` + +## Usage + +Open a torrent directly in VLC on Linux or OSX. + +```bash +vlc `cli-example/bin/python stream-cli.py username password my_video.torrent` +``` \ No newline at end of file diff --git a/examples/cli-stream/stream-cli.py b/examples/cli-stream/stream-cli.py new file mode 100644 index 0000000..be82c59 --- /dev/null +++ b/examples/cli-stream/stream-cli.py @@ -0,0 +1,28 @@ +import argparse +import urllib + +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_or_url', type=str, help='Path or URL to torrent') + + parser.add_argument('--hostname', '-o', type=str, default='localhost', help='Deluge daemon hostname or ip') + parser.add_argument('--port', '-p', type=int, default=58846, help='Deluge daemon port') + + args = parser.parse_args() + + if args.path_or_url.startswith('http'): + filedata = urllib.urlopen(args.path_or_url).read() + else: + with open(args.path_or_url, 'rb') as f: + filedata = f.read() + + client = DelugeRPCClient(args.hostname, args.port, args.username, args.password) + client.connect() + + result = client.streaming.stream_torrent(None, None, filedata, None, None, True) + print(result['url']) From 015a7cbc7acb47047e689f3949f58737af81249d Mon Sep 17 00:00:00 2001 From: Anders Jensen Date: Sat, 25 Aug 2018 17:53:55 +0200 Subject: [PATCH 2/4] added buffer buster and some wrong math --- streaming/core.py | 2 +- streaming/torrentfile.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/streaming/core.py b/streaming/core.py index 8ef7b59..40e48a8 100644 --- a/streaming/core.py +++ b/streaming/core.py @@ -182,7 +182,7 @@ class Torrent(object): logger.debug('Calling read again to get the real number') return self.can_read(from_byte) else: - return ((last_available_piece - needed_piece) * self.piece_length) + rest + self.piece_length + return ((last_available_piece - needed_piece) * self.piece_length) + self.piece_length - rest def is_idle(self): return not self.readers and self.last_activity + TORRENT_CLEANUP_INTERVAL < datetime.now() diff --git a/streaming/torrentfile.py b/streaming/torrentfile.py index 6429612..ee3b103 100644 --- a/streaming/torrentfile.py +++ b/streaming/torrentfile.py @@ -50,6 +50,9 @@ class DelugeTorrentInput(InputBase.find_plugin('file')): if self.can_read_to <= tell or self.can_read_to is None: self.can_read_to = self.torrent.can_read(self.offset + tell) + tell + if self._open_file: + self._open_file.seek(tell) + real_num = min(num, self.can_read_to - tell) if num != real_num: logger.info('The real number we can read to is %s and not %s at position %s' % (real_num, num, tell)) From 21f1d775685658e6718af7ce9f0e00ae7307b728 Mon Sep 17 00:00:00 2001 From: Anders Jensen Date: Sat, 25 Aug 2018 18:03:30 +0200 Subject: [PATCH 3/4] ensuring torrent is added fully before streaming --- streaming/core.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/streaming/core.py b/streaming/core.py index 40e48a8..25dc766 100644 --- a/streaming/core.py +++ b/streaming/core.py @@ -391,8 +391,7 @@ class TorrentHandler(object): def get_filesystem(self, infohash): torrent = get_torrent(infohash) - status = torrent.get_status(['piece_length', 'files', 'file_progress', 'save_path']) - self.piece_length = status['piece_length'] + status = torrent.get_status(['files', 'file_progress', 'save_path']) save_path = status['save_path'] found_rar = False @@ -456,9 +455,16 @@ class TorrentHandler(object): @defer.inlineCallbacks def stream(self, infohash, path, wait_for_end_pieces=False): logger.debug('Trying to get path:%s from infohash:%s' % (path, infohash)) - local_torrent = self.get_torrent(infohash) torrent = get_torrent(infohash) + for _ in range(10): + status = torrent.get_status(['piece_length']) + if status['piece_length'] > 0: + break + yield sleep(0.2) + + local_torrent = self.get_torrent(infohash) + filesystem = self.get_filesystem(infohash) if path: stream_item = filesystem.get_item_from_path(path) From 73ddeb021cc0d08e217e84186e01177a0f51e175 Mon Sep 17 00:00:00 2001 From: Anders Jensen Date: Sat, 25 Aug 2018 18:05:12 +0200 Subject: [PATCH 4/4] bumped version --- README.md | 4 ++++ setup.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 910f18a..98d7b86 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,10 @@ The _allow remote_ option is to allow remote add and stream of torrents. # Version Info +## Version 0.10.2 +* Busting cache when waiting for piece +* Math error in calculating size of readable bytes + ## Version 0.10.1 * Small bugfixes related to priorities, should actually make sequential download work. diff --git a/setup.py b/setup.py index 7be06e8..f6f16cf 100644 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ from setuptools import setup, find_packages __plugin_name__ = "Streaming" __author__ = "Anders Jensen" __author_email__ = "johndoee@tidalstream.org" -__version__ = "0.10.1" +__version__ = "0.10.2" __url__ = "https://github.com/JohnDoee/deluge-streaming" __license__ = "GPLv3" __description__ = "Enables streaming of files while downloading them."