ace magnet

pull/1/head
DiMartinoXBMC 2015-12-21 18:15:21 +03:00
parent 8547f8354a
commit f52863e684
1 changed files with 24 additions and 21 deletions

View File

@ -28,7 +28,7 @@ from StringIO import StringIO
import gzip import gzip
from functions import file_decode, file_encode from functions import file_decode, file_encode
from functions import magnet_alert from functions import magnet_alert, log, debug
import xbmcvfs import xbmcvfs
@ -39,7 +39,7 @@ class AceStream:
gf = open(pfile, 'r') gf = open(pfile, 'r')
aceport = int(gf.read()) aceport = int(gf.read())
gf.close() gf.close()
print aceport log('[AceStream]: aceport - '+str(aceport))
except: except:
aceport = 62062 aceport = 62062
@ -60,9 +60,9 @@ class AceStream:
try: try:
from ASCore import TSengine as tsengine from ASCore import TSengine as tsengine
print 'Imported TSengine from ASCore' log('Imported TSengine from ASCore')
except Exception, e: except Exception, e:
print 'Error importing TSengine from ASCore. Exception: ' + str(e) log('Error importing TSengine from ASCore. Exception: ' + str(e))
return return
self.TSplayer = tsengine() self.TSplayer = tsengine()
@ -70,15 +70,14 @@ class AceStream:
self.torrentFilesDirectory = torrentFilesDirectory self.torrentFilesDirectory = torrentFilesDirectory
self.storageDirectory = storageDirectory self.storageDirectory = storageDirectory
_path = os.path.join(self.storageDirectory, self.torrentFilesDirectory) + os.sep _path = os.path.join(self.storageDirectory, self.torrentFilesDirectory) + os.sep
if re.match("^magnet\:.+$", torrentFile):
torrentFile = self.magnetToTorrent(torrentFile)
if not xbmcvfs.exists(_path): if not xbmcvfs.exists(_path):
xbmcvfs.mkdirs(_path) xbmcvfs.mkdirs(_path)
if xbmcvfs.exists(torrentFile): if xbmcvfs.exists(torrentFile):
self.torrentFile = torrentFile self.torrentFile = torrentFile
content = xbmcvfs.File(torrentFile, "rb").read() content = xbmcvfs.File(torrentFile, "rb").read()
self.torrentFileInfo = self.TSplayer.load_torrent(base64.b64encode(content), 'RAW') self.torrentFileInfo = self.TSplayer.load_torrent(base64.b64encode(content), 'RAW')
elif re.match("^magnet\:.+$", torrentFile):
magnet_alert()
exit()
def __exit__(self): def __exit__(self):
self.TSplayer.end() self.TSplayer.end()
@ -88,8 +87,8 @@ class AceStream:
def saveTorrent(self, torrentUrl): def saveTorrent(self, torrentUrl):
if re.match("^magnet\:.+$", torrentUrl): if re.match("^magnet\:.+$", torrentUrl):
magnet_alert() torrentFile = self.magnetToTorrent(torrentUrl)
exit() content = xbmcvfs.File(file_decode(torrentFile), "rb").read()
else: else:
torrentFile = self.storageDirectory + os.sep + self.torrentFilesDirectory + os.sep + self.md5( torrentFile = self.storageDirectory + os.sep + self.torrentFilesDirectory + os.sep + self.md5(
torrentUrl) + '.torrent' torrentUrl) + '.torrent'
@ -112,19 +111,23 @@ class AceStream:
localFile.write(content) localFile.write(content)
localFile.close() localFile.close()
except Exception, e: except Exception, e:
print 'Unable to save torrent file from "' + torrentUrl + '" to "' + torrentFile + '" in Torrent::saveTorrent' + '. Exception: ' + str( log('Unable to save torrent file from "' + torrentUrl + '" to "' + torrentFile +
e) '" in Torrent::saveTorrent' + '. Exception: ' + str(e))
return return
if xbmcvfs.exists(torrentFile): if xbmcvfs.exists(torrentFile):
self.torrentFile = torrentFile self.torrentFile = torrentFile
self.torrentFileInfo = self.TSplayer.load_torrent(base64.b64encode(content), 'RAW') self.torrentFileInfo = self.TSplayer.load_torrent(base64.b64encode(content), 'RAW')
return self.torrentFile return self.torrentFile
def getMagnetInfo(self):
magnet_alert()
exit()
def magnetToTorrent(self, magnet): def magnetToTorrent(self, magnet):
try:
from Libtorrent import Libtorrent
torrent = Libtorrent(self.storageDirectory, magnet)
torrent.magnetToTorrent(magnet)
self.torrentFile = torrent.torrentFile
log('[AceStream][magnetToTorrent]: self.torrentFile '+str(self.torrentFile))
return self.torrentFile
except:
magnet_alert() magnet_alert()
exit() exit()