Merge pull request #5 from DiMartinoXBMC/master

merge from origin
sandbox1
inpos 2016-03-19 10:03:11 +04:00
commit ba0f2263fd
11 changed files with 542 additions and 712 deletions

File diff suppressed because it is too large Load Diff

View File

@ -386,6 +386,7 @@ class AnteoPlayer(xbmc.Player):
dht_routers = ["router.bittorrent.com:6881","router.utorrent.com:6881"] dht_routers = ["router.bittorrent.com:6881","router.utorrent.com:6881"]
user_agent = 'uTorrent/2200(24683)' user_agent = 'uTorrent/2200(24683)'
self.pre_buffer_bytes = int(self.__settings__.getSetting("pre_buffer_bytes"))*1024*1024 self.pre_buffer_bytes = int(self.__settings__.getSetting("pre_buffer_bytes"))*1024*1024
showMessage('[%sPlayer v%s] ' % (author, __version__), self.localize('Please Wait'))
self.engine = Engine(uri=file_url(self.torrentUrl), download_path=self.userStorageDirectory, self.engine = Engine(uri=file_url(self.torrentUrl), download_path=self.userStorageDirectory,
connections_limit=connections_limit, download_kbps=download_limit, upload_kbps=upload_limit, connections_limit=connections_limit, download_kbps=download_limit, upload_kbps=upload_limit,
@ -520,7 +521,7 @@ class AnteoPlayer(xbmc.Player):
xbmc.sleep(2000) # very important, do not edit this, podavan xbmc.sleep(2000) # very important, do not edit this, podavan
i = 0 i = 0
while not xbmc.abortRequested and not self.isPlaying() and i < 50: while not xbmc.abortRequested and not self.isPlaying() and i < 150:
xbmc.sleep(200) xbmc.sleep(200)
i += 1 i += 1

78
Core.py
View File

@ -1101,11 +1101,13 @@ class Core:
view_style('searchOption') view_style('searchOption')
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=True) xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=True)
def drawItem(self, title, action, link='', image='', isFolder=True, contextMenu=None, replaceMenu=True, action2='', def drawItem(self, title, action, link='', image='', isFolder=True, contextMenu=None, replaceMenu=True, action2='', fileSize=0L,
info={}): info={}):
listitem = xbmcgui.ListItem(title, iconImage=image, thumbnailImage=image) listitem = xbmcgui.ListItem(title, iconImage=image, thumbnailImage=image)
#log('[drawItem]:'+str((title, action, image, isFolder, contextMenu, replaceMenu, action2, info))) #log('[drawItem]:'+str((title, action, image, isFolder, contextMenu, replaceMenu, action2, info)))
if not info: info = {"Title": title, "plot": title} if not info: info = {"Title": title, "plot": title}
if not isFolder and fileSize:
info['size'] = fileSize
if isinstance(link, dict): if isinstance(link, dict):
link_url = '' link_url = ''
for key in link.keys(): for key in link.keys():
@ -1127,6 +1129,7 @@ class Core:
listitem.setInfo(type='Video', infoLabels=info) listitem.setInfo(type='Video', infoLabels=info)
else: else:
listitem.setInfo(type='Video', infoLabels=info) listitem.setInfo(type='Video', infoLabels=info)
listitem.setArt({'thumb': image})
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=listitem, isFolder=isFolder) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=listitem, isFolder=isFolder)
def getParameters(self, parameterString): def getParameters(self, parameterString):
@ -1353,44 +1356,7 @@ class Core:
% ('torrentPlayer', url)) % ('torrentPlayer', url))
return return
if url: if url:
self.__settings__.setSetting("lastTorrentUrl", url) self.openTorrent(params)
torrent = Downloader.Torrent(self.userStorageDirectory, torrentFilesDirectory=self.torrentFilesDirectory)
self.__settings__.setSetting("lastTorrent", torrent.saveTorrent(url))
contentList = []
for filedict in torrent.getContentList():
fileTitle = filedict.get('title')
if filedict.get('size'):
fileTitle += ' [%d MB]' % (filedict.get('size') / 1024 / 1024)
contentList.append((unescape(fileTitle), str(filedict.get('ind'))))
contentList = sorted(contentList, key=lambda x: x[0])
#print str(contentList)
dirList, contentListNew = cutFolder(contentList, tdir)
for title in dirList:
self.drawItem(title, 'openTorrent', url, isFolder=True, action2=title)
ids_video_result = get_ids_video(contentListNew)
ids_video=''
if len(ids_video_result)>0:
for identifier in ids_video_result:
ids_video = ids_video + str(identifier) + ','
for title, identifier in contentListNew:
contextMenu = [
(self.localize('Download via T-client'),
'XBMC.RunPlugin(%s)' % ('%s?action=%s&ind=%s') % (
sys.argv[0], 'downloadFilesList', str(identifier))),
(self.localize('Download via Libtorrent'),
'XBMC.RunPlugin(%s)' % ('%s?action=%s&ind=%s') % (
sys.argv[0], 'downloadLibtorrent', str(identifier))),
]
self.drawItem(title, 'playTorrent', identifier, isFolder=False, action2=ids_video.rstrip(','),
contextMenu=contextMenu, replaceMenu=False)
view_style('torrentPlayer')
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=True)
def userStorage(self, params): def userStorage(self, params):
save=False save=False
@ -1486,7 +1452,7 @@ class Core:
def openTorrent(self, params={}): def openTorrent(self, params={}):
get = params.get get = params.get
tdir = unquote(get("url2"),None) tdir = unquote(get("url2"),None)
thumbnail = unquote(get("thumbnail"),'') thumbnail = unquote(get("thumbnail"), False) and True or 'DefaultVideo.png'
save_folder = unquote(get("save_folder"),'') save_folder = unquote(get("save_folder"),'')
url = urllib.unquote_plus(get("url")) url = urllib.unquote_plus(get("url"))
@ -1502,18 +1468,23 @@ class Core:
torrentFilesDirectory=self.torrentFilesDirectory) torrentFilesDirectory=self.torrentFilesDirectory)
self.__settings__.setSetting("lastTorrent", torrent.saveTorrent(url)) self.__settings__.setSetting("lastTorrent", torrent.saveTorrent(url))
append_filesize = self.__settings__.getSetting("append_filesize") == 'true'
hasSize = False
contentList = [] contentList = []
for filedict in torrent.getContentList(): for filedict in torrent.getContentList():
fileTitle = filedict.get('title') fileTitle = filedict.get('title')
if filedict.get('size'): size = filedict.get('size')
fileTitle += ' [%d MB]' % (filedict.get('size') / 1024 / 1024) if size:
contentList.append((unescape(fileTitle), str(filedict.get('ind')))) if append_filesize:
contentList = sorted(contentList, key=lambda x: x[0]) fileTitle += ' [%d MB]' % (size / 1024 / 1024)
hasSize = True
contentList.append((unescape(fileTitle), str(filedict.get('ind')), size))
#contentList = sorted(contentList, key=lambda x: x[0])
dirList, contentListNew = cutFolder(contentList, tdir) dirList, contentListNew = cutFolder(contentList, tdir)
for title in dirList: for title in dirList:
self.drawItem(title, 'openTorrent', url, image=thumbnail, isFolder=True, action2=title) self.drawItem(title, 'openTorrent', url, isFolder=True, action2=title)
ids_video_result = get_ids_video(contentListNew) ids_video_result = get_ids_video(contentListNew)
ids_video='' ids_video=''
@ -1522,7 +1493,7 @@ class Core:
for identifier in ids_video_result: for identifier in ids_video_result:
ids_video = ids_video + str(identifier) + ',' ids_video = ids_video + str(identifier) + ','
for title, identifier in contentListNew: for title, identifier, filesize in contentListNew:
contextMenu = [ contextMenu = [
(self.localize('Download via T-client'), (self.localize('Download via T-client'),
'XBMC.RunPlugin(%s)' % ('%s?action=%s&ind=%s') % ( 'XBMC.RunPlugin(%s)' % ('%s?action=%s&ind=%s') % (
@ -1533,9 +1504,20 @@ class Core:
] ]
link = {'url': identifier, 'thumbnail': thumbnail, 'save_folder':save_folder} link = {'url': identifier, 'thumbnail': thumbnail, 'save_folder':save_folder}
self.drawItem(title, 'playTorrent', link, image=thumbnail, isFolder=False, self.drawItem(title, 'playTorrent', link, image=thumbnail, isFolder=False,
action2=ids_video.rstrip(','), contextMenu=contextMenu, replaceMenu=False) action2=ids_video.rstrip(','), contextMenu=contextMenu, replaceMenu=False, fileSize=filesize)
view_style('openTorrent') view_style('openTorrent')
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=True) p_handle = int(sys.argv[1])
try:
xbmcplugin.addSortMethod(p_handle, xbmcplugin.SORT_METHOD_LABEL)
if hasSize:
xbmcplugin.addSortMethod(p_handle, xbmcplugin.SORT_METHOD_SIZE)
xbmc.executebuiltin("Container.SetSortMethod(%s)" % str(1))
#xbmc.executebuiltin("Container.SetSortDirection()")
except:
log(' !!!! >>>> Faild to set sorting method to ' + str(xbmcplugin.SORT_METHOD_SIZE))
pass
xbmcplugin.endOfDirectory(p_handle, succeeded=True)
def openSection(self, params={}): def openSection(self, params={}):
get = params.get get = params.get

View File

@ -96,7 +96,9 @@ class Libtorrent:
torrentUrl) + '.torrent' torrentUrl) + '.torrent'
try: try:
if not re.match("^http\:.+$", torrentUrl): if not re.match("^http\:.+$", torrentUrl):
content = xbmcvfs.File(torrentUrl, "rb").read() contentFile = xbmcvfs.File(torrentUrl, "rb")
content = contentFile.read()
contentFile.close()
else: else:
request = urllib2.Request(torrentUrl) request = urllib2.Request(torrentUrl)
request.add_header('Referer', torrentUrl) request.add_header('Referer', torrentUrl)
@ -123,32 +125,25 @@ class Libtorrent:
log('Exception: ' + str(e)) log('Exception: ' + str(e))
xbmcvfs.delete(torrentFile) xbmcvfs.delete(torrentFile)
return return
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 self.torrentFile = torrentFile
return self.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): def getMagnetInfo(self):
magnetSettings = { magnetSettings = {

View File

@ -255,3 +255,8 @@ class SearcherABC:
content = r1.read() content = r1.read()
self.debug('[open2] status:'+str(status)) self.debug('[open2] status:'+str(status))
return content return content
def showMessage(self, heading, message, times=10000):
xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s, "%s")' % (
heading.replace('"', "'"), message.replace('"', "'"), times, self.searchIcon))
self.log(str((heading.replace('"', "'"), message.replace('"', "'"), times, self.searchIcon)))

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.torrenter" name="Torrenter" version="2.5.1" provider-name="DiMartino"> <addon id="plugin.video.torrenter" name="Torrenter" version="2.5.2" provider-name="DiMartino">
<requires> <requires>
<import addon="xbmc.python" version="2.1.0"/> <import addon="xbmc.python" version="2.1.0"/>
<import addon="script.module.libtorrent"/> <import addon="script.module.libtorrent"/>

