plugin.video.torrenter/Downloader.py

142 lines
4.3 KiB
Python
Raw Normal View History

2015-01-09 14:11:21 +03:00
# -*- coding: utf-8 -*-
'''
2015-06-30 18:08:57 +03:00
Torrenter v2 plugin for XBMC/Kodi
Copyright (C) 2012-2015 Vadim Skorba v1 - DiMartino v2
http://forum.kodi.tv/showthread.php?tid=214366
2015-01-09 14:11:21 +03:00
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
2015-06-23 23:00:27 +03:00
import hashlib
import sys
2015-01-09 14:11:21 +03:00
import Libtorrent
import AceStream
2015-12-16 23:01:36 +03:00
import Anteoloader
2015-01-09 14:11:21 +03:00
class Torrent():
__settings__ = sys.modules["__main__"].__settings__
def __init__(self, storageDirectory='', torrentFile='', torrentFilesDirectory='torrents'):
self.get_torrent_client()
if self.player == 'libtorrent':
self.player = Libtorrent.Libtorrent(storageDirectory, torrentFile, torrentFilesDirectory)
elif self.player == 'acestream':
self.player = AceStream.AceStream(storageDirectory, torrentFile, torrentFilesDirectory)
2015-12-16 23:01:36 +03:00
elif self.player == 'anteo':
2015-12-16 23:55:38 +03:00
self.player = Anteoloader.AnteoLoader(storageDirectory, torrentFile, torrentFilesDirectory)
2015-12-16 23:01:36 +03:00
2015-01-09 14:11:21 +03:00
def __exit__(self):
self.player.__exit__()
def get_torrent_client(self):
player = self.__settings__.getSetting("torrent_player")
2015-12-16 23:01:36 +03:00
if player == '0':
2015-01-09 14:11:21 +03:00
self.player = 'libtorrent'
elif player == '1':
self.player = 'acestream'
2015-12-16 23:01:36 +03:00
elif player == '2':
self.player = 'anteo'
2015-01-09 14:11:21 +03:00
def play_url_ind(self, ind, label, icon):
return self.player.play_url_ind(int(ind), label, str(icon))
def saveTorrent(self, torrentUrl):
return self.player.saveTorrent(torrentUrl)
def getMagnetInfo(self):
return self.player.getMagnetInfo()
def magnetToTorrent(self, magnet):
return self.player.magnetToTorrent(magnet)
def getUploadRate(self):
return self.player.getUploadRate()
def getDownloadRate(self):
return self.player.getDownloadRate()
def getPeers(self):
return self.player.getPeers()
def getSeeds(self):
2015-12-17 21:17:40 +03:00
return self.player.getSeeds()
2015-01-09 14:11:21 +03:00
def getFileSize(self, contentId=0):
return self.player.getFileSize(contentId)
def getFilePath(self, contentId=0):
return self.player.getFilePath(contentId)
def getContentList(self):
2015-06-23 23:00:27 +03:00
# print str(self.player.getContentList())
2015-01-09 14:11:21 +03:00
return self.player.getContentList()
def setUploadLimit(self, bytesPerSecond):
return self.player.setUploadLimit(bytesPerSecond)
def setDownloadLimit(self, bytesPerSecond):
return self.player.setDownloadLimit(bytesPerSecond)
def stopSession(self):
return self.player.stopSession()
def md5(self, string):
hasher = hashlib.md5()
try:
hasher.update(string)
except:
hasher.update(string.encode('utf-8', 'ignore'))
return hasher.hexdigest()
2015-06-28 18:14:36 +03:00
def downloadProcess(self, contentId=None, encrytion=True):
return self.player.downloadProcess(contentId, encrytion)
2015-01-09 14:11:21 +03:00
def initSession(self):
return self.player.initSession()
2015-06-28 18:04:09 +03:00
def encryptSession(self):
return self.player.encryptSession()
2015-01-09 14:11:21 +03:00
def startSession(self):
return self.player.startSession()
def continueSession(self, contentId=0, Offset=155, seeding=True):
return self.player.continueSession(contentId, Offset, seeding)
def addToSeeding(self):
return self.player.addToSeeding()
def fetchParts(self):
return self.player.fetchParts()
def checkThread(self):
return self.player.checkThread()
def _makedirs(self, _path):
return self.player._makedirs(_path)
def debug(self):
return self.player.debug()
def dump(self, obj):
for attr in dir(obj):
try:
print "'%s':'%s'," % (attr, getattr(obj, attr))
except:
2015-06-23 23:00:27 +03:00
pass