Updated README.md

sandbox1
Anton Argirov 2015-02-06 12:59:04 +06:00
parent 8c8944b822
commit 56e97e1f46
1 changed files with 81 additions and 77 deletions

View File

@ -17,15 +17,16 @@ Usage
Getting list of files inside torrent is straightforward:
import xbmc
from torrent2http import State, Engine, MediaType
from contextlib import closing
```python
import xbmc
from torrent2http import State, Engine, MediaType
from contextlib import closing
# Create instance of Engine
engine = Engine(uri="...")
files = []
# Ensure we'll close engine on exception
with closing(engine):
# Create instance of Engine
engine = Engine(uri="...")
files = []
# Ensure we'll close engine on exception
with closing(engine):
# Start engine
engine.start()
# Wait until files received
@ -35,25 +36,27 @@ Getting list of files inside torrent is straightforward:
# Check if there is loading torrent error and raise exception
engine.check_torrent_error()
xbmc.sleep(200)
```
### Start streaming ###
import xbmc
from torrent2http import State, Engine, MediaType
from contextlib import closing
```python
import xbmc
from torrent2http import State, Engine, MediaType
from contextlib import closing
# XBMC addon handle
handle = ...
# Playable list item
listitem = ...
# We can know file_id of needed video file on this step, if no, we'll try to detect one.
file_id = None
# Flag will set to True when engine is ready to resolve URL to XBMC
ready = False
# Set pre-buffer size to 15Mb. This is a size of file that need to be downloaded before we resolve URL to XMBC
pre_buffer_bytes = 15*1024*1024
engine = Engine(uri="...")
with closing(engine):
# XBMC addon handle
handle = ...
# Playable list item
listitem = ...
# We can know file_id of needed video file on this step, if no, we'll try to detect one.
file_id = None
# Flag will set to True when engine is ready to resolve URL to XBMC
ready = False
# Set pre-buffer size to 15Mb. This is a size of file that need to be downloaded before we resolve URL to XMBC
pre_buffer_bytes = 15*1024*1024
engine = Engine(uri="...")
with closing(engine):
# Start engine and instruct torrent2http to begin download first file,
# so it can start searching and connecting to peers
engine.start(file_id or 0)
@ -101,6 +104,7 @@ Getting list of files inside torrent is straightforward:
# Wait until playing finished or abort requested
while not xbmc.abortRequested and xbmc.Player().isPlaying():
xbmc.sleep(500)
```
### Fully working example ###