Merge branch 'master' of

https://github.com/DiMartinoXBMC/plugin.video.torrenter

# Conflicts:
#	Anteoloader.py
sandbox1
inpos 2016-03-17 19:13:32 +03:00
commit 57a15f6822
8 changed files with 696 additions and 646 deletions

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,7 @@ import xbmcgui
import xbmcvfs
import xbmcaddon
import Localization
from functions import file_encode, isSubtitle, DownloadDB, log, debug, is_writable, unquote, file_url
from functions import localize_path, isSubtitle, is_writable, file_url
import os
@ -117,12 +117,6 @@ class AnteoLoader:
else:
self.torrentFile = torrentFile
def __exit__(self):
log('on __exit__')
if self.engine:
self.engine.close()
log('__exit__ worked!')
def setup_engine(self):
encryption = Encryption.ENABLED if self.__settings__.getSetting('encryption') == 'true' else Encryption.DISABLED
@ -163,14 +157,21 @@ class AnteoLoader:
torrent = Libtorrent(self.storageDirectory, self.torrentFile)
return torrent.getContentList()
except:
import traceback
log(traceback.format_exc())
return self.getContentList_engine()
def getContentList_engine(self):
self.setup_engine()
files = []
filelist = []
<<<<<<< HEAD
with closing(self.engine):
#self.engine.start()
=======
try:
self.engine.start()
>>>>>>> 1974c5a41ad9cbfa5eb82d5848e79387701b9c92
#media_types=[MediaType.VIDEO, MediaType.AUDIO, MediaType.SUBTITLES, MediaType.UNKNOWN]
iterator = 0
@ -198,6 +199,11 @@ class AnteoLoader:
stringdata = {"title": ensure_str(fs.name), "size": fs.size, "ind": fs.index,
'offset': fs.offset}
filelist.append(stringdata)
except:
import traceback
log(traceback.format_exc())
finally:
self.engine.close()
return filelist
def saveTorrent(self, torrentUrl):
@ -232,8 +238,6 @@ class AnteoLoader:
log('Unable to rename torrent file from %s to %s in AnteoLoader::saveTorrent. Exception: %s' %
(torrentUrl, torrentFile, str(e)))
return
#else:
#torrentFile = torrentUrl
if xbmcvfs.exists(torrentFile) and not os.path.exists(torrentFile):
if not xbmcvfs.exists(self.torrentFilesPath): xbmcvfs.mkdirs(self.torrentFilesPath)
torrentFile = os.path.join(self.torrentFilesPath, self.md5(torrentUrl) + '.torrent')
@ -263,7 +267,7 @@ class AnteoLoader:
class AnteoPlayer(xbmc.Player):
__plugin__ = sys.modules["__main__"].__plugin__
__settings__ = sys.modules["__main__"].__settings__
ROOT = sys.modules["__main__"].__root__ # .decode('utf-8').encode(sys.getfilesystemencoding())
ROOT = sys.modules["__main__"].__root__
USERAGENT = "Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0"
torrentFilesDirectory = 'torrents'
debug = __settings__.getSetting('debug') == 'true'
@ -289,10 +293,9 @@ class AnteoPlayer(xbmc.Player):
self.contentId = int(self.get("url"))
if self.get("seek"):
self.seek = int(self.get("seek"))
#self.torrent = AnteoLoader(self.userStorageDirectory, self.torrentUrl, self.torrentFilesDirectory)
self.init()
self.setup_engine()
with closing(self.engine):
try:
self.engine.start(self.contentId)
self.setup_nextep()
while True:
@ -317,6 +320,11 @@ class AnteoPlayer(xbmc.Player):
continue
log('['+author+'Player]: ************************************* NO! break')
break
except:
import traceback
log(traceback.format_exc())
finally:
self.engine.close()
xbmc.Player().stop()
@ -332,12 +340,6 @@ class AnteoPlayer(xbmc.Player):
showMessage(self.localize('Information'),
self.localize('Torrent downloading is stopped.'), forced=True)
def __exit__(self):
log('on __exit__')
if self.engine:
self.engine.close()
log('__exit__ worked!')
def init(self):
self.next_contentId = False
self.display_name = ''
@ -616,7 +618,7 @@ class AnteoPlayer(xbmc.Player):
def _get_status_lines(self, s, f):
return [
self.display_name,
localize_path(self.display_name),
"%.2f%% %s" % (f.progress * 100, self.localize(STATE_STRS[s.state]).decode('utf-8')),
"D:%.2f%s U:%.2f%s S:%d P:%d" % (s.download_rate, self.localize('kb/s').decode('utf-8'),
s.upload_rate, self.localize('kb/s').decode('utf-8'),

View File

@ -31,8 +31,8 @@ from functions import *
class Core:
__plugin__ = sys.modules["__main__"].__plugin__
__settings__ = sys.modules["__main__"].__settings__
ROOT = sys.modules["__main__"].__root__ #.decode('utf-8').encode(sys.getfilesystemencoding())
userStorageDirectory = file_encode(__settings__.getSetting("storage"))
ROOT = sys.modules["__main__"].__root__
userStorageDirectory = localize_path(__settings__.getSetting("storage"))#file_encode(__settings__.getSetting("storage"))
torrentFilesDirectory = 'torrents'
debug = __settings__.getSetting('debug') == 'true'
torrent_player = __settings__.getSetting("torrent_player")

View File

@ -31,8 +31,8 @@ import xbmc
import xbmcgui
import xbmcvfs
import Localization
from functions import file_encode, isSubtitle, DownloadDB, log, debug, is_writable, vista_check, windows_check
from platform_pulsar import get_platform
from functions import isSubtitle, DownloadDB, log, debug, is_writable,\
vista_check, windows_check, localize_path
class Libtorrent:
magnetLink = None
@ -48,7 +48,6 @@ class Libtorrent:
__settings__ = sys.modules["__main__"].__settings__
def __init__(self, storageDirectory='', torrentFile='', torrentFilesDirectory='torrents'):
self.platform = get_platform()
self.storageDirectory = storageDirectory
self.torrentFilesPath = os.path.join(self.storageDirectory, torrentFilesDirectory) + os.sep
if not is_writable(self.storageDirectory):
@ -61,11 +60,11 @@ class Libtorrent:
try:
from python_libtorrent import get_libtorrent
libtorrent=get_libtorrent()
log('Imported libtorrent v%s from python_libtorrent/%s' %(libtorrent.version, self.platform['system']))
log('Imported libtorrent v%s from python_libtorrent' %(libtorrent.version))
module=True
except Exception, e:
module=False
log('Error importing python_libtorrent.%s. Exception: %s' %(self.platform['system'], str(e)))
log('Error importing python_libtorrent Exception: %s' %( str(e)))
import libtorrent
try:
@ -75,9 +74,6 @@ class Libtorrent:
except Exception, e:
log('Error importing from system. Exception: ' + str(e))
xbmcgui.Dialog().ok(Localization.localize('python-libtorrent Not Found'),
Localization.localize(self.platform["message"][0]),
Localization.localize(self.platform["message"][1]))
return
if xbmcvfs.exists(torrentFile):
@ -127,25 +123,32 @@ class Libtorrent:
log('Exception: ' + str(e))
xbmcvfs.delete(torrentFile)
return
baseName = file_encode(os.path.basename(self.getFilePath()))
if not xbmcvfs.exists(self.torrentFilesPath):
xbmcvfs.mkdirs(self.torrentFilesPath)
newFile = self.torrentFilesPath + self.md5(baseName) + '.' + self.md5(
torrentUrl) + '.torrent' # + '.'+ baseName
if xbmcvfs.exists(newFile):
xbmcvfs.delete(newFile)
if not xbmcvfs.exists(newFile):
try:
xbmcvfs.rename(torrentFile, newFile)
except Exception, e:
log('Unable to rename torrent file from %s to %s in Torrent::renameTorrent. Exception: %s' %
(torrentFile, newFile, str(e)))
return
self.torrentFile = newFile
if not self.torrentFileInfo:
e=self.lt.bdecode(xbmcvfs.File(self.torrentFile,'rb').read())
self.torrentFileInfo = self.lt.torrent_info(e)
self.torrentFile = torrentFile
return self.torrentFile
#baseName = localize_path(os.path.basename(self.getFilePath()))
#if not xbmcvfs.exists(self.torrentFilesPath):
# xbmcvfs.mkdirs(self.torrentFilesPath)
#newFile = self.torrentFilesPath + self.md5(
# torrentUrl) + '.torrent' #self.md5(baseName) + '.' +
#if xbmcvfs.exists(newFile):
# log('saveTorrent: delete file ' + newFile)
# xbmcvfs.delete(newFile)
#if not xbmcvfs.exists(newFile):
# try:
# renamed = xbmcvfs.rename(torrentFile, newFile)
# log('saveTorrent: xbmcvfs.rename %s %s to %s' %(torrentFile, newFile, str(renamed)))
# except Exception, e:
# log('Unable to rename torrent file from %s to %s in Torrent::renameTorrent. Exception: %s' %
# (torrentFile, newFile, str(e)))
# return
#self.torrentFile = newFile
#if not self.torrentFileInfo:
# e=self.lt.bdecode(xbmcvfs.File(self.torrentFile,'rb').read())
# self.torrentFileInfo = self.lt.torrent_info(e)
# log('torrentFileInfo (saveTorrent2)=' + str(self.torrentFileInfo))
#return self.torrentFile
def getMagnetInfo(self):
magnetSettings = {
@ -240,7 +243,7 @@ class Libtorrent:
def getContentList(self):
filelist = []
for contentId, contentFile in enumerate(self.torrentFileInfo.files()):
stringdata = {"title": contentFile.path, "size": contentFile.size, "ind": int(contentId),
stringdata = {"title": localize_path(contentFile.path), "size": contentFile.size, "ind": int(contentId),
'offset': contentFile.offset}
filelist.append(stringdata)
return filelist
@ -428,7 +431,7 @@ class Libtorrent:
#'storage_mode': self.lt.storage_mode_t(1),
'paused': False,
#'auto_managed': False,
#'duplicate_is_error': True
'duplicate_is_error': True
}
if self.save_resume_data:
log('loading resume data')

View File

@ -124,7 +124,6 @@ class OverlayText(object):
class TorrentPlayer(xbmc.Player):
__plugin__ = sys.modules["__main__"].__plugin__
__settings__ = sys.modules["__main__"].__settings__
ROOT = sys.modules["__main__"].__root__ # .decode('utf-8').encode(sys.getfilesystemencoding())
USERAGENT = "Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0"
torrentFilesDirectory = 'torrents'
debug = __settings__.getSetting('debug') == 'true'
@ -466,7 +465,7 @@ class TorrentPlayer(xbmc.Player):
def _get_status_lines(self, s):
return [
self.display_name.decode('utf-8')+'; '+self.torrent.get_debug_info('dht_state'),
self.display_name+'; '+self.torrent.get_debug_info('dht_state'),
"%.2f%% %s; %s" % (s.progress * 100, self.localize(STATE_STRS[s.state]).decode('utf-8'), self.torrent.get_debug_info('trackers_sum')),
"D:%.2f%s U:%.2f%s S:%d P:%d" % (s.download_rate / 1024, self.localize('kb/s').decode('utf-8'),
s.upload_rate / 1024, self.localize('kb/s').decode('utf-8'),

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.torrenter" name="Torrenter" version="2.5.0b" provider-name="DiMartino">
<addon id="plugin.video.torrenter" name="Torrenter" version="2.5.1" provider-name="DiMartino">
<requires>
<import addon="xbmc.python" version="2.1.0"/>
<import addon="script.module.libtorrent"/>
@ -7,6 +7,7 @@
<import addon="script.module.requests"/>
<import addon="script.module.torrent2http"/>
<import addon="script.module.pyrrent2http"/>
<import addon="script.module.chardet" />
</requires>
<extension point="xbmc.python.pluginsource" provides="video" library="default.py">
<provides>video</provides>

View File

@ -1,5 +1,8 @@
English changelog at http://bit.ly/1MfSVUP
[B]Version 2.5.1[/B]
[+] Исправлена работа с кодировками.
[B]Version 2.5.0[/B]
[+] НОВЫЙ проигрыватель pyrrent2http от inpos! Аналог torrent2http написаный на python, а не на GO.
[+] Проигрыватель: Ускорена повторная работа с торрентом - resume data (спасибо srg70 и RussakHH)

View File

@ -1966,7 +1966,6 @@ def check_network_advancedsettings():
log('UPDATE advancedsettings.xml disabled by user!')
def get_download_dir():
from platform_pulsar import get_platform
import tempfile
platform = get_platform()
@ -2000,8 +1999,9 @@ def ensure_str(string, encoding='utf-8'):
def file_url(torrentFile):
import urlparse
if not re.match("^file\:.+$", torrentFile) and os.path.exists(torrentFile):
torrentFile = urlparse.urljoin('file:', urllib.pathname2url(ensure_str(torrentFile)))
torrentFile = ensure_str(torrentFile)
if not re.match("^file\:.+$", torrentFile):
torrentFile = urlparse.urljoin('file:', urllib.pathname2url(torrentFile))
return torrentFile
def dump(obj):
@ -2031,4 +2031,65 @@ def foldername(path):
foldername = path.split('\\')[0]
else:
foldername = ''
return foldername
return foldername
def uri2path(uri):
import urlparse
if uri[1] == ':' and sys.platform.startswith('win'):
uri = 'file:///' + uri
fileUri = urlparse.urlparse(uri)
if fileUri.scheme == 'file':
uriPath = fileUri.path
if uriPath != '' and sys.platform.startswith('win') and (os.path.sep == uriPath[0] or uriPath[0] == '/'):
uriPath = uriPath[1:]
absPath = os.path.abspath(urllib.unquote(uriPath))
return localize_path(absPath)
def localize_path(path):
import chardet
if not isinstance(path, unicode): path = path.decode(chardet.detect(path)['encoding'])
if not sys.platform.startswith('win'):
path = encode_msg(path)
return path
def encode_msg(msg):
try:
msg = isinstance(msg, unicode) and msg.encode(True and sys.getfilesystemencoding() or 'utf-8') or msg
except:
import traceback
log(traceback.format_exc())
msg = msg.encode('utf-8')
return msg
def get_platform():
ret = {
"arch": sys.maxsize > 2 ** 32 and "x64" or "x86",
}
if xbmc.getCondVisibility("system.platform.android"):
ret["os"] = "android"
if "arm" in os.uname()[4] or "aarch64" in os.uname()[4]:
ret["arch"] = "arm"
elif xbmc.getCondVisibility("system.platform.linux"):
ret["os"] = "linux"
uname=os.uname()[4]
if "arm" in uname:
if "armv7" in uname:
ret["arch"] = "armv7"
elif "armv6" in uname:
ret["arch"] = "armv6"
else:
ret["arch"] = "arm"
elif "mips" in uname:
if sys.maxunicode > 65536:
ret["arch"] = 'mipsel_ucs4'
else:
ret["arch"] = 'mipsel_ucs2'
elif xbmc.getCondVisibility("system.platform.windows"):
ret["os"] = "windows"
elif xbmc.getCondVisibility("system.platform.osx"):
ret["os"] = "darwin"
elif xbmc.getCondVisibility("system.platform.ios"):
ret["os"] = "ios"
ret["arch"] = "arm"
return ret