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 *
|
2015-07-17 20:53:52 +03:00
|
|
|
import xbmc, xbmcaddon
|
2015-07-11 12:00:55 +03:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
|
|
|
__settings__ = xbmcaddon.Addon(id='script.module.libtorrent')
|
|
|
|
__version__ = __settings__.getAddonInfo('version')
|
|
|
|
__plugin__ = __settings__.getAddonInfo('name') + " v." + __version__
|
2015-07-20 21:12:38 +03:00
|
|
|
__language__ = __settings__.getLocalizedString
|
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-20 21:12:38 +03:00
|
|
|
set_dirname=__settings__.getSetting('dirname')
|
|
|
|
if getSettingAsBool('custom_dirname') and set_dirname:
|
2015-08-03 20:23:45 +03:00
|
|
|
log('set_dirname:' +str(set_dirname))
|
2015-07-20 21:12:38 +03:00
|
|
|
dirname=set_dirname
|
|
|
|
else:
|
|
|
|
dirname = os.path.join(xbmc.translatePath('special://temp'), 'xbmcup', 'script.module.libtorrent',
|
|
|
|
'python_libtorrent')
|
|
|
|
|
|
|
|
log('dirname:' +str(dirname))
|
2015-08-02 16:04:40 +03:00
|
|
|
|
2015-08-08 23:23:17 +03:00
|
|
|
default_version = 0 #[0.16.19, 1.0.6]
|
2015-08-03 20:23:45 +03:00
|
|
|
set_version = __settings__.getSetting('set_version')
|
|
|
|
default_path = __language__(1150+default_version)
|
2015-08-02 16:04:40 +03:00
|
|
|
if getSettingAsBool('custom_version'):
|
2015-08-03 20:23:45 +03:00
|
|
|
log('set_version:' +str(set_version)+' '+__language__(1150+int(set_version)))
|
2015-08-02 16:04:40 +03:00
|
|
|
platform['version'] = __language__(1150+int(set_version))
|
|
|
|
else:
|
2015-08-03 20:23:45 +03:00
|
|
|
platform['version'] = default_path
|
2015-08-02 16:04:40 +03:00
|
|
|
|
2015-08-03 20:23:45 +03:00
|
|
|
if not os.path.exists(os.path.join(os.path.dirname(__file__), platform['system'], platform['version'])):
|
|
|
|
log('set_version: back to default '+default_path)
|
|
|
|
platform['version'] = default_path
|
2015-08-02 16:04:40 +03:00
|
|
|
dest_path = os.path.join(dirname, platform['system'], platform['version'])
|
2015-07-11 12:45:24 +03:00
|
|
|
sys.path.insert(0, dest_path)
|
2015-07-11 12:00:55 +03:00
|
|
|
|
2015-08-02 16:14:05 +03:00
|
|
|
lm=LibraryManager(dest_path, platform)
|
2015-07-11 12:00:55 +03:00
|
|
|
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()
|
|
|
|
|
2015-07-15 20:39:42 +03:00
|
|
|
log('platform: ' + str(platform))
|
2015-07-16 21:12:26 +03:00
|
|
|
if platform['system'] not in ['windows']:
|
|
|
|
log('os: '+str(os.uname()))
|
|
|
|
|
2015-06-28 14:40:33 +03:00
|
|
|
try:
|
2015-07-30 21:35:28 +03:00
|
|
|
if platform['system'] in ['linux_x86', 'windows', 'linux_armv6', 'linux_armv7', 'linux_x86_64']:
|
2015-07-11 12:45:24 +03:00
|
|
|
import libtorrent
|
2015-07-16 21:12:26 +03:00
|
|
|
elif platform['system'] in ['darwin']:
|
2015-07-16 23:56:06 +03:00
|
|
|
import imp
|
|
|
|
path_list = [dest_path]
|
|
|
|
log('path_list = ' + str(path_list))
|
|
|
|
fp, pathname, description = imp.find_module('libtorrent', path_list)
|
|
|
|
log('fp = ' + str(fp))
|
|
|
|
log('pathname = ' + str(pathname))
|
|
|
|
try:
|
|
|
|
libtorrent = imp.load_module('libtorrent', fp, pathname, description)
|
|
|
|
finally:
|
|
|
|
if fp: fp.close()
|
2015-07-13 00:28:44 +03:00
|
|
|
elif platform['system'] in ['android_armv7', 'android_x86']:
|
2015-07-26 12:59:08 +03:00
|
|
|
import imp
|
|
|
|
from ctypes import CDLL
|
2015-07-12 18:54:43 +03:00
|
|
|
try:
|
2015-07-26 12:59:08 +03:00
|
|
|
dll_path=os.path.join(dest_path, 'liblibtorrent.so')
|
|
|
|
log('CDLL path = ' + dll_path)
|
2015-07-24 18:00:27 +03:00
|
|
|
liblibtorrent=CDLL(dll_path)
|
|
|
|
log('CDLL = ' + str(liblibtorrent))
|
2015-07-26 12:59:08 +03:00
|
|
|
except:
|
|
|
|
# If no permission in dest_path we need to go deeper!
|
2015-07-28 20:17:37 +03:00
|
|
|
try:
|
|
|
|
dest_path=lm.android_workaround(new_dest_path='/data/data/org.xbmc.kodi/lib/')
|
|
|
|
dll_path=os.path.join(dest_path, 'liblibtorrent.so')
|
|
|
|
log('NEW CDLL path = ' + dll_path)
|
|
|
|
liblibtorrent=CDLL(dll_path)
|
|
|
|
log('CDLL = ' + str(liblibtorrent))
|
|
|
|
except:
|
|
|
|
# http://i3.kym-cdn.com/photos/images/original/000/531/557/a88.jpg
|
|
|
|
dest_path=lm.android_workaround(new_dest_path=xbmc.translatePath('special://xbmc'))
|
|
|
|
dll_path=os.path.join(dest_path, 'liblibtorrent.so')
|
|
|
|
log('NEW CDLL path = ' + dll_path)
|
|
|
|
liblibtorrent=CDLL(dll_path)
|
|
|
|
log('CDLL = ' + str(liblibtorrent))
|
2015-07-26 12:59:08 +03:00
|
|
|
liblibtorrent=CDLL(dll_path)
|
|
|
|
log('CDLL = ' + str(liblibtorrent))
|
|
|
|
path_list = [dest_path]
|
|
|
|
log('path_list = ' + str(path_list))
|
|
|
|
fp, pathname, description = imp.find_module('libtorrent', path_list)
|
|
|
|
log('fp = ' + str(fp))
|
|
|
|
log('pathname = ' + str(pathname))
|
|
|
|
try:
|
|
|
|
libtorrent = imp.load_module('libtorrent', fp, pathname, description)
|
|
|
|
finally:
|
|
|
|
if fp: fp.close()
|
2015-07-11 12:00:55 +03:00
|
|
|
|
2015-07-24 18:00:27 +03:00
|
|
|
log('Imported libtorrent v' + libtorrent.version + ' from "' + dest_path + '"')
|
2015-06-28 14:40:33 +03:00
|
|
|
|
|
|
|
except Exception, e:
|
2015-07-24 18:00:27 +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
|