pull/9/head
DiMartinoXBMC 2016-03-21 22:55:27 +03:00
parent 3196ee1437
commit ec694f4fc9
3 changed files with 29 additions and 38 deletions

View File

@ -2,6 +2,7 @@
''' '''
Torrenter v2 plugin for XBMC/Kodi Torrenter v2 plugin for XBMC/Kodi
Copyright (C) 2012-2015 Vadim Skorba v1 - DiMartino v2 Copyright (C) 2012-2015 Vadim Skorba v1 - DiMartino v2
https://forums.tvaddons.ag/addon-releases/29224-torrenter-v2.html
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -29,7 +30,7 @@ import xbmcgui
import xbmcvfs import xbmcvfs
import xbmcaddon import xbmcaddon
import Localization import Localization
from functions import localize_path, isSubtitle, is_writable, file_url from functions import file_encode, isSubtitle, DownloadDB, log, debug, is_writable, unquote, file_url
import os import os
@ -40,16 +41,10 @@ from contextlib import contextmanager, closing, nested
from functions import foldername, showMessage, clearStorage, WatchedHistoryDB, get_ids_video, log, debug, ensure_str from functions import foldername, showMessage, clearStorage, WatchedHistoryDB, get_ids_video, log, debug, ensure_str
#if sys.modules["__main__"].__settings__.getSetting("torrent_player") == '2':
from torrent2http import State, Engine, MediaType from torrent2http import State, Engine, MediaType
author = 'Anteo' author = 'Anteo'
__settings__ = xbmcaddon.Addon(id='script.module.torrent2http') __settings__ = xbmcaddon.Addon(id='script.module.torrent2http')
__version__ = __settings__.getAddonInfo('version') __version__ = __settings__.getAddonInfo('version')
#elif sys.modules["__main__"].__settings__.getSetting("torrent_player") == '3':
# from pyrrent2http import State, Engine, MediaType
# author = 'Inpos'
# __settings__ = xbmcaddon.Addon(id='script.module.pyrrent2http')
# __version__ = __settings__.getAddonInfo('version')
ROOT = sys.modules["__main__"].__root__ ROOT = sys.modules["__main__"].__root__
RESOURCES_PATH = os.path.join(ROOT, 'resources') RESOURCES_PATH = os.path.join(ROOT, 'resources')
@ -165,7 +160,7 @@ class AnteoLoader:
self.setup_engine() self.setup_engine()
files = [] files = []
filelist = [] filelist = []
try: with closing(self.engine):
self.engine.start() self.engine.start()
#media_types=[MediaType.VIDEO, MediaType.AUDIO, MediaType.SUBTITLES, MediaType.UNKNOWN] #media_types=[MediaType.VIDEO, MediaType.AUDIO, MediaType.SUBTITLES, MediaType.UNKNOWN]
@ -192,11 +187,6 @@ class AnteoLoader:
stringdata = {"title": ensure_str(fs.name), "size": fs.size, "ind": fs.index, stringdata = {"title": ensure_str(fs.name), "size": fs.size, "ind": fs.index,
'offset': fs.offset} 'offset': fs.offset}
filelist.append(stringdata) filelist.append(stringdata)
except:
import traceback
log(traceback.format_exc())
finally:
self.engine.close()
return filelist return filelist
def saveTorrent(self, torrentUrl): def saveTorrent(self, torrentUrl):
@ -255,7 +245,7 @@ class AnteoLoader:
self.torrentFile = torrent.torrentFile self.torrentFile = torrent.torrentFile
except: except:
self.torrentFile = magnet self.torrentFile = magnet
log('['+author+'Loader][magnetToTorrent]: self.torrentFile '+str(self.torrentFile)) log('[AnteoLoader][magnetToTorrent]: self.torrentFile '+str(self.torrentFile))
class AnteoPlayer(xbmc.Player): class AnteoPlayer(xbmc.Player):
__plugin__ = sys.modules["__main__"].__plugin__ __plugin__ = sys.modules["__main__"].__plugin__
@ -286,22 +276,23 @@ class AnteoPlayer(xbmc.Player):
self.contentId = int(self.get("url")) self.contentId = int(self.get("url"))
if self.get("seek"): if self.get("seek"):
self.seek = int(self.get("seek")) self.seek = int(self.get("seek"))
#self.torrent = AnteoLoader(self.userStorageDirectory, self.torrentUrl, self.torrentFilesDirectory)
self.init() self.init()
self.setup_engine() self.setup_engine()
try: with closing(self.engine):
self.engine.start(self.contentId) self.engine.start(self.contentId)
self.setup_nextep() self.setup_nextep()
while True: while True:
if self.buffer(): if self.buffer():
log('['+author+'Player]: ************************************* GOING LOOP') log('[AnteoPlayer]: ************************************* GOING LOOP')
if self.setup_play(): if self.setup_play():
self.setup_subs() self.setup_subs()
self.loop() self.loop()
WatchedHistoryDB().add(self.basename, foldername(self.getContentList()[self.contentId]['title']), self.watchedTime, self.totalTime, self.contentId, self.fullSize) WatchedHistoryDB().add(self.basename, foldername(self.getContentList()[self.contentId]['title']), self.watchedTime, self.totalTime, self.contentId, self.fullSize)
else: else:
log('['+author+'Player]: ************************************* break') log('[AnteoPlayer]: ************************************* break')
break break
log('['+author+'Player]: ************************************* GO NEXT?') log('[AnteoPlayer]: ************************************* GO NEXT?')
if self.next_dl and self.next_contentId != False and isinstance(self.next_contentId, int) and self.iterator == 100: if self.next_dl and self.next_contentId != False and isinstance(self.next_contentId, int) and self.iterator == 100:
if not self.next_play: if not self.next_play:
xbmc.sleep(3000) xbmc.sleep(3000)
@ -311,13 +302,9 @@ class AnteoPlayer(xbmc.Player):
break break
self.contentId = self.next_contentId self.contentId = self.next_contentId
continue continue
log('['+author+'Player]: ************************************* NO! break')
log('[AnteoPlayer]: ************************************* NO! break')
break break
except:
import traceback
log(traceback.format_exc())
finally:
self.engine.close()
xbmc.Player().stop() xbmc.Player().stop()
@ -386,7 +373,6 @@ 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,
@ -470,7 +456,7 @@ class AnteoPlayer(xbmc.Player):
else: else:
self.next_dl = False self.next_dl = False
self.next_play = self.__settings__.getSetting('next_play') == 'true' self.next_play = self.__settings__.getSetting('next_play') == 'true'
log('['+author+'Player]: next_dl - %s, next_play - %s, ids_video - %s' % (str(self.next_dl), str(self.next_play), str(self.ids_video))) log('[AnteoPlayer]: next_dl - %s, next_play - %s, ids_video - %s' % (str(self.next_dl), str(self.next_play), str(self.ids_video)))
def setup_play(self): def setup_play(self):
file_status = self.engine.file_status(self.contentId) file_status = self.engine.file_status(self.contentId)
@ -489,7 +475,7 @@ class AnteoPlayer(xbmc.Player):
self.next_contentId = int(self.ids_video[next_contentId_index]) self.next_contentId = int(self.ids_video[next_contentId_index])
else: else:
self.next_contentId = False self.next_contentId = False
log('['+author+'Player][setup_play]: next_contentId: '+str(self.next_contentId)) log('[AnteoPlayer][setup_play]: next_contentId: '+str(self.next_contentId))
try: try:
seasonId = self.get("seasonId") seasonId = self.get("seasonId")
self.episodeId = self.get("episodeId") if not self.episodeId else int(self.episodeId) + 1 self.episodeId = self.get("episodeId") if not self.episodeId else int(self.episodeId) + 1
@ -509,7 +495,7 @@ class AnteoPlayer(xbmc.Player):
'season': int(seasonId), 'season': int(seasonId),
'tvshowtitle': title}) 'tvshowtitle': title})
except: except:
log('['+author+'Player]: Operation INFO failed!') log('[AnteoPlayer]: Operation INFO failed!')
thumbnail = self.get("thumbnail") thumbnail = self.get("thumbnail")
if thumbnail: if thumbnail:
@ -525,12 +511,12 @@ class AnteoPlayer(xbmc.Player):
xbmc.sleep(200) xbmc.sleep(200)
i += 1 i += 1
log('['+author+'Player]: self.isPlaying() = %s, i = %d, xbmc.abortRequested - %s' % (str(self.isPlaying()), i, str(xbmc.abortRequested))) log('[AnteoPlayer]: self.isPlaying() = %s, i = %d, xbmc.abortRequested - %s' % (str(self.isPlaying()), i, str(xbmc.abortRequested)))
if not self.isPlaying() or xbmc.abortRequested: if not self.isPlaying() or xbmc.abortRequested:
return False return False
if self.seek > 0: if self.seek > 0:
log('['+author+'Player]: seekTime - '+str(self.seek)) log('[AnteoPlayer]: seekTime - '+str(self.seek))
self.seekTime(self.seek) self.seekTime(self.seek)
return True return True
@ -544,7 +530,7 @@ class AnteoPlayer(xbmc.Player):
if isSubtitle(filename, i.name): if isSubtitle(filename, i.name):
subs.append(i) subs.append(i)
if subs: if subs:
log("["+author+"Player][setup_subs]: Detected subtitles: %s" % str(subs)) log("[AnteoPlayer][setup_subs]: Detected subtitles: %s" % str(subs))
for sub in subs: for sub in subs:
xbmc.Player().setSubtitles(sub.url) xbmc.Player().setSubtitles(sub.url)
@ -612,7 +598,7 @@ class AnteoPlayer(xbmc.Player):
def _get_status_lines(self, s, f): def _get_status_lines(self, s, f):
return [ return [
ensure_str(self.display_name), 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'),
@ -637,7 +623,7 @@ class AnteoPlayer(xbmc.Player):
if not status: if not status:
status = self.engine.status() status = self.engine.status()
self.engine.check_torrent_error(status) self.engine.check_torrent_error(status)
log('['+author+'Player]: %.2f%% complete (down: %.1f kb/s up: %.1f kb/s peers: %d) %s' % \ log('[AnteoPlayer]: %.2f%% complete (down: %.1f kb/s up: %.1f kb/s peers: %d) %s' % \
(status.progress * 100, status.download_rate, (status.progress * 100, status.download_rate,
status.upload_rate, status.num_peers, status.state_str)) status.upload_rate, status.num_peers, status.state_str))

10
Core.py
View File

@ -1101,8 +1101,8 @@ class Core:
def drawItem(self, title, action, link='', image='', isFolder=True, contextMenu=None, replaceMenu=True, action2='', fileSize=0L, 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)
#log('[drawItem]:'+str((title, action, image, isFolder, contextMenu, replaceMenu, action2, info))) #log('[drawItem]:'+str((title, action, image, isFolder, contextMenu, replaceMenu, action2, info)))
listitem = xbmcgui.ListItem(title, iconImage=image, thumbnailImage=image)
if not info: info = {"Title": title, "plot": title} if not info: info = {"Title": title, "plot": title}
if not isFolder and fileSize: if not isFolder and fileSize:
info['size'] = fileSize info['size'] = fileSize
@ -1430,9 +1430,11 @@ class Core:
request.add_header('Accept-encoding', 'gzip') request.add_header('Accept-encoding', 'gzip')
result = urllib2.urlopen(request) result = urllib2.urlopen(request)
if result.info().get('Content-Encoding') == 'gzip': if result.info().get('Content-Encoding') == 'gzip':
from StringIO import StringIO
import zlib
buf = StringIO(result.read()) buf = StringIO(result.read())
f = gzip.GzipFile(fileobj=buf) decomp = zlib.decompressobj(16 + zlib.MAX_WBITS)
content = f.read() content = decomp.decompress(buf.getvalue())
else: else:
content = result.read() content = result.read()
localFile = xbmcvfs.File(torrentFile, "wb+") localFile = xbmcvfs.File(torrentFile, "wb+")
@ -1459,7 +1461,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"), False) and True or 'DefaultVideo.png' thumbnail = unquote(get("thumbnail"), False) 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"))

View File

@ -522,7 +522,10 @@ class InposPlayer(xbmc.Player):
while not xbmc.abortRequested and self.isPlaying(): while not xbmc.abortRequested and self.isPlaying():
self.print_fulldebug() self.print_fulldebug()
status = self.engine.status() status = self.engine.status()
if not self.next_dling:
file_status = self.engine.file_status(self.contentId) file_status = self.engine.file_status(self.contentId)
else:
file_status = self.engine.file_status(self.next_contentId)
self.watchedTime = xbmc.Player().getTime() self.watchedTime = xbmc.Player().getTime()
self.totalTime = xbmc.Player().getTotalTime() self.totalTime = xbmc.Player().getTotalTime()
if self.iterator == 100 and debug_counter < 100: if self.iterator == 100 and debug_counter < 100: