0.9.6 - Android
parent
7557ed8223
commit
c594801130
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<addon id="script.module.pyrrent2http" name="pyrrent2http" version="0.9.5" provider-name="inpos">
|
||||
<addon id="script.module.pyrrent2http" name="pyrrent2http" version="0.9.6" provider-name="inpos">
|
||||
<requires>
|
||||
<import addon="xbmc.python" version="2.14.0"/>
|
||||
<import addon="script.module.libtorrent" />
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import os, sys
|
||||
import chardet
|
||||
|
||||
try:
|
||||
|
@ -26,6 +26,17 @@ import io
|
|||
from util import localize_path, Struct, detect_media_type, uri2path, encode_msg
|
||||
|
||||
|
||||
|
||||
if os.getenv('ANDROID_ROOT'):
|
||||
from ctypes import *
|
||||
libc = CDLL('/system/lib/libc.so')
|
||||
libc.lseek64.restype = c_ulonglong
|
||||
libc.lseek64.argtypes = [c_uint, c_ulonglong, c_uint]
|
||||
libc.read.restype = c_long
|
||||
libc.read.argtypes = [c_uint, c_void_p, c_long]
|
||||
O_RDONLY = 0
|
||||
O_LARGEFILE = 0x8000
|
||||
|
||||
######################################################################################
|
||||
|
||||
if not hasattr(os, 'getppid'):
|
||||
|
@ -165,6 +176,9 @@ class TorrentFile(object):
|
|||
logging.info('Waiting for file: %s' % (self.save_path,))
|
||||
self.tfs.handle.flush_cache()
|
||||
time.sleep(0.5)
|
||||
if os.getenv('ANDROID_ROOT'):
|
||||
self.filePtr = libc.open(self.save_path, O_RDONLY | O_LARGEFILE, 755)
|
||||
else:
|
||||
self.filePtr = io.open(self.save_path, 'rb')
|
||||
return self.filePtr
|
||||
def log(self, message):
|
||||
|
@ -177,6 +191,9 @@ class TorrentFile(object):
|
|||
def SetPriority(self, priority):
|
||||
self.tfs.setPriority(self.index, priority)
|
||||
def readOffset(self):
|
||||
if os.getenv('ANDROID_ROOT'):
|
||||
return libc.lseek64(self.filePtr, 0, os.SEEK_CUR)
|
||||
else:
|
||||
return self.filePtr.seek(0, os.SEEK_CUR)
|
||||
def havePiece(self, piece):
|
||||
return self.tfs.handle.have_piece(piece)
|
||||
|
@ -210,6 +227,9 @@ class TorrentFile(object):
|
|||
self.tfs.removeOpenedFile(self)
|
||||
self.closed = True
|
||||
if self.filePtr is not None:
|
||||
if os.getenv('ANDROID_ROOT'):
|
||||
libc.close(self.filePtr)
|
||||
else:
|
||||
self.filePtr.close()
|
||||
self.filePtr = None
|
||||
def ShowPieces(self):
|
||||
|
@ -234,6 +254,9 @@ class TorrentFile(object):
|
|||
for i in range(startPiece, endPiece + 1):
|
||||
if not self.waitForPiece(i):
|
||||
raise IOError
|
||||
if os.getenv('ANDROID_ROOT'):
|
||||
read = libc.read(self.filePtr, addressof(buf), toRead)
|
||||
else:
|
||||
read = filePtr.readinto(buf)
|
||||
return read
|
||||
def Seek(self, offset, whence):
|
||||
|
@ -242,6 +265,9 @@ class TorrentFile(object):
|
|||
if whence == os.SEEK_END:
|
||||
offset = self.size - offset
|
||||
whence = os.SEEK_SET
|
||||
if os.getenv('ANDROID_ROOT'):
|
||||
newOffset = libc.lseek64(self.filePtr, offset, whence)
|
||||
else:
|
||||
newOffset = filePtr.seek(offset, whence)
|
||||
self.log('Seeking to %d/%d' % (newOffset, self.size))
|
||||
return newOffset
|
||||
|
@ -405,16 +431,25 @@ def HttpHandlerFactory():
|
|||
f.Seek(start_range, 0)
|
||||
chunk = f.piece_length
|
||||
total = 0
|
||||
if os.getenv('ANDROID_ROOT'):
|
||||
buf = create_string_buffer(chunk)
|
||||
else:
|
||||
buf = bytearray(chunk)
|
||||
while chunk > 0:
|
||||
if start_range + chunk > end_range:
|
||||
chunk = end_range - start_range
|
||||
if os.getenv('ANDROID_ROOT'):
|
||||
buf = create_string_buffer(chunk)
|
||||
else:
|
||||
buf = bytearray(chunk)
|
||||
try:
|
||||
if f.Read(buf) < 1: break
|
||||
while self.server.root_obj.pause:
|
||||
time.sleep(0.1)
|
||||
continue
|
||||
if os.getenv('ANDROID_ROOT'):
|
||||
self.wfile.write(buf.raw)
|
||||
else:
|
||||
self.wfile.write(buf)
|
||||
except:
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue