From ef180cc215f36649e36697a5a5a9b0b122fddfcd Mon Sep 17 00:00:00 2001 From: DiMartinoXBMC Date: Tue, 13 Dec 2016 19:12:14 +0300 Subject: [PATCH] :// protocol for mancuniancol --- AceStream.py | 42 +++++++++++++++++++++++++++++------------- Anteoloader.py | 38 +++++++++++++++++++++++++++----------- Inposloader.py | 39 +++++++++++++++++++++++++++------------ SkorbaLoader.py | 44 +++++++++++++++++++++++++++++--------------- 4 files changed, 112 insertions(+), 51 deletions(-) diff --git a/AceStream.py b/AceStream.py index 8d7137f..dda3cfc 100644 --- a/AceStream.py +++ b/AceStream.py @@ -25,7 +25,7 @@ import hashlib import re import base64 from StringIO import StringIO -import gzip +import zlib from functions import file_decode, file_encode from functions import magnet_alert, log, debug @@ -93,19 +93,12 @@ class AceStream: torrentFile = self.storageDirectory + os.sep + self.torrentFilesDirectory + os.sep + self.md5( torrentUrl) + '.torrent' try: - if not re.match("^http\:.+$", torrentUrl): - content = xbmcvfs.File(file_decode(torrentUrl), "rb").read() + if not re.match("^[htps]+?://.+$|^://.+$", torrentUrl): + log('xbmcvfs.File for %s' % torrentUrl) + content = xbmcvfs.File(torrentUrl, "rb").read() else: - request = urllib2.Request(torrentUrl) - request.add_header('Referer', torrentUrl) - request.add_header('Accept-encoding', 'gzip') - result = urllib2.urlopen(request) - if result.info().get('Content-Encoding') == 'gzip': - buf = StringIO(result.read()) - f = gzip.GzipFile(fileobj=buf) - content = f.read() - else: - content = result.read() + log('request for %s' % torrentUrl) + content = self.makeRequest(torrentUrl) localFile = xbmcvfs.File(torrentFile, "w+b") localFile.write(content) @@ -119,6 +112,29 @@ class AceStream: self.torrentFileInfo = self.TSplayer.load_torrent(base64.b64encode(content), 'RAW') return self.torrentFile + def makeRequest(self, torrentUrl): + torrentUrl = re.sub('^://', 'http://', torrentUrl) + x = re.search("://(.+?)/|://(.+?)$", torrentUrl) + if x: + baseurl = x.group(1) if x.group(1) else x.group(2) + else: + baseurl ='' + + headers = [('User-Agent', + 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 YaBrowser/14.10.2062.12061 Safari/537.36'), + ('Referer', 'http://%s/' % baseurl), ('Accept-encoding', 'gzip'), ] + + opener = urllib2.build_opener() + opener.addheaders = headers + result = opener.open(torrentUrl) + if result.info().get('Content-Encoding') == 'gzip': + buf = StringIO(result.read()) + decomp = zlib.decompressobj(16 + zlib.MAX_WBITS) + content = decomp.decompress(buf.getvalue()) + else: + content = result.read() + return content + def magnetToTorrent(self, magnet): try: from SkorbaLoader import SkorbaLoader diff --git a/Anteoloader.py b/Anteoloader.py index 4eae5fa..3ec1105 100644 --- a/Anteoloader.py +++ b/Anteoloader.py @@ -200,19 +200,12 @@ class AnteoLoader: if not xbmcvfs.exists(self.torrentFilesPath): xbmcvfs.mkdirs(self.torrentFilesPath) torrentFile = os.path.join(self.torrentFilesPath, self.md5(torrentUrl) + '.torrent') try: - if not re.match("^http\:.+$", torrentUrl): + if not re.match("^[htps]+?://.+$|^://.+$", torrentUrl): + log('xbmcvfs.File for %s' % torrentUrl) content = xbmcvfs.File(torrentUrl, "rb").read() else: - request = urllib2.Request(torrentUrl) - request.add_header('Referer', torrentUrl) - request.add_header('Accept-encoding', 'gzip') - result = urllib2.urlopen(request) - if result.info().get('Content-Encoding') == 'gzip': - buf = StringIO(result.read()) - decomp = zlib.decompressobj(16 + zlib.MAX_WBITS) - content = decomp.decompress(buf.getvalue()) - else: - content = result.read() + log('request for %s' % torrentUrl) + content = self.makeRequest(torrentUrl) localFile = xbmcvfs.File(torrentFile, "w+b") localFile.write(content) @@ -229,6 +222,29 @@ class AnteoLoader: self.torrentFile = torrentFile return self.torrentFile + def makeRequest(self, torrentUrl): + torrentUrl = re.sub('^://', 'http://', torrentUrl) + x = re.search("://(.+?)/|://(.+?)$", torrentUrl) + if x: + baseurl = x.group(1) if x.group(1) else x.group(2) + else: + baseurl ='' + + headers = [('User-Agent', + 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 YaBrowser/14.10.2062.12061 Safari/537.36'), + ('Referer', 'http://%s/' % baseurl), ('Accept-encoding', 'gzip'), ] + + opener = urllib2.build_opener() + opener.addheaders = headers + result = opener.open(torrentUrl) + if result.info().get('Content-Encoding') == 'gzip': + buf = StringIO(result.read()) + decomp = zlib.decompressobj(16 + zlib.MAX_WBITS) + content = decomp.decompress(buf.getvalue()) + else: + content = result.read() + return content + def md5(self, string): hasher = hashlib.md5() try: diff --git a/Inposloader.py b/Inposloader.py index 0408aac..6e754ff 100644 --- a/Inposloader.py +++ b/Inposloader.py @@ -168,20 +168,12 @@ class InposLoader: if not xbmcvfs.exists(self.torrentFilesPath): xbmcvfs.mkdirs(self.torrentFilesPath) torrentFile = localize_path(os.path.join(self.torrentFilesPath, self.md5(torrentUrl) + '.torrent')) try: - if not re.match("^http\:.+$", torrentUrl): + if not re.match("^[htps]+?://.+$|^://.+$", torrentUrl): + log('xbmcvfs.File for %s' % torrentUrl) content = xbmcvfs.File(torrentUrl, "rb").read() else: - request = urllib2.Request(torrentUrl) - request.add_header('Referer', torrentUrl) - request.add_header('Accept-encoding', 'gzip') - result = urllib2.urlopen(request) - if result.info().get('Content-Encoding') == 'gzip': - buf = StringIO(result.read()) - decomp = zlib.decompressobj(16 + zlib.MAX_WBITS) - content = decomp.decompress(buf.getvalue()) - else: - content = result.read() - + log('request for %s' % torrentUrl) + content = self.makeRequest(torrentUrl) localFile = xbmcvfs.File(torrentFile, "w+b") localFile.write(content) localFile.close() @@ -197,6 +189,29 @@ class InposLoader: self.torrentFile = torrentFile return self.torrentFile + def makeRequest(self, torrentUrl): + torrentUrl = re.sub('^://', 'http://', torrentUrl) + x = re.search("://(.+?)/|://(.+?)$", torrentUrl) + if x: + baseurl = x.group(1) if x.group(1) else x.group(2) + else: + baseurl ='' + + headers = [('User-Agent', + 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 YaBrowser/14.10.2062.12061 Safari/537.36'), + ('Referer', 'http://%s/' % baseurl), ('Accept-encoding', 'gzip'), ] + + opener = urllib2.build_opener() + opener.addheaders = headers + result = opener.open(torrentUrl) + if result.info().get('Content-Encoding') == 'gzip': + buf = StringIO(result.read()) + decomp = zlib.decompressobj(16 + zlib.MAX_WBITS) + content = decomp.decompress(buf.getvalue()) + else: + content = result.read() + return content + def md5(self, string): hasher = hashlib.md5() try: diff --git a/SkorbaLoader.py b/SkorbaLoader.py index fb0cdd7..34048c5 100644 --- a/SkorbaLoader.py +++ b/SkorbaLoader.py @@ -95,21 +95,12 @@ class SkorbaLoader: xbmcvfs.mkdirs(self.torrentFilesPath) torrentFile = localize_path(os.path.join(self.torrentFilesPath, self.md5(torrentUrl) + '.torrent')) try: - if not re.match("^http\:.+$", torrentUrl): - contentFile = xbmcvfs.File(torrentUrl, "rb") - content = contentFile.read() - contentFile.close() + if not re.match("^[htps]+?://.+$|^://.+$", torrentUrl): + log('xbmcvfs.File for %s' % torrentUrl) + content = xbmcvfs.File(torrentUrl, "rb").read() else: - request = urllib2.Request(torrentUrl) - request.add_header('Referer', torrentUrl) - request.add_header('Accept-encoding', 'gzip') - result = urllib2.urlopen(request) - if result.info().get('Content-Encoding') == 'gzip': - buf = StringIO(result.read()) - decomp = zlib.decompressobj(16 + zlib.MAX_WBITS) - content = decomp.decompress(buf.getvalue()) - else: - content = result.read() + log('request for %s' % torrentUrl) + content = self.makeRequest(torrentUrl) localFile = xbmcvfs.File(torrentFile, "w+b") localFile.write(content) @@ -144,7 +135,30 @@ class SkorbaLoader: self.torrentFileInfo = self.lt.torrent_info(e) self.torrentFile = torrentFile return self.torrentFile - + + def makeRequest(self, torrentUrl): + torrentUrl = re.sub('^://', 'http://', torrentUrl) + x = re.search("://(.+?)/|://(.+?)$", torrentUrl) + if x: + baseurl = x.group(1) if x.group(1) else x.group(2) + else: + baseurl ='' + + headers = [('User-Agent', + 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 YaBrowser/14.10.2062.12061 Safari/537.36'), + ('Referer', 'http://%s/' % baseurl), ('Accept-encoding', 'gzip'), ] + + opener = urllib2.build_opener() + opener.addheaders = headers + result = opener.open(torrentUrl) + if result.info().get('Content-Encoding') == 'gzip': + buf = StringIO(result.read()) + decomp = zlib.decompressobj(16 + zlib.MAX_WBITS) + content = decomp.decompress(buf.getvalue()) + else: + content = result.read() + return content + def getMagnetInfo(self): magnetSettings = { 'url': self.magnetLink,