From 89d23556bb3f0bdae3b2d63917f956ae35cc9c3c Mon Sep 17 00:00:00 2001 From: DiMartinoXBMC Date: Sat, 12 Mar 2016 13:02:03 +0300 Subject: [PATCH 1/3] cosmetics --- Anteoloader.py | 11 ++++++++--- Player.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Anteoloader.py b/Anteoloader.py index 748bdb0..0d170e0 100644 --- a/Anteoloader.py +++ b/Anteoloader.py @@ -27,6 +27,7 @@ import zlib import xbmc import xbmcgui import xbmcvfs +import xbmcaddon import Localization from functions import file_encode, isSubtitle, DownloadDB, log, debug, is_writable, unquote, file_url @@ -42,9 +43,13 @@ from functions import foldername, showMessage, clearStorage, WatchedHistoryDB, g if sys.modules["__main__"].__settings__.getSetting("torrent_player") == '2': from torrent2http import State, Engine, MediaType author = 'Anteo' + __settings__ = xbmcaddon.Addon(id='script.module.torrent2http') + __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__ RESOURCES_PATH = os.path.join(ROOT, 'resources') @@ -276,7 +281,7 @@ class AnteoPlayer(xbmc.Player): self.userStorageDirectory = userStorageDirectory self.torrentUrl = torrentUrl xbmc.Player.__init__(self) - log("[AnteoPlayer] Initalized") + log("["+author+"Player] Initalized v"+__version__) self.params = params self.get = self.params.get self.contentId = int(self.get("url")) @@ -395,7 +400,7 @@ class AnteoPlayer(xbmc.Player): #self.pre_buffer_bytes = 30*1024*1024 #30 MB ready = False progressBar = xbmcgui.DialogProgress() - progressBar.create(self.localize('Please Wait'), + progressBar.create('[%sPlayer v%s] ' % (author, __version__) + self.localize('Please Wait'), self.localize('Seeds searching.')) #if self.subs_dl: # subs = self.torrent.getSubsIds(os.path.basename(self.torrent.getFilePath(self.contentId))) @@ -541,7 +546,7 @@ class AnteoPlayer(xbmc.Player): if isSubtitle(filename, i.name): subs.append(i) if subs: - log("[AnteoPlayer][setup_subs]: Detected subtitles: %s" % str(subs)) + log("["+author+"Player][setup_subs]: Detected subtitles: %s" % str(subs)) for sub in subs: xbmc.Player().setSubtitles(sub.url) diff --git a/Player.py b/Player.py index b771840..1509f23 100644 --- a/Player.py +++ b/Player.py @@ -244,7 +244,7 @@ class TorrentPlayer(xbmc.Player): def buffer(self): iterator = 0 progressBar = xbmcgui.DialogProgress() - progressBar.create(self.localize('Please Wait') + str(' [%s]' % str(self.torrent.lt.version)), + progressBar.create('[python-libtorrent %s] - ' % str(self.torrent.lt.version) + self.localize('Please Wait'), self.localize('Seeds searching.')) if self.subs_dl: subs = self.torrent.getSubsIds(os.path.basename(self.path)) From 55cb8797e247b52e2be38066dc2756daf71f669f Mon Sep 17 00:00:00 2001 From: DiMartinoXBMC Date: Sat, 12 Mar 2016 20:45:29 +0300 Subject: [PATCH 2/3] antizapret fix by inpos --- resources/proxy/antizapret.py | 56 ++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/resources/proxy/antizapret.py b/resources/proxy/antizapret.py index 127949f..e0f1ec2 100644 --- a/resources/proxy/antizapret.py +++ b/resources/proxy/antizapret.py @@ -14,52 +14,61 @@ if not os.path.exists(CACHE_DIR): CACHE = 24 * 3600 # 24 hour caching -@contextmanager +#@contextmanager def shelf(filename, ttl=0): import shelve filename = os.path.join(CACHE_DIR, filename) with LOCKS.get(filename, threading.RLock()): - with closing(shelve.open(filename, writeback=True)) as d: +# with closing(shelve.open(filename, writeback=True)) as d: + d = shelve.open(filename, writeback=True) + try: import time - if not d: + if not dict(d): d.update({ "created_at": time.time(), "data": {}, }) elif ttl > 0 and (time.time() - d["created_at"]) > ttl: + d["created_at"] = time.time() d["data"] = {} - yield d["data"] + return d + except: + d.close() + raise _config = {} def config(): global _config if not _config: - with shelf("antizapret.pac_config", ttl=CACHE) as pac_config: - if not pac_config: - log("[antizapret]: Fetching Antizapret PAC file on %s" %PAC_URL) - try: - pac_data = urllib2.urlopen(PAC_URL).read() - except: - pac_data = "" +# with shelf("antizapret.pac_config", ttl=CACHE) as pac_config: + d = shelf("antizapret.pac_config2", ttl=CACHE) + pac_config = d['data'] + if not pac_config: + log("[antizapret]: Fetching Antizapret PAC file on %s" %PAC_URL) + try: + pac_data = urllib2.urlopen(PAC_URL).read() + except: + pac_data = "" - r = re.search(r"\"PROXY (.*); DIRECT", pac_data) - if r: - pac_config["server"] = r.group(1) - pac_config["domains"] = map(lambda x: x.replace(r"\Z(?ms)", "").replace("\\", ""), map(fnmatch.translate, re.findall(r"\"(.*?)\",", pac_data))) - else: - pac_config["server"] = None - pac_config["domains"] = [] - _config = pac_config + r = re.search(r"\"PROXY (.*); DIRECT", pac_data) + if r: + pac_config["server"] = r.group(1) + pac_config["domains"] = map(lambda x: x.replace(r"\Z(?ms)", "").replace("\\", ""), map(fnmatch.translate, re.findall(r"\"(.*?)\",", pac_data))) + else: + pac_config["server"] = None + pac_config["domains"] = [] + d.close() + _config = pac_config return _config class AntizapretProxyHandler(urllib2.ProxyHandler, object): def __init__(self): self.config = config() urllib2.ProxyHandler.__init__(self, { - "http" : "", - "https": "", - "ftp" : "", + "http" : "", + "https": "", + "ftp" : "", }) def proxy_open(self, req, proxy, type): import socket @@ -95,5 +104,4 @@ def url_get(url, params={}, headers={}, post = None): return data except urllib2.HTTPError as e: log("[antizapret]: HTTP Error(%s): %s" % (e.errno, e.strerror)) - return None - + return None \ No newline at end of file From a457d2639598b82ceac2bf7d24467277899637cc Mon Sep 17 00:00:00 2001 From: DiMartinoXBMC Date: Sat, 12 Mar 2016 20:47:49 +0300 Subject: [PATCH 3/3] antizapret fix by inpos --- Core.py | 14 +++++++++++++- SearcherABC.py | 38 ++++++++++++++++++-------------------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/Core.py b/Core.py index 74ff169..36360cb 100644 --- a/Core.py +++ b/Core.py @@ -276,7 +276,19 @@ class Core: # self.Downloader.__exit__() #self.Player = AnteoPlayer(userStorageDirectory=self.userStorageDirectory, torrentUrl=torrentUrl, params=params) - xbmcgui.Dialog().ok('Dam Son!','Now send this shit to DiMartino') + #xbmcgui.Dialog().ok('Dam Son!','Now send this shit to DiMartino') + from resources.proxy import antizapret + filename = os.path.join(tempdir(),"antizapret.pac_config") + import shelve + from contextlib import contextmanager, closing + with closing(shelve.open(filename, writeback=True)) as d: + import time + log(str(d)) + log(str(time.time())) + log(str((time.time() - d["created_at"]))) + ttl = 24*3600 + if ttl > 0 and (time.time() - d["created_at"]) > ttl: + log('xxx') def DownloadStatus(self, params={}): db = DownloadDB() diff --git a/SearcherABC.py b/SearcherABC.py index 18638a4..1e4a432 100644 --- a/SearcherABC.py +++ b/SearcherABC.py @@ -33,7 +33,7 @@ import sys import xbmcgui import xbmc import Localization -from functions import log, debug +from functions import log, debug, showMessage class SearcherABC: @@ -47,13 +47,6 @@ class SearcherABC: socket.setdefaulttimeout(10+(10*int(timeout_multi))) - - #def __del__(self): - # print '!!!!!!!!!!!!!!!!!! DIED !!! '+self.__class__.__name__ - - #def __init__(self): - # print '!!!!!!!!!!!!!!!!!! BORN '+self.__class__.__name__ - def search(self, keyword): ''' Retrieve keyword from the input and return a list of tuples: @@ -110,19 +103,24 @@ class SearcherABC: def makeRequest(self, url, data={}, headers={}): self.load_cookie() + opener = None if self.proxy == 1: - from resources.proxy import antizapret - opener = urllib2.build_opener(antizapret.AntizapretProxyHandler(), urllib2.HTTPCookieProcessor(self.cookieJar)) - config = antizapret.config() - self.debug('[antizapret]: '+str(config["domains"])) - self.debug('[antizapret]: '+str(config["server"])) - elif self.proxy == 2: - from resources.proxy import immunicity - opener = urllib2.build_opener(immunicity.ImmunicityProxyHandler(), urllib2.HTTPCookieProcessor(self.cookieJar)) - config = immunicity.config() - self.debug('[immunicity]: '+str(config["domains"])) - self.debug('[immunicity]: '+str(config["server"])) - else: + try: + from resources.proxy import antizapret + opener = urllib2.build_opener(antizapret.AntizapretProxyHandler(), urllib2.HTTPCookieProcessor(self.cookieJar)) + config = antizapret.config() + self.debug('[antizapret]: '+str(config["domains"])) + self.debug('[antizapret]: '+str(config["server"])) + except: + showMessage('AntiZapret', Localization.localize('Error')) + self.debug('[antizapret]: OFF!') + #elif self.proxy == 2: + # from resources.proxy import immunicity + # opener = urllib2.build_opener(immunicity.ImmunicityProxyHandler(), urllib2.HTTPCookieProcessor(self.cookieJar)) + # config = immunicity.config() + # self.debug('[immunicity]: '+str(config["domains"])) + # self.debug('[immunicity]: '+str(config["server"])) + if not opener: opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookieJar)) opener.addheaders = headers if 0 < len(data):