Skip to content

Commit

Permalink
Merge branch 'release/0.10.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Anders Jensen committed Aug 25, 2018
2 parents bfe0f9f + 73ddeb0 commit 86c6b0d
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
23 changes: 23 additions & 0 deletions examples/cli-stream/README.md
Original file line number Diff line number Diff line change
@@ -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`
```
28 changes: 28 additions & 0 deletions examples/cli-stream/stream-cli.py
Original file line number Diff line number Diff line change
@@ -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'])
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
__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."
Expand Down
14 changes: 10 additions & 4 deletions streaming/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def can_read(self, from_byte):
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()
Expand Down Expand Up @@ -391,8 +391,7 @@ def shutdown(self):

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
Expand Down Expand Up @@ -456,9 +455,16 @@ def get_torrent(self, infohash):
@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)
Expand Down
3 changes: 3 additions & 0 deletions streaming/torrentfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def read(self, num):
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))
Expand Down

0 comments on commit 86c6b0d

Please sign in to comment.