Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import xbmc
- import xbmcaddon
- import xbmcgui
- import xbmcplugin
- import os
- import subprocess
- import base64
- import sys
- import xbmcvfs
- import atexit
- import requests
- import shutil
- import urllib
- import urllib2
- import cookielib
- import re
- import extract
- import downloader
- import time
- import json
- import plugintools
- from ConfigParser import SafeConfigParser
- from addon.common.addon import Addon
- from addon.common.net import Net
- try:
- from hashlib import sha1
- except ImportError: # python 2.4 compat
- from sha import sha as sha1
- AddonID = 'plugin.video.paradoxwizard'
- ADDON = xbmcaddon.Addon(id=AddonID)
- VERSION = "1.0.8.5"
- ADDONPATH = xbmc.translatePath(
- os.path.join('special://home/addons/' + AddonID))
- AddonTitle = "Paradox Wizard"
- USER_AGENT = 'Kodi/Paradox Wizard'
- U = plugintools.get_setting('username')
- P = plugintools.get_setting('password')
- M = plugintools.get_setting('submessage')
- dialog = xbmcgui.Dialog()
- net = Net()
- BASEURL = "http://theblackboxostv.co.uk/"
- CHECKURL = BASEURL + "wizard-dev.php"
- ART = xbmc.translatePath(os.path.join(
- 'special://home/addons/' + AddonID + '/resources/art/'))
- DBPATH = xbmc.translatePath('special://database')
- TNPATH = xbmc.translatePath('special://thumbnails')
- SKIN = xbmc.getSkinDir()
- USERDATA = xbmc.translatePath(os.path.join('special://profile',''))
- ADDON_DATA = xbmc.translatePath(os.path.join(USERDATA,'addon_data'))
- SKINPATH = xbmc.translatePath(os.path.join(ADDON_DATA,SKIN))
- GUISETTINGS = xbmc.translatePath(os.path.join(USERDATA,'guisettings.xml'))
- SKINSETTINGS = xbmc.translatePath(os.path.join(SKINPATH,'settings.xml'))
- FAVS = xbmc.translatePath(os.path.join(USERDATA,'favourites.xml'))
- SOURCE = xbmc.translatePath(os.path.join(USERDATA,'sources.xml'))
- ADVANCED = xbmc.translatePath(os.path.join(USERDATA,'advancedsettings.xml'))
- RSS = xbmc.translatePath(os.path.join(USERDATA,'RssFeeds.xml'))
- KEYMAPS = xbmc.translatePath(os.path.join(USERDATA,'keymaps','keyboard.xml'))
- ADDONS = xbmc.translatePath(os.path.join('special://home','addons'))
- USB = ADDONPATH
- EXCLUDES = ['plugin.video.paradoxwizard', 'script.module.addon.common',
- 'repository.paradox', 'script.module.requests']
- FANART = ART + 'fanart.png'
- ICON = ART + 'icon.png'
- # set some default icons
- INSTALLICON = ART + 'install.png'
- MAINTAINANCEICON = ART + 'maintenance.png'
- CONTACTICON = ART + 'contact.png'
- CLEARCACHEICON = ART + 'clear-cache.png'
- FRESHSTARTICON = ART + 'fresh-start.png'
- PURGEICON = ART + 'purge.png'
- FORCESTOP = ART + 'force-stop.png'
- SETTINGSICON = ART + 'settings.png'
- THUMBSICON = ART + 'thumbs.png'
- BACKUPICON = ART + 'backup.png'
- RESTOREICON = ART + 'restore.png'
- # Grab the mac address encase we need it later!
- MAC_ADDRESS = xbmc.getInfoLabel('Network.MacAddress')
- # Firstrun marker
- FIRSTRUN = True
- def DoE(e): xbmc.executebuiltin(e)
- def DoAW(e): xbmc.executebuiltin("ActivateWindow(%s)" % str(e))
- def DoRW(e): xbmc.executebuiltin("ReplaceWindow(%s)" % str(e))
- def DoRA(e): xbmc.executebuiltin("RunAddon(%s)" % str(e))
- def DoRA2(e, e2="1", e3=""): xbmc.executebuiltin(
- 'RunAddon(%s,"%s","%s")' % (str(e), str(e2), e3))
- def DoA(a): xbmc.executebuiltin("Action(%s)" % str(a))
- def DoCM(a): xbmc.executebuiltin("Control.Message(windowid=%s)" % (str(a)))
- def DoSC(a): xbmc.executebuiltin("SendClick(%s)" % (str(a)))
- def DoSC2(a, Id): xbmc.executebuiltin("SendClick(%s,%s)" % (str(a), str(Id)))
- def DoStopScript(e): xbmc.executebuiltin("StopScript(%s)" % str(e))
- def DoTD(): xbmc.executebuiltin("ToggleDebug")
- def script_chk(script_name):
- return xbmc.getCondVisibility('System.HasAddon(%s)' % script_name) == 1
- # Anything that needs to be run before the script init's
- def SETUP():
- global INSTALLICON, MAINTAINANCEICON, CONTACTICON, CLEARCACHEICON, FRESHSTARTICON, PURGEICON, SETTINGSICON, M
- # See if we can update the logos used
- # logopath = "http://paradoxwizard.co.uk/icon/paradox-wizard-icons.cfg"
- # path = xbmc.translatePath(os.path.join('special://home/addons','packages/'))
- # downloader.download(logopath, path + "/paradox-wizard-icons.cfg")
- # icons = SafeConfigParser()
- # icons.read(path + "/paradox-wizard-icons.cfg")
- # INSTALLICON = str(icons.get('icons', 'installicon'))
- # MAINTAINANCEICON = str(icons.get('icons', 'maintainanceicon'))
- # CONTACTICON = str(icons.get('icons', 'contacticon'))
- # CLEARCACHEICON = str(icons.get('icons', 'clearcacheicon'))
- # FRESHSTARTICON = str(icons.get('icons', 'freshstarticon'))
- # PURGEICON = str(icons.get('icons', 'purgeicon'))
- # FORCESTOP = str(icons.get('icons', 'forcestop'))
- # FANART = str(icons.get('icons', 'fanart'))
- # repo_installed = script_chk("repository.paradox")
- # if repo_installed:
- # plugintools.message(AddonTitle, "Would you like to install the Paradox Repository?")
- # DoRA("repository.paradox")
- if U == "" and P == "" and M == "false":
- msg1 = "Please register an account at http://theblackboxostv.co.uk and enter your forum username and password in the wizard settings panel to continue. "
- msg2 = "Would you like to enter your username and password now?"
- yes_pressed = plugintools.message_yes_no(AddonTitle + " - Authentication", msg1, msg2)
- plugintools.set_setting('submessage', 'true')
- if yes_pressed:
- opensettings()
- INDEX()
- # Inital Menu
- def INDEX():
- addDir('Install Paradox', BASEURL, 2, INSTALLICON, FANART, '')
- addDir('Maintenance', BASEURL, 3, MAINTAINANCEICON, FANART, '')
- addDir('Settings', BASEURL, 15, SETTINGSICON, FANART, '')
- setView('movies', 'MAIN')
- # Build Menu
- def BUILDMENU():
- data = OPEN_URL(CHECKURL + "?action=listbuilds&user=" + str(U) + "&pass=" + str(smf_hash(P, U)))
- parsed = json.loads(data)
- for build in parsed:
- addDir(build['bfriendlyname'] + ' - ' + build['bversion'],build['bslug'], 5, build['bicon'], FANART, '')
- setView('movies', 'MAIN')
- # Maintenance menu
- def MAINTENANCE():
- addDir('Purge Packages', 'url', 7, PURGEICON, FANART, 'Delete any downloaded packeages')
- addDir('Clear Cache', 'url', 4, CLEARCACHEICON, FANART, 'Delete Kodis cached files to free up space on your device')
- addDir('Clear Thumbnails', 'url', 16, THUMBSICON, FANART, 'Clear the thumbnail library')
- addDir('Fresh Start', 'url', 6, FRESHSTARTICON, FANART, 'Reset your Kodi to its default settings, this will remove all addons, settings and skins')
- addDir('Backup/Restore', 'url', 17, BACKUPICON, FANART, 'Back Up Your settings.xml')
- addDir('Force Close', 'url', 10, FORCESTOP, FANART, 'Force Kodi to shut down instantly')
- setView('movies', 'MAIN')
- # Install builds
- def WIZARD(name, url, description):
- whatami = platform()
- whattodo = plugintools.selector(title="Please Select", option_list=[ "View Change Log", "Install " + name])
- if whattodo == 0:
- burl = CHECKURL + "?action=changelog&devos=" + str(whatami) + "&build=" + str(url) + "&user=" + str(U) + "&pass=" + str(smf_hash(P, U))
- data = OPEN_URL(burl)
- parsed = json.loads(data)
- build = str(parsed.get('bfriendlyname'))
- version = str(parsed.get('bversion'))
- cltext = str(parsed.get('bchangelog'))
- changelog("Change Log","[COLOR=yellow]" + build + "[/COLOR][CR][CR]" + cltext)
- elif whattodo == 1:
- # User has chosen to install the build so fire it up!
- xbmc.executebuiltin("ActivateWindow(busydialog)")
- # Check the username and password set in the wizard
- burl = CHECKURL + "?action=getbuild&devos=" + str(whatami) + "&build=" + str(url) + "&user=" + str(U) + "&pass=" + str(smf_hash(P, U))
- data = OPEN_URL(burl)
- parsed = json.loads(data)
- build = str(parsed.get('bfriendlyname'))
- version = str(parsed.get('bversion'))
- # See if we have a version file
- versionpath = xbmc.translatePath(os.path.join('special://', 'home'))
- versionfile = versionpath + 'version.txt'
- versionfileexists = os.path.isfile(versionfile)
- parser = SafeConfigParser()
- parser.read(versionfile)
- tempfolder = xbmc.translatePath(
- os.path.join('special://', 'home', 'temp'))
- # Removing this as it causes problems for people that get the Kodi screen following install
- #
- # Check the version of the build against the latest available version
- # if versionfileexists and parser.get('versioninfo', 'version') == version and parser.get('versioninfo', 'build') == build:
- # dialog = xbmcgui.Dialog()
- # xbmc.executebuiltin("Dialog.Close(busydialog)")
- # dialog.ok(AddonTitle, "You already have the most recent version", "", str(
- # parser.get('versioninfo', 'build')) + " " + str(parser.get('versioninfo', 'version')))
- # else:
- path = xbmc.translatePath(os.path.join(
- 'special://home/addons', 'packages/'))
- fileexists = os.path.isfile(path + url + version + '.zip')
- existingfile = os.path.join(path + url + version + '.zip')
- if fileexists:
- lib = existingfile
- dp = xbmcgui.DialogProgress()
- xbmc.executebuiltin("Dialog.Close(busydialog)")
- addonfolder = xbmc.translatePath(
- os.path.join('special://', 'home'))
- time.sleep(2)
- dp.create(AddonTitle, "Extracting " + name, "Please Wait...")
- extract.all(lib, addonfolder, dp)
- # copytree(tempfolder, addonfolder)
- # shutil.rmtree(tempfolder)
- dp.close()
- ADDON.setSetting(id="username", value="")
- ADDON.setSetting(id="password", value="")
- plugintools.message(AddonTitle, name + " has been installed from your existing packages")
- plugintools.message(AddonTitle, " ", "To save changes you now need to force close Kodi, Press OK to force close Kodi")
- killxbmc()
- else:
- if parsed.get('auth'):
- rid = parsed.get('recid')
- dlurl = parsed.get('bdlurl')
- if parsed.get('brsurl'):
- dlurl = parsed.get('brsurl')
- dp = xbmcgui.DialogProgress()
- xbmc.executebuiltin("Dialog.Close(busydialog)")
- # if whatami == "windows":
- # FRESHSTARTBUILD(params)
- dp.create(AddonTitle, "Downloading " + parsed.get('bfriendlyname') +
- " - " + parsed.get('bversion'), "Please Wait...")
- lib = existingfile
- # added to remove any partially downloaded files
- try:
- downloader.download(dlurl, lib, dp)
- except Exception as e:
- if str(e) == "Canceled":
- os.remove(lib)
- return
- addonfolder = xbmc.translatePath(
- os.path.join('special://', 'home'))
- tempfolder = xbmc.translatePath(
- os.path.join('special://', 'home', 'temp'))
- time.sleep(2)
- dp.update(0, "", "Extracting " +
- parsed.get('bfriendlyname') + " Zip", "Please Wait...")
- extract.all(lib, addonfolder, dp)
- dp.close()
- successdata = OPEN_URL(CHECKURL + "?action=installed&instid=" + str(rid) + "&user=" + str(U) + "&pass=" + str(smf_hash(P, U)))
- suceess = json.loads(successdata)
- plugintools.message(AddonTitle, suceess.get('mtit'), suceess.get('mmsg'))
- plugintools.message(AddonTitle, "To save changes you now need to force close Kodi, Press OK to force close Kodi")
- ADDON.setSetting(id="username", value="")
- ADDON.setSetting(id="password", value="")
- killxbmc()
- else:
- xbmc.executebuiltin("Dialog.Close(busydialog)")
- yes_pressed = plugintools.message_yes_no(AddonTitle, parsed.get('etit'), "Do you want to open settings now?")
- if yes_pressed:
- opensettings()
- # Open URL (Changed to use urllib2.request)
- def OPEN_URL(url):
- headers = {
- 'User-Agent': USER_AGENT
- }
- sess = requests.session()
- req = sess.get(url, headers=headers)
- link = req.content
- req.close()
- return link
- # Delete Packages
- def DeletePackages(url):
- packages_cache_path = xbmc.translatePath(
- os.path.join('special://home/addons/packages', ''))
- if plugintools.message_yes_no(AddonTitle, "Are you sure you want to purge all packages?"):
- try:
- for root, dirs, files in os.walk(packages_cache_path):
- file_count = 0
- file_count += len(files)
- # Count files and give option to delete
- if file_count > 0:
- if plugintools.message_yes_no("Delete Package Cache Files", str(file_count) + " files found", "Do you want to delete them?"):
- for f in files:
- os.unlink(os.path.join(root, f))
- for d in dirs:
- shutil.rmtree(os.path.join(root, d))
- plugintools.message(AddonTitle, "Packages Successfuly Removed")
- except:
- plugintools.message(AddonTitle, "Sorry we were not able to remove Package Files")
- else:
- plugintools.message(AddonTitle, "No packages have been removed")
- # Delete Cache
- def deletecachefiles(url):
- xbmc_cache_path = os.path.join(
- xbmc.translatePath('special://home'), 'cache')
- if plugintools.message_yes_no("Clear Cache", "Are you sure you want to clear the cache?"):
- if os.path.exists(xbmc_cache_path) == True:
- for root, dirs, files in os.walk(xbmc_cache_path):
- file_count = 0
- file_count += len(files)
- # Count files and give option to delete
- if file_count > 0:
- dialog = xbmcgui.Dialog()
- if dialog.yesno("Delete Cache Files", str(file_count) + " files found", "Do you want to delete them?"):
- for f in files:
- try:
- os.unlink(os.path.join(root, f))
- except:
- pass
- for d in dirs:
- try:
- shutil.rmtree(os.path.join(root, d))
- except:
- pass
- else:
- pass
- if xbmc.getCondVisibility('system.platform.ATV2'):
- atv2_cache_a = os.path.join(
- '/private/var/mobile/Library/Caches/AppleTV/Video/', 'Other')
- for root, dirs, files in os.walk(atv2_cache_a):
- file_count = 0
- file_count += len(files)
- if file_count > 0:
- dialog = xbmcgui.Dialog()
- if dialog.yesno("Delete ATV2 Cache Files", str(file_count) + " files found in 'Other'", "Do you want to delete them?"):
- for f in files:
- os.unlink(os.path.join(root, f))
- for d in dirs:
- shutil.rmtree(os.path.join(root, d))
- else:
- pass
- atv2_cache_b = os.path.join(
- '/private/var/mobile/Library/Caches/AppleTV/Video/', 'LocalAndRental')
- for root, dirs, files in os.walk(atv2_cache_b):
- file_count = 0
- file_count += len(files)
- if file_count > 0:
- dialog = xbmcgui.Dialog()
- if dialog.yesno("Delete ATV2 Cache Files", str(file_count) + " files found in 'LocalAndRental'", "Do you want to delete them?"):
- for f in files:
- os.unlink(os.path.join(root, f))
- for d in dirs:
- shutil.rmtree(os.path.join(root, d))
- else:
- pass
- # Set path to Cydia Archives cache files
- # Set path to What th Furk cache files
- wtf_cache_path = os.path.join(xbmc.translatePath(
- 'special://profile/addon_data/plugin.video.whatthefurk/cache'), '')
- if os.path.exists(wtf_cache_path) == True:
- for root, dirs, files in os.walk(wtf_cache_path):
- file_count = 0
- file_count += len(files)
- # Count files and give option to delete
- if file_count > 0:
- dialog = xbmcgui.Dialog()
- if dialog.yesno("Delete WTF Cache Files", str(file_count) + " files found", "Do you want to delete them?"):
- for f in files:
- os.unlink(os.path.join(root, f))
- for d in dirs:
- shutil.rmtree(os.path.join(root, d))
- else:
- pass
- # Set path to 4oD cache files
- channel4_cache_path = os.path.join(xbmc.translatePath(
- 'special://profile/addon_data/plugin.video.4od/cache'), '')
- if os.path.exists(channel4_cache_path) == True:
- for root, dirs, files in os.walk(channel4_cache_path):
- file_count = 0
- file_count += len(files)
- # Count files and give option to delete
- if file_count > 0:
- dialog = xbmcgui.Dialog()
- if dialog.yesno("Delete 4oD Cache Files", str(file_count) + " files found", "Do you want to delete them?"):
- for f in files:
- os.unlink(os.path.join(root, f))
- for d in dirs:
- shutil.rmtree(os.path.join(root, d))
- else:
- pass
- # Set path to BBC iPlayer cache files
- iplayer_cache_path = os.path.join(xbmc.translatePath(
- 'special://profile/addon_data/plugin.video.iplayer/iplayer_http_cache'), '')
- if os.path.exists(iplayer_cache_path) == True:
- for root, dirs, files in os.walk(iplayer_cache_path):
- file_count = 0
- file_count += len(files)
- # Count files and give option to delete
- if file_count > 0:
- dialog = xbmcgui.Dialog()
- if dialog.yesno("Delete BBC iPlayer Cache Files", str(file_count) + " files found", "Do you want to delete them?"):
- for f in files:
- os.unlink(os.path.join(root, f))
- for d in dirs:
- shutil.rmtree(os.path.join(root, d))
- else:
- pass
- # Set path to Simple Downloader cache files
- downloader_cache_path = os.path.join(xbmc.translatePath(
- 'special://profile/addon_data/script.module.simple.downloader'), '')
- if os.path.exists(downloader_cache_path) == True:
- for root, dirs, files in os.walk(downloader_cache_path):
- file_count = 0
- file_count += len(files)
- # Count files and give option to delete
- if file_count > 0:
- dialog = xbmcgui.Dialog()
- if dialog.yesno("Delete Simple Downloader Cache Files", str(file_count) + " files found", "Do you want to delete them?"):
- for f in files:
- os.unlink(os.path.join(root, f))
- for d in dirs:
- shutil.rmtree(os.path.join(root, d))
- else:
- pass
- # Set path to ITV cache files
- itv_cache_path = os.path.join(xbmc.translatePath(
- 'special://profile/addon_data/plugin.video.itv/Images'), '')
- if os.path.exists(itv_cache_path) == True:
- for root, dirs, files in os.walk(itv_cache_path):
- file_count = 0
- file_count += len(files)
- # Count files and give option to delete
- if file_count > 0:
- dialog = xbmcgui.Dialog()
- if dialog.yesno("Delete ITV Cache Files", str(file_count) + " files found", "Do you want to delete them?"):
- for f in files:
- os.unlink(os.path.join(root, f))
- for d in dirs:
- shutil.rmtree(os.path.join(root, d))
- else:
- pass
- # Set path to temp cache files
- temp_cache_path = os.path.join(
- xbmc.translatePath('special://home/temp'), '')
- if os.path.exists(temp_cache_path) == True:
- for root, dirs, files in os.walk(temp_cache_path):
- file_count = 0
- file_count += len(files)
- # Count files and give option to delete
- if file_count > 0:
- dialog = xbmcgui.Dialog()
- if dialog.yesno("Delete TEMP dir Cache Files", str(file_count) + " files found", "Do you want to delete them?"):
- for f in files:
- os.unlink(os.path.join(root, f))
- for d in dirs:
- shutil.rmtree(os.path.join(root, d))
- else:
- pass
- plugintools.message(AddonTitle, "All Cache Files Removed")
- else:
- plugintools.message(AddonTitle, "No files have been removed")
- # Delete thumbnails
- def deleteThumbnails(url):
- if plugintools.message_yes_no(AddonTitle, "Are you sure you want to delete all thumbnails?"):
- if os.path.exists(TNPATH) == True:
- for root, dirs, files in os.walk(TNPATH):
- file_count = 0
- file_count += len(files)
- if file_count > 0:
- for f in files:
- try:
- os.unlink(os.path.join(root, f))
- except:
- pass
- plugintools.message(AddonTitle, " All Thumbnails Removed","Please restart Kodi to rebuild thumbnail library")
- else:
- plugintools.message(AddonTitle, "No thumbnails have been romoved")
- # Kill Kodi
- def killxbmc():
- choice = plugintools.message_yes_no('Force Close Kodi', 'You are about to close Kodi','Would you like to continue?')
- if choice == 0:
- return
- elif choice == 1:
- pass
- myplatform = platform()
- print "Platform: " + str(myplatform)
- try:
- os._exit(1)
- except:
- pass
- if myplatform == 'osx': # OSX
- print "############ try osx force close #################"
- try:
- os.system('killall -9 XBMC')
- except:
- pass
- try:
- os.system('killall -9 Kodi')
- except:
- pass
- plugintools.message(AddonTitle, "If you\'re seeing this message it means the force close","was unsuccessful. Please force close XBMC/Kodi [COLOR=lime]DO NOT[/COLOR] exit cleanly via the menu.", '')
- elif myplatform == 'linux': # Linux
- print "############ try linux force close #################"
- try:
- os.system('killall XBMC')
- except:
- pass
- try:
- os.system('killall Kodi')
- except:
- pass
- try:
- os.system('killall -9 xbmc.bin')
- except:
- pass
- try:
- os.system('killall -9 kodi.bin')
- except:
- pass
- plugintools.message(AddonTitle, "If you\'re seeing this message it means the force close","was unsuccessful. Please force close XBMC/Kodi [COLOR=lime]DO NOT[/COLOR] exit cleanly via the menu.", '')
- elif myplatform == 'android': # Android
- print "############ try android force close #################"
- try:
- os._exit(1)
- except:
- pass
- try:
- os.system('adb shell am force-stop org.xbmc.kodi')
- except:
- pass
- try:
- os.system('adb shell am force-stop org.kodi')
- except:
- pass
- try:
- os.system('adb shell am force-stop org.xbmc.xbmc')
- except:
- pass
- try:
- os.system('adb shell am force-stop org.xbmc')
- except:
- pass
- try:
- os.system('adb shell am force-stop com.semperpax.spmc16')
- except:
- pass
- try:
- os.system('adb shell am force-stop com.spmc16')
- except:
- pass
- time.sleep(5)
- plugintools.message(AddonTitle,"Press the HOME button on your remote and [COLOR=red][b]FORCE STOP[/b][/COLOR] KODI via the Manage Installed Applications menu in settings on your Amazon home page then re-launch KODI")
- elif myplatform == 'windows': # Windows
- print "############ try windows force close #################"
- try:
- os.system('@ECHO off')
- os.system('tskill XBMC.exe')
- except:
- pass
- try:
- os.system('@ECHO off')
- os.system('tskill Kodi.exe')
- except:
- pass
- try:
- os.system('@ECHO off')
- os.system('TASKKILL /im Kodi.exe /f')
- except:
- pass
- try:
- os.system('@ECHO off')
- os.system('TASKKILL /im XBMC.exe /f')
- except:
- pass
- plugintools.message(AddonTitle, "If you\'re seeing this message it means the force close","was unsuccessful. Please force close XBMC/Kodi [COLOR=lime]DO NOT[/COLOR] exit cleanly via the menu.", "Use task manager and NOT ALT F4")
- else: # ATV
- print "############ try atv force close #################"
- try:
- os.system('killall AppleTV')
- except:
- pass
- print "############ try raspbmc force close #################" # OSMC / Raspbmc
- try:
- os.system('sudo initctl stop kodi')
- except:
- pass
- try:
- os.system('sudo initctl stop xbmc')
- except:
- pass
- plugintools.message(AddonTitle, "If you\'re seeing this message it means the force close", "was unsuccessful. Please force close XBMC/Kodi [COLOR=lime]DO NOT[/COLOR] exit via the menu.","iOS detected. Press and hold both the Sleep/Wake and Home button for at least 10 seconds, until you see the Apple logo.")
- # Get Current platform
- def platform():
- if xbmc.getCondVisibility('system.platform.android'):
- return 'android'
- elif xbmc.getCondVisibility('system.platform.linux'):
- return 'linux'
- elif xbmc.getCondVisibility('system.platform.windows'):
- return 'windows'
- elif xbmc.getCondVisibility('system.platform.osx'):
- return 'osx'
- elif xbmc.getCondVisibility('system.platform.atv2'):
- return 'atv2'
- elif xbmc.getCondVisibility('system.platform.ios'):
- return 'ios'
- # Fresh start
- def FRESHSTART(params):
- plugintools.log("freshstart.main_list " + repr(params))
- yes_pressed = plugintools.message_yes_no(AddonTitle, "Do you wish to restore your", "Kodi configuration to default settings?")
- if yes_pressed:
- addonPath = xbmcaddon.Addon(id=AddonID).getAddonInfo('path')
- addonPath = xbmc.translatePath(addonPath)
- xbmcPath = os.path.join(addonPath, "..", "..")
- xbmcPath = os.path.abspath(xbmcPath)
- plugintools.log("freshstart.main_list xbmcPath=" + xbmcPath)
- failed = False
- try:
- for root, dirs, files in os.walk(xbmcPath, topdown=True):
- dirs[:] = [d for d in dirs if d not in EXCLUDES]
- for name in files:
- try:
- os.remove(os.path.join(root, name))
- except:
- if name not in ["Addons15.db", "MyVideos75.db", "Textures13.db", "xbmc.log"]:
- failed = True
- plugintools.log("Error removing " + root + " " + name)
- for name in dirs:
- try:
- os.rmdir(os.path.join(root, name))
- except:
- if name not in ["Database", "userdata"]:
- failed = True
- plugintools.log("Error removing " + root + " " + name)
- if not failed:
- plugintools.log("freshstart.main_list All user files removed, you now have a clean install")
- plugintools.message(AddonTitle, "The process is complete", "click OK to begin clean installation")
- else:
- plugintools.log("freshstart.main_list User files partially removed")
- plugintools.message(AddonTitle, "The process is complete", "click OK to begin clean installation")
- except:
- plugintools.message(AddonTitle, "Problem found","Your settings has not been changed")
- import traceback
- plugintools.log(traceback.format_exc())
- plugintools.log("freshstart.main_list NOT removed")
- force_close = plugintools.message_yes_no(AddonTitle, "To complete the fresh start, you need to force close Kodi", "Do you want to force close now?")
- if force_close:
- killxbmc()
- else:
- plugintools.message(AddonTitle, "Your settings have not been changed")
- plugintools.add_item(action="", title="Done", folder=False)
- # Fix bad zip files
- def fixBadZipfile(zipFile):
- f = open(zipFile, 'r+b')
- data = f.read()
- pos = data.find('\x50\x4b\x05\x06') # End of central directory signature
- if (pos > 0):
- print "Trancating file at location " + str(pos + 22) + "."
- f.seek(pos + 22) # size of 'ZIP end of central directory record'
- f.truncate()
- f.close()
- else:
- pass
- # raise error, file is truncated
- # SMF Password Hashing
- def smf_hash(password, username):
- """
- Python implementation of the smf check hash function
- """
- return sha1(username.lower().encode('utf8') + password).hexdigest()
- # Set a function to open settings for reusability
- def opensettings():
- plugintools.open_settings_dialog()
- # Copy directories from one laction to another
- def copytree(src, dst, symlinks=False, ignore=None):
- if not os.path.exists(dst):
- os.makedirs(dst)
- for item in os.listdir(src):
- s = os.path.join(src, item)
- d = os.path.join(dst, item)
- if os.path.isdir(s):
- copytree(s, d, symlinks, ignore)
- else:
- if not os.path.exists(d) or os.stat(s).st_mtime - os.stat(d).st_mtime > 1:
- shutil.copy2(s, d)
- # Popup script
- def TextBoxes(heading, announce):
- class TextBox():
- WINDOW = 10147
- CONTROL_LABEL = 1
- CONTROL_TEXTBOX = 5
- def __init__(self, *args, **kwargs):
- # activate the text viewer window
- xbmc.executebuiltin("ActivateWindow(%d)" % (self.WINDOW, ))
- self.win = xbmcgui.Window(self.WINDOW) # get window
- xbmc.sleep(500) # give window time to initialize
- self.setControls()
- def setControls(self):
- self.win.getControl(self.CONTROL_LABEL).setLabel(
- heading) # set heading
- try:
- f = open(announce)
- text = f.read()
- except:
- text = announce
- self.win.getControl(self.CONTROL_TEXTBOX).setText(str(text))
- return
- TextBox()
- # About us text
- def changelog(cltitle, cltext):
- TextBoxes(cltitle, cltext)
- # Get params
- def get_params():
- param = []
- paramstring = sys.argv[2]
- if len(paramstring) >= 2:
- params = sys.argv[2]
- cleanedparams = params.replace('?', '')
- if (params[len(params) - 1] == '/'):
- params = params[0:len(params) - 2]
- pairsofparams = cleanedparams.split('&')
- param = {}
- for i in range(len(pairsofparams)):
- splitparams = {}
- splitparams = pairsofparams[i].split('=')
- if (len(splitparams)) == 2:
- param[splitparams[0]] = splitparams[1]
- return param
- def backup_restore():
- whattodo = plugintools.selector(title="Please Select", option_list=[ "Backup Settings", "Restore Settings"])
- if whattodo == 0:
- backup_xml()
- elif whattodo == 1:
- restore_xml()
- def backup_xml():
- xbmc.executebuiltin("ActivateWindow(busydialog)")
- #GUISETTINGS
- TO_READ = open(GUISETTINGS).read()
- TO_WRITE = os.path.join(USB,"guisettings.xml")
- f = open(TO_WRITE, mode='w')
- f.write(TO_READ)
- #SKINSETTINGS
- # TO_READ = open(SKINSETTINGS).read()
- # TO_WRITE = os.path.join(USB,"settings.xml")
- # f = open(TO_WRITE, mode='w')
- # f.write(TO_READ)
- f.close()
- xbmc.executebuiltin("Dialog.Close(busydialog)")
- plugintools.message(AddonTitle, "Guisettings.xml Backup Completed,")
- def restore_xml():
- # if 'settings.xml' in description:
- # a = open(os.path.join(USB,description.split('Your ')[1])).read()
- #
- # r='<setting id="%s.(.+?)" type="(.+?)">(.+?)</setting>'% SKIN
- # #<setting id="skin.confluence.HomeMusicButton4" type="string"></setting>
- #
- # match=re.compile(r).findall(a)
- # plugintools.log("### Found Matches ##")
- # for string,type,setting in match:
- # plugintools.log(type)
- # setting=setting.replace('"','') .replace('&','&')
- # xbmc.executebuiltin("Skin.Set%s(%s,%s)"%(type.title(),string,setting))
- # else:
- #GUISETTINGS
- xbmc.executebuiltin("ActivateWindow(busydialog)")
- TO_WRITE = os.path.join(GUISETTINGS)
- TO_READ = open(os.path.join(USB,"guisettings.xml")).read()
- f = open(TO_WRITE, mode='w')
- f.write(TO_READ)
- #SKINSETTINGS
- # TO_WRITE = os.path.join(SKINSETTINGS)
- # TO_READ = open(os.path.join(USB,"settings.xml")).read()
- # f = open(TO_WRITE, mode='w')
- # f.write(TO_READ)
- f.close()
- xbmc.executebuiltin('UnloadSkin()')
- xbmc.executebuiltin('ReloadSkin()')
- xbmc.executebuiltin("Dialog.Close(busydialog)")
- plugintools.message(AddonTitle, "Guisettings.xml Restore Completed,")
- N = base64.decodestring('')
- T = base64.decodestring('L2FkZG9ucy50eHQ=')
- b = base64.decodestring('')
- F = base64.decodestring('')
- # Add directory
- def addDir(name, url, mode, iconimage, fanart, description):
- u = sys.argv[0] + "?url=" + urllib.quote_plus(url) + "&mode=" + str(mode) + "&name=" + urllib.quote_plus(
- name) + "&iconimage=" + urllib.quote_plus(iconimage) + "&fanart=" + urllib.quote_plus(fanart) + "&description=" + urllib.quote_plus(description)
- ok = True
- liz = xbmcgui.ListItem(
- name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
- liz.setInfo(type="Video", infoLabels={"Title": name, "Plot": description})
- liz.setProperty("Fanart_Image", fanart)
- if (mode == 5) or (mode == 15) or (mode == 16) or (mode == 10) or (mode == 4) or (mode == 6) or (mode == 7) or (mode == 17) or (mode == 18):
- ok = xbmcplugin.addDirectoryItem(handle=int(
- sys.argv[1]), url=u, listitem=liz, isFolder=False)
- else:
- ok = xbmcplugin.addDirectoryItem(handle=int(
- sys.argv[1]), url=u, listitem=liz, isFolder=True)
- return ok
- params = get_params()
- url = None
- name = None
- mode = None
- iconimage = None
- fanart = None
- description = None
- try:
- url = urllib.unquote_plus(params["url"])
- except:
- pass
- try:
- name = urllib.unquote_plus(params["name"])
- except:
- pass
- try:
- iconimage = urllib.unquote_plus(params["iconimage"])
- except:
- pass
- try:
- mode = int(params["mode"])
- except:
- pass
- try:
- fanart = urllib.unquote_plus(params["fanart"])
- except:
- pass
- try:
- description = urllib.unquote_plus(params["description"])
- except:
- pass
- # Set the current window view
- def setView(content, viewType):
- # set content type so library shows more views and info
- if content:
- xbmcplugin.setContent(int(sys.argv[1]), content)
- if ADDON.getSetting('auto-view') == 'true':
- xbmc.executebuiltin("Container.SetViewMode(%s)" %
- ADDON.getSetting(viewType))
- if mode == None or url == None or len(url) < 1:
- SETUP()
- elif mode == 2:
- BUILDMENU()
- elif mode == 3:
- MAINTENANCE()
- elif mode == 4:
- deletecachefiles(url)
- elif mode == 5:
- WIZARD(name, url, description)
- elif mode == 6:
- FRESHSTART(params)
- elif mode == 7:
- DeletePackages(url)
- elif mode == 8:
- facebook()
- elif mode == 9:
- donation()
- elif mode == 10:
- killxbmc()
- elif mode == 11:
- DELETEIVUEDB()
- elif mode == 15:
- opensettings()
- elif mode == 16:
- deleteThumbnails(url)
- elif mode == 17:
- backup_restore()
- elif mode == 18:
- restore_xml(name,url,description)
- xbmcplugin.endOfDirectory(int(sys.argv[1]))
- Exit status: 0
- logout
- Saving session...
- ...copying shared history...
- ...saving history...truncating history files...
- ...completed.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement