script.module.libtorrent/python_libtorrent/__init__.py

64 lines
1.9 KiB
Python
Raw Normal View History

2015-06-28 14:40:33 +03:00
#-*- coding: utf-8 -*-
'''
Torrenter v2 plugin for XBMC/Kodi
2015-07-11 12:00:55 +03:00
Copyright (C) 2015 srg70, RussakHH, DiMartino
2015-06-28 14:40:33 +03:00
'''
2015-07-11 12:00:55 +03:00
from functions import *
import xbmc, xbmcgui, xbmcvfs, xbmcaddon
import sys
import os
__settings__ = xbmcaddon.Addon(id='script.module.libtorrent')
__version__ = __settings__.getAddonInfo('version')
__plugin__ = __settings__.getAddonInfo('name') + " v." + __version__
2015-06-28 14:40:33 +03:00
2015-07-11 23:49:53 +03:00
libtorrent=None
2015-06-28 14:40:33 +03:00
platform = get_platform()
2015-07-11 12:00:55 +03:00
dirname = os.path.join(xbmc.translatePath('special://temp'), 'xbmcup', 'script.module.libtorrent',
'python_libtorrent')
dest_path = os.path.join(dirname, platform['system'])
2015-07-11 12:45:24 +03:00
sys.path.insert(0, dest_path)
2015-07-11 12:00:55 +03:00
lm=LibraryManager(dest_path)
if not lm.check_exist():
2015-07-11 23:49:53 +03:00
ok=lm.download()
xbmc.sleep(2000)
2015-06-28 14:40:33 +03:00
2015-07-11 12:00:55 +03:00
if __settings__.getSetting('plugin_name')!=__plugin__:
__settings__.setSetting('plugin_name', __plugin__)
lm.update()
log('platform ' + str(platform))
2015-06-28 14:40:33 +03:00
try:
2015-07-11 12:45:24 +03:00
if platform['system'] in ['darwin', 'linux_x86', 'linux_x86_64', 'windows']:
import libtorrent
2015-07-13 00:28:44 +03:00
elif platform['system'] in ['android_armv7', 'android_x86']:
2015-07-11 12:00:55 +03:00
import imp
from ctypes import *
dll_path=os.path.join(dest_path, 'liblibtorrent.so')
print "CDLL path = " + dll_path
liblibtorrent=CDLL(dll_path)
2015-07-11 12:45:24 +03:00
log('CDLL = ' + str(liblibtorrent))
2015-07-11 12:00:55 +03:00
path_list = [dest_path]
2015-07-11 12:45:24 +03:00
log('path_list = ' + str(path_list))
2015-07-11 12:00:55 +03:00
fp, pathname, description = imp.find_module('libtorrent', path_list)
2015-07-11 12:45:24 +03:00
log('fp = ' + str(fp))
log('pathname = ' + str(pathname))
2015-07-12 18:54:43 +03:00
try:
libtorrent = imp.load_module('libtorrent', fp, pathname, description)
finally:
if fp: fp.close()
2015-07-11 12:00:55 +03:00
2015-07-11 12:45:24 +03:00
log('Imported libtorrent v' + libtorrent.version + ' from ' + dest_path)
2015-06-28 14:40:33 +03:00
except Exception, e:
2015-07-11 12:45:24 +03:00
log('Error importing libtorrent from' + dest_path + '. Exception: ' + str(e))
2015-07-11 12:00:55 +03:00
pass
def get_libtorrent():
return libtorrent