pull/3/head
DiMartinoXBMC 2016-03-13 23:28:12 +03:00
parent a83699f477
commit c08f0c3b0e
6 changed files with 42 additions and 14 deletions

View File

@ -29,7 +29,7 @@ import xbmcgui
import xbmcvfs import xbmcvfs
import xbmcaddon import xbmcaddon
import Localization 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 import os
@ -261,7 +261,7 @@ class AnteoLoader:
class AnteoPlayer(xbmc.Player): class AnteoPlayer(xbmc.Player):
__plugin__ = sys.modules["__main__"].__plugin__ __plugin__ = sys.modules["__main__"].__plugin__
__settings__ = sys.modules["__main__"].__settings__ __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" USERAGENT = "Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0"
torrentFilesDirectory = 'torrents' torrentFilesDirectory = 'torrents'
debug = __settings__.getSetting('debug') == 'true' debug = __settings__.getSetting('debug') == 'true'
@ -318,7 +318,6 @@ class AnteoPlayer(xbmc.Player):
break break
except Exception, e: except Exception, e:
import traceback import traceback
log('['+author+'Player]: ' + str(e))
log(traceback.format_exc()) log(traceback.format_exc())
finally: finally:
self.engine.close() self.engine.close()
@ -621,7 +620,7 @@ class AnteoPlayer(xbmc.Player):
def _get_status_lines(self, s, f): def _get_status_lines(self, s, f):
return [ return [
self.display_name, localize_path(self.display_name),
"%.2f%% %s" % (f.progress * 100, self.localize(STATE_STRS[s.state]).decode('utf-8')), "%.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'), "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'), s.upload_rate, self.localize('kb/s').decode('utf-8'),

View File

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

View File

@ -31,7 +31,8 @@ import xbmc
import xbmcgui import xbmcgui
import xbmcvfs import xbmcvfs
import Localization 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 from platform_pulsar import get_platform
class Libtorrent: class Libtorrent:
@ -127,7 +128,7 @@ class Libtorrent:
log('Exception: ' + str(e)) log('Exception: ' + str(e))
xbmcvfs.delete(torrentFile) xbmcvfs.delete(torrentFile)
return return
baseName = file_encode(os.path.basename(self.getFilePath())) baseName = localize_path(os.path.basename(self.getFilePath()))
if not xbmcvfs.exists(self.torrentFilesPath): if not xbmcvfs.exists(self.torrentFilesPath):
xbmcvfs.mkdirs(self.torrentFilesPath) xbmcvfs.mkdirs(self.torrentFilesPath)
newFile = self.torrentFilesPath + self.md5(baseName) + '.' + self.md5( newFile = self.torrentFilesPath + self.md5(baseName) + '.' + self.md5(
@ -240,7 +241,7 @@ class Libtorrent:
def getContentList(self): def getContentList(self):
filelist = [] filelist = []
for contentId, contentFile in enumerate(self.torrentFileInfo.files()): 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} 'offset': contentFile.offset}
filelist.append(stringdata) filelist.append(stringdata)
return filelist return filelist

View File

@ -124,7 +124,6 @@ class OverlayText(object):
class TorrentPlayer(xbmc.Player): class TorrentPlayer(xbmc.Player):
__plugin__ = sys.modules["__main__"].__plugin__ __plugin__ = sys.modules["__main__"].__plugin__
__settings__ = sys.modules["__main__"].__settings__ __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" USERAGENT = "Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0"
torrentFilesDirectory = 'torrents' torrentFilesDirectory = 'torrents'
debug = __settings__.getSetting('debug') == 'true' debug = __settings__.getSetting('debug') == 'true'
@ -466,7 +465,7 @@ class TorrentPlayer(xbmc.Player):
def _get_status_lines(self, s): def _get_status_lines(self, s):
return [ 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')), "%.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'), "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'), s.upload_rate / 1024, self.localize('kb/s').decode('utf-8'),

View File

@ -7,6 +7,7 @@
<import addon="script.module.requests"/> <import addon="script.module.requests"/>
<import addon="script.module.torrent2http"/> <import addon="script.module.torrent2http"/>
<import addon="script.module.pyrrent2http"/> <import addon="script.module.pyrrent2http"/>
<import addon="script.module.chardet" />
</requires> </requires>
<extension point="xbmc.python.pluginsource" provides="video" library="default.py"> <extension point="xbmc.python.pluginsource" provides="video" library="default.py">
<provides>video</provides> <provides>video</provides>

View File

@ -2000,8 +2000,8 @@ def ensure_str(string, encoding='utf-8'):
def file_url(torrentFile): def file_url(torrentFile):
import urlparse import urlparse
if not re.match("^file\:.+$", torrentFile) and os.path.exists(torrentFile): if not re.match("^file\:.+$", torrentFile) and xbmcvfs.exists(torrentFile):
torrentFile = urlparse.urljoin('file:', urllib.pathname2url(ensure_str(torrentFile))) torrentFile = urlparse.urljoin('file:', urllib.pathname2url(torrentFile))
return torrentFile return torrentFile
def dump(obj): def dump(obj):
@ -2031,4 +2031,32 @@ def foldername(path):
foldername = path.split('\\')[0] foldername = path.split('\\')[0]
else: else:
foldername = '' 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 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