View File

@ -1,5 +1,8 @@
English changelog at http://bit.ly/1MfSVUP English changelog at http://bit.ly/1MfSVUP
[B]Version 2.5.2[/B]
[+] Упорядочивание по разверу файла.
[B]Version 2.5.1[/B] [B]Version 2.5.1[/B]
[+] Исправлена работа с кодировками. [+] Исправлена работа с кодировками.

View File

@ -428,13 +428,16 @@ def cutFolder(contentList, tdir=None):
common_folder = common_folder.split('/')[0] common_folder = common_folder.split('/')[0]
common = True common = True
for fileTitle, contentId in contentList: for item in contentList:
fileTitle = item[0]
if common_folder not in fileTitle: if common_folder not in fileTitle:
common = False common = False
break break
# print common_folder # print common_folder
for fileTitle, contentId in contentList: for item in contentList:
fileTitle = item[0]
contentId = item[1]
dir = None dir = None
if common: if common:
fileTitle = fileTitle[len(common_folder) + 1:] fileTitle = fileTitle[len(common_folder) + 1:]
@ -446,10 +449,12 @@ def cutFolder(contentList, tdir=None):
elif '/' in fileTitle: elif '/' in fileTitle:
dir = fileTitle.split('/')[0] dir = fileTitle.split('/')[0]
elif not tdir: elif not tdir:
contentListNew.append((fileTitle, contentId)) contentListNew.append(item)
if tdir and dir == tdir: if tdir and dir == tdir:
contentListNew.append((fileTitle[len(dir) + 1:], contentId)) tupleContent = list(item)
tupleContent[0] = fileTitle[len(dir) + 1:]
contentListNew.append(tuple(tupleContent))
if not tdir and dir and dir not in dirList: if not tdir and dir and dir not in dirList:
dirList.append(dir) dirList.append(dir)
@ -1711,7 +1716,9 @@ def get_ids_video(contentList):
'fli', 'flc', 'm4v', 'iso'] 'fli', 'flc', 'm4v', 'iso']
allowed_music_ext = ['mp3', 'flac', 'wma', 'ogg', 'm4a', 'aac', 'm4p', 'rm', 'ra'] allowed_music_ext = ['mp3', 'flac', 'wma', 'ogg', 'm4a', 'aac', 'm4p', 'rm', 'ra']
for extlist in [allowed_video_ext, allowed_music_ext]: for extlist in [allowed_video_ext, allowed_music_ext]:
for title, identifier in contentList: for item in contentList:
title = item[0]
identifier = item[1]
try: try:
ext = title.split('.')[-1] ext = title.split('.')[-1]
if ext.lower() in extlist: if ext.lower() in extlist:

View File

@ -3,7 +3,7 @@
<string id="30001">Interface Language</string> <string id="30001">Interface Language</string>
<string id="30002">Lock Folders View Style</string> <string id="30002">Lock Folders View Style</string>
<string id="30003">Off</string> <string id="30003">Off</string>
<string id="30004">Save Files To Folder</string> <string id="30004">Save Files To Folder (not FAT32)</string>
<string id="30007">Use magnet-links</string> <string id="30007">Use magnet-links</string>
<string id="30008">Keep downloaded files</string> <string id="30008">Keep downloaded files</string>
<string id="30009">Keep seeding of downloaded files</string> <string id="30009">Keep seeding of downloaded files</string>
@ -66,6 +66,7 @@
<string id="30066">Confluence (by safonov_ivan)</string> <string id="30066">Confluence (by safonov_ivan)</string>
<string id="30067">Aeon Nox (by joyrider)</string> <string id="30067">Aeon Nox (by joyrider)</string>
<string id="30068">pyrrent2http (python-libtorrent via http)</string> <string id="30068">pyrrent2http (python-libtorrent via http)</string>
<string id="30069">Append size to file name</string>
<string id="30101">Interface</string> <string id="30101">Interface</string>
<string id="30102">P2P Network</string> <string id="30102">P2P Network</string>
<string id="30103">Advanced</string> <string id="30103">Advanced</string>

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <?xml version="1.0" encoding="utf-8" standalone="yes"?>
<strings> <strings>
<string id="30001">Язык интерфейса</string> <string id="30001">Язык интерфейса</string>
<string id="30002">Удерживать стиль отображения</string> <string id="30002">Удерживать стиль отображения</string>
<string id="30003">Отключено</string> <string id="30003">Отключено</string>
<string id="30004">Сохранять файлы в директорию</string> <string id="30004">Сохранять файлы в директорию (не FAT32)</string>
<string id="30007">Использовать магнет-ссылки</string> <string id="30007">Использовать магнет-ссылки</string>
<string id="30008">Хранить загруженные файлы</string> <string id="30008">Хранить загруженные файлы</string>
<string id="30009">Оставаться на раздаче скачанных файлов</string> <string id="30009">Оставаться на раздаче скачанных файлов</string>
@ -66,6 +66,7 @@
<string id="30066">Confluence (от safonov_ivan)</string> <string id="30066">Confluence (от safonov_ivan)</string>
<string id="30067">Aeon Nox (от joyrider)</string> <string id="30067">Aeon Nox (от joyrider)</string>
<string id="30068">pyrrent2http (python-libtorrent по http)</string> <string id="30068">pyrrent2http (python-libtorrent по http)</string>
<string id="30069">Добавлять размер к имени файла</string>
<string id="30101">Интерфейс</string> <string id="30101">Интерфейс</string>
<string id="30102">P2P Сеть</string> <string id="30102">P2P Сеть</string>
<string id="30103">Дополнительные</string> <string id="30103">Дополнительные</string>

View File

@ -69,5 +69,6 @@
<setting id="min_storage_size" type="slider" label="30059" default="0" visible="!eq(-5,1)" range="0,2,100" option="int"/> <setting id="min_storage_size" type="slider" label="30059" default="0" visible="!eq(-5,1)" range="0,2,100" option="int"/>
<setting id="pause_onplay" type="bool" label="30060" default="false" visible="!eq(-6,1)"/> <setting id="pause_onplay" type="bool" label="30060" default="false" visible="!eq(-6,1)"/>
<setting id="max_history_add" type="slider" label="30065" default="100" visible="!eq(-7,1)" range="0,2,100" option="int"/> <setting id="max_history_add" type="slider" label="30065" default="100" visible="!eq(-7,1)" range="0,2,100" option="int"/>
<setting id="append_filesize" type="bool" label="30069" default="true"/>
</category> </category>
</settings> </settings>