pull/1/head
DiMartinoXBMC 2016-03-07 21:12:53 +03:00
parent 8d4a28e91e
commit f55c56cf60
1 changed files with 32 additions and 32 deletions

View File

@ -186,39 +186,39 @@ class AnteoLoader:
return filelist return filelist
def saveTorrent(self, torrentUrl): def saveTorrent(self, torrentUrl):
if not xbmcvfs.exists(torrentUrl) or re.match("^http.+$", torrentUrl): #if not xbmcvfs.exists(torrentUrl) or re.match("^http.+$", torrentUrl):
if re.match("^magnet\:.+$", torrentUrl): if re.match("^magnet\:.+$", torrentUrl):
self.magnetLink = torrentUrl self.magnetLink = torrentUrl
self.magnetToTorrent(torrentUrl) self.magnetToTorrent(torrentUrl)
self.magnetLink = None self.magnetLink = None
return self.torrentFile return self.torrentFile
else:
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):
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()
localFile = xbmcvfs.File(torrentFile, "w+b")
localFile.write(content)
localFile.close()
except Exception, e:
log('Unable to rename torrent file from %s to %s in AnteoLoader::saveTorrent. Exception: %s' %
(torrentUrl, torrentFile, str(e)))
return
else: else:
torrentFile = torrentUrl 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):
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()
localFile = xbmcvfs.File(torrentFile, "w+b")
localFile.write(content)
localFile.close()
except Exception, e:
log('Unable to rename torrent file from %s to %s in AnteoLoader::saveTorrent. Exception: %s' %
(torrentUrl, torrentFile, str(e)))
return
#else:
#torrentFile = torrentUrl
if xbmcvfs.exists(torrentFile) and not os.path.exists(torrentFile): if xbmcvfs.exists(torrentFile) and not os.path.exists(torrentFile):
if not xbmcvfs.exists(self.torrentFilesPath): xbmcvfs.mkdirs(self.torrentFilesPath) if not xbmcvfs.exists(self.torrentFilesPath): xbmcvfs.mkdirs(self.torrentFilesPath)
torrentFile = os.path.join(self.torrentFilesPath, self.md5(torrentUrl) + '.torrent') torrentFile = os.path.join(self.torrentFilesPath, self.md5(torrentUrl) + '.torrent')