From a83699f47794cb445da3f05764190a7a4a413dea Mon Sep 17 00:00:00 2001 From: DiMartinoXBMC Date: Sun, 13 Mar 2016 12:27:20 +0300 Subject: [PATCH 1/7] debug for inpos --- Anteoloader.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Anteoloader.py b/Anteoloader.py index 0d170e0..e37bd64 100644 --- a/Anteoloader.py +++ b/Anteoloader.py @@ -290,7 +290,8 @@ class AnteoPlayer(xbmc.Player): #self.torrent = AnteoLoader(self.userStorageDirectory, self.torrentUrl, self.torrentFilesDirectory) self.init() self.setup_engine() - with closing(self.engine): + #with closing(self.engine): + try: self.engine.start(self.contentId) self.setup_nextep() while True: @@ -315,6 +316,12 @@ class AnteoPlayer(xbmc.Player): continue log('['+author+'Player]: ************************************* NO! break') break + except Exception, e: + import traceback + log('['+author+'Player]: ' + str(e)) + log(traceback.format_exc()) + finally: + self.engine.close() xbmc.Player().stop() From c08f0c3b0ee5c4fc2c662939facf2b9300b34b62 Mon Sep 17 00:00:00 2001 From: DiMartinoXBMC Date: Sun, 13 Mar 2016 23:28:12 +0300 Subject: [PATCH 2/7] localize --- Anteoloader.py | 7 +++---- Core.py | 4 ++-- Libtorrent.py | 7 ++++--- Player.py | 3 +-- addon.xml | 1 + functions.py | 34 +++++++++++++++++++++++++++++++--- 6 files changed, 42 insertions(+), 14 deletions(-) diff --git a/Anteoloader.py b/Anteoloader.py index e37bd64..eea16b0 100644 --- a/Anteoloader.py +++ b/Anteoloader.py @@ -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 @@ -261,7 +261,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' @@ -318,7 +318,6 @@ class AnteoPlayer(xbmc.Player): break except Exception, e: import traceback - log('['+author+'Player]: ' + str(e)) log(traceback.format_exc()) finally: self.engine.close() @@ -621,7 +620,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'), diff --git a/Core.py b/Core.py index 36360cb..e1843ce 100644 --- a/Core.py +++ b/Core.py @@ -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") diff --git a/Libtorrent.py b/Libtorrent.py index 1f22f38..a89cda0 100644 --- a/Libtorrent.py +++ b/Libtorrent.py @@ -31,7 +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 functions import isSubtitle, DownloadDB, log, debug, is_writable,\ + vista_check, windows_check, localize_path from platform_pulsar import get_platform class Libtorrent: @@ -127,7 +128,7 @@ class Libtorrent: log('Exception: ' + str(e)) xbmcvfs.delete(torrentFile) return - baseName = file_encode(os.path.basename(self.getFilePath())) + baseName = localize_path(os.path.basename(self.getFilePath())) if not xbmcvfs.exists(self.torrentFilesPath): xbmcvfs.mkdirs(self.torrentFilesPath) newFile = self.torrentFilesPath + self.md5(baseName) + '.' + self.md5( @@ -240,7 +241,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 diff --git a/Player.py b/Player.py index 1509f23..4376657 100644 --- a/Player.py +++ b/Player.py @@ -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'), diff --git a/addon.xml b/addon.xml index 44d7a5d..f034a23 100644 --- a/addon.xml +++ b/addon.xml @@ -7,6 +7,7 @@ + video diff --git a/functions.py b/functions.py index 8026f0d..2e66cbe 100644 --- a/functions.py +++ b/functions.py @@ -2000,8 +2000,8 @@ 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))) + if not re.match("^file\:.+$", torrentFile) and xbmcvfs.exists(torrentFile): + torrentFile = urlparse.urljoin('file:', urllib.pathname2url(torrentFile)) return torrentFile def dump(obj): @@ -2031,4 +2031,32 @@ def foldername(path): foldername = path.split('\\')[0] else: foldername = '' - return foldername \ No newline at end of file + 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 normalize_msg(tmpl, *args): + import chardet + msg = isinstance(tmpl, unicode) and tmpl or tmpl.decode(chardet.detect(tmpl)['encoding']) + arg_ = [] + for a in args: + if not isinstance(a, unicode): arg_.append(a.decode(chardet.detect(a)['encoding'])) + return msg % tuple(arg_) + + +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 = path.encode(True and sys.getfilesystemencoding() or 'utf-8') + return path \ No newline at end of file From 58790136166f3aa3be0815489f7c2594ae825c13 Mon Sep 17 00:00:00 2001 From: DiMartinoXBMC Date: Mon, 14 Mar 2016 00:23:00 +0300 Subject: [PATCH 3/7] delete pulsar --- .idea/workspace.xml | 1161 +++++++++++++++++++++---------------------- Libtorrent.py | 6 +- functions.py | 36 +- 3 files changed, 606 insertions(+), 597 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6dfb265..1bf5c46 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,12 +1,10 @@ - + - - - + @@ -36,10 +34,10 @@ - + - + @@ -90,17 +88,16 @@ - + - - + + - @@ -110,7 +107,6 @@ - @@ -128,7 +124,6 @@ - @@ -176,7 +171,6 @@ - @@ -184,7 +178,6 @@ - @@ -202,7 +195,6 @@ - @@ -233,13 +225,11 @@ - - - - - - - + + + + + @@ -259,46 +249,26 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + @@ -307,7 +277,7 @@ - + @@ -342,19 +312,35 @@ - - + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -368,7 +354,7 @@ - + @@ -379,20 +365,18 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + @@ -402,89 +386,91 @@ - - + + + + - + + + + + + + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + @@ -500,16 +486,6 @@ - - - - - - - - - - @@ -532,7 +508,6 @@ @@ -617,6 +593,7 @@ + @@ -649,6 +626,24 @@ + + + + + + + + + + - @@ -896,48 +890,6 @@ @@ -1199,22 +1193,22 @@ + + - + - - @@ -1231,12 +1225,6 @@ - - - - - - @@ -1256,7 +1244,13 @@ - @@ -1265,27 +1259,6 @@ - - - - - - - - - - - - - - - - - - - - - @@ -1496,14 +1469,6 @@ - - - - - - - - @@ -1511,14 +1476,6 @@ - - - - - - - - @@ -1535,30 +1492,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -1566,268 +1499,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1858,9 +1532,24 @@ + + + + + + + + + + + + + + + - + @@ -1910,60 +1599,352 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Libtorrent.py b/Libtorrent.py index a89cda0..44025f1 100644 --- a/Libtorrent.py +++ b/Libtorrent.py @@ -32,8 +32,7 @@ import xbmcgui import xbmcvfs import Localization from functions import isSubtitle, DownloadDB, log, debug, is_writable,\ - vista_check, windows_check, localize_path -from platform_pulsar import get_platform + vista_check, windows_check, localize_path, get_platform class Libtorrent: magnetLink = None @@ -76,9 +75,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): diff --git a/functions.py b/functions.py index 2e66cbe..eb94d8f 100644 --- a/functions.py +++ b/functions.py @@ -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() @@ -2059,4 +2058,37 @@ def localize_path(path): if not isinstance(path, unicode): path = path.decode(chardet.detect(path)['encoding']) if not sys.platform.startswith('win'): path = path.encode(True and sys.getfilesystemencoding() or 'utf-8') - return path \ No newline at end of file + return path + +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 \ No newline at end of file From 09bb69265002dcebe2f7b3bd36e1e662cf74962b Mon Sep 17 00:00:00 2001 From: DiMartinoXBMC Date: Mon, 14 Mar 2016 13:57:54 +0300 Subject: [PATCH 4/7] rus fixes --- Anteoloader.py | 27 +++++++++------------------ Libtorrent.py | 13 ++++++------- functions.py | 18 ++++++++---------- 3 files changed, 23 insertions(+), 35 deletions(-) diff --git a/Anteoloader.py b/Anteoloader.py index eea16b0..a2c60eb 100644 --- a/Anteoloader.py +++ b/Anteoloader.py @@ -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,13 +157,15 @@ 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 = [] - with closing(self.engine): + try: self.engine.start() #media_types=[MediaType.VIDEO, MediaType.AUDIO, MediaType.SUBTITLES, MediaType.UNKNOWN] @@ -196,6 +192,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): @@ -230,8 +231,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') @@ -287,10 +286,8 @@ 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() @@ -316,7 +313,7 @@ class AnteoPlayer(xbmc.Player): continue log('['+author+'Player]: ************************************* NO! break') break - except Exception, e: + except: import traceback log(traceback.format_exc()) finally: @@ -336,12 +333,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 = '' diff --git a/Libtorrent.py b/Libtorrent.py index 44025f1..907a2b4 100644 --- a/Libtorrent.py +++ b/Libtorrent.py @@ -32,7 +32,7 @@ import xbmcgui import xbmcvfs import Localization from functions import isSubtitle, DownloadDB, log, debug, is_writable,\ - vista_check, windows_check, localize_path, get_platform + 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: @@ -124,11 +123,11 @@ class Libtorrent: log('Exception: ' + str(e)) xbmcvfs.delete(torrentFile) return - baseName = localize_path(os.path.basename(self.getFilePath())) + #baseName = localize_path(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 + newFile = self.torrentFilesPath + self.md5( + torrentUrl) + '.torrent' #self.md5(baseName) + '.' + if xbmcvfs.exists(newFile): xbmcvfs.delete(newFile) if not xbmcvfs.exists(newFile): diff --git a/functions.py b/functions.py index eb94d8f..946c022 100644 --- a/functions.py +++ b/functions.py @@ -1999,7 +1999,8 @@ def ensure_str(string, encoding='utf-8'): def file_url(torrentFile): import urlparse - if not re.match("^file\:.+$", torrentFile) and xbmcvfs.exists(torrentFile): + torrentFile = ensure_str(torrentFile) + if not re.match("^file\:.+$", torrentFile): torrentFile = urlparse.urljoin('file:', urllib.pathname2url(torrentFile)) return torrentFile @@ -2044,15 +2045,6 @@ def uri2path(uri): absPath = os.path.abspath(urllib.unquote(uriPath)) return localize_path(absPath) -def normalize_msg(tmpl, *args): - import chardet - msg = isinstance(tmpl, unicode) and tmpl or tmpl.decode(chardet.detect(tmpl)['encoding']) - arg_ = [] - for a in args: - if not isinstance(a, unicode): arg_.append(a.decode(chardet.detect(a)['encoding'])) - return msg % tuple(arg_) - - def localize_path(path): import chardet if not isinstance(path, unicode): path = path.decode(chardet.detect(path)['encoding']) @@ -2060,6 +2052,12 @@ def localize_path(path): path = path.encode(True and sys.getfilesystemencoding() or 'utf-8') return path +def delocalize_path(path): + import chardet + if not isinstance(path, unicode): path = path.decode(chardet.detect(path)['encoding']) + path = path.encode('utf-8') + return path + def get_platform(): ret = { "arch": sys.maxsize > 2 ** 32 and "x64" or "x86", From ccfcbf60898398a93c0ee19098443f64f8133763 Mon Sep 17 00:00:00 2001 From: DiMartinoXBMC Date: Mon, 14 Mar 2016 13:58:42 +0300 Subject: [PATCH 5/7] rus fixes --- addon.xml | 2 +- changelog.txt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/addon.xml b/addon.xml index f034a23..6231ca4 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@  - + diff --git a/changelog.txt b/changelog.txt index 91811fb..e6b9ee0 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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) From ef6584dd8c0c48af8706cba2d2df50c649bccd0e Mon Sep 17 00:00:00 2001 From: DiMartinoXBMC Date: Mon, 14 Mar 2016 20:38:33 +0300 Subject: [PATCH 6/7] rus fixes --- Libtorrent.py | 22 +++++++++++----------- functions.py | 15 +++++++++------ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Libtorrent.py b/Libtorrent.py index 907a2b4..9e6e0e5 100644 --- a/Libtorrent.py +++ b/Libtorrent.py @@ -126,17 +126,17 @@ class Libtorrent: #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): - 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 + newFile = self.torrentFilesPath + self.md5(torrentUrl) + '.torrent' + if newFile != torrentFile: + 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()) diff --git a/functions.py b/functions.py index 946c022..45e5801 100644 --- a/functions.py +++ b/functions.py @@ -2049,14 +2049,17 @@ 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 = path.encode(True and sys.getfilesystemencoding() or 'utf-8') + path = encode_msg(path) return path -def delocalize_path(path): - import chardet - if not isinstance(path, unicode): path = path.decode(chardet.detect(path)['encoding']) - path = path.encode('utf-8') - 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 = { From b45b8641eb67734a711612eba9fc49d28de5cc60 Mon Sep 17 00:00:00 2001 From: Sergey Shramchenko Date: Tue, 15 Mar 2016 09:55:25 +0200 Subject: [PATCH 7/7] Old player fix --- Libtorrent.py | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/Libtorrent.py b/Libtorrent.py index 9e6e0e5..220e31d 100644 --- a/Libtorrent.py +++ b/Libtorrent.py @@ -123,25 +123,32 @@ class Libtorrent: log('Exception: ' + str(e)) xbmcvfs.delete(torrentFile) return - #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' - if newFile != torrentFile: - 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 = { @@ -424,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')