Guest User

Untitled

a guest
Feb 23rd, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 25.82 KB | None | 0 0
  1. import re;import base64
  2. import xbmc, xbmcaddon, xbmcgui, xbmcplugin, os, base64, sys, xbmcvfs, atexit, requests
  3. import shutil, urllib, urllib2, cookielib, re, extract, downloader, time, json, plugintools
  4. from ConfigParser import SafeConfigParser
  5. from addon.common.addon import Addon
  6. from addon.common.net import Net
  7.  
  8. try:
  9.     from hashlib import sha1
  10. except ImportError: # python 2.4 compat
  11.     from sha import sha as sha1
  12.  
  13.  
  14.  
  15.  
  16. AddonID          = 'plugin.video.paradoxwizard'
  17. ADDON              = xbmcaddon.Addon(id=AddonID)
  18. VERSION          = "1.0.3"
  19. ADDONPATH          = xbmc.translatePath(os.path.join('special://home/addons/' + AddonID))
  20. AddonTitle        = "Paradox Wizard"
  21. USER_AGENT        = 'Kodi/Paradox Wizard'
  22. U                  = plugintools.get_setting('username')
  23. P                  = plugintools.get_setting('password')
  24. M                  = plugintools.get_setting('submessage')
  25.  
  26. dialog            = xbmcgui.Dialog()
  27. net              = Net()
  28.  
  29. BASEURL          = "http://theblackboxostv.co.uk/"
  30. CHECKURL            = BASEURL + "wizard-dev.php"
  31.  
  32. ART              = xbmc.translatePath(os.path.join('special://home/addons/' + AddonID + '/resources/art/'))
  33. DBPATH            = xbmc.translatePath('special://database')
  34. TNPATH            = xbmc.translatePath('special://thumbnails');
  35.  
  36. EXCLUDES            = ['plugin.video.paradoxwizard','script.module.addon.common','repository.paradox']
  37.  
  38. FANART            = ART+'fanart.png'
  39. ICON                = ART+'icon.png'
  40.  
  41. #set some default icons
  42. INSTALLICON      = ART+'install.png'
  43. MAINTAINANCEICON    = ART+'maintenance.png'
  44. CONTACTICON      = ART+'contact.png'
  45. CLEARCACHEICON    = ART+'clear-cache.png'
  46. FRESHSTARTICON    = ART+'fresh-start.png'
  47. PURGEICON          = ART+'purge.png'
  48.  
  49. #Firstrun marker
  50. FIRSTRUN            = True
  51.  
  52.  
  53.  
  54.  
  55. def DoE(e): xbmc.executebuiltin(e)
  56. def DoAW(e): xbmc.executebuiltin("ActivateWindow(%s)" % str(e))
  57. def DoRW(e): xbmc.executebuiltin("ReplaceWindow(%s)" % str(e))
  58. def DoRA(e): xbmc.executebuiltin("RunAddon(%s)" % str(e))
  59. def DoRA2(e,e2="1",e3=""): xbmc.executebuiltin('RunAddon(%s,"%s","%s")' % (str(e),str(e2),e3));
  60. def DoA(a): xbmc.executebuiltin("Action(%s)" % str(a))
  61. def DoCM(a): xbmc.executebuiltin("Control.Message(windowid=%s)" % (str(a)))
  62. def DoSC(a): xbmc.executebuiltin("SendClick(%s)" % (str(a)))
  63. def DoSC2(a,Id): xbmc.executebuiltin("SendClick(%s,%s)" % (str(a),str(Id)))
  64. def DoStopScript(e): xbmc.executebuiltin("StopScript(%s)" % str(e))
  65. def DoTD(): xbmc.executebuiltin("ToggleDebug")
  66. def exit_handler():
  67.     print 'My application is ending!'
  68.    
  69. atexit.register(exit_handler)
  70.  
  71. # Anything that needs to be run before the script init's
  72. def SETUP():
  73.     global INSTALLICON,MAINTAINANCEICON,CONTACTICON,CLEARCACHEICON,FRESHSTARTICON,PURGEICON,M
  74.     # See if we can update the logos used
  75.     # logopath = "http://paradoxwizard.co.uk/icon/paradox-wizard-icons.cfg"
  76.     # path = xbmc.translatePath(os.path.join('special://home/addons','packages/'))
  77.     # downloader.download(logopath, path + "/paradox-wizard-icons.cfg")
  78.     # icons = SafeConfigParser()
  79.     # icons.read(path + "/paradox-wizard-icons.cfg")
  80.     # INSTALLICON        = str(icons.get('icons', 'installicon'))
  81.     # MAINTAINANCEICON  = str(icons.get('icons', 'maintainanceicon'))
  82.     # CONTACTICON        = str(icons.get('icons', 'contacticon'))
  83.     # CLEARCACHEICON      = str(icons.get('icons', 'clearcacheicon'))
  84.     # FRESHSTARTICON      = str(icons.get('icons', 'freshstarticon'))
  85.     # PURGEICON        = str(icons.get('icons', 'purgeicon'))
  86.     # FANART              = str(icons.get('icons', 'fanart'))
  87.     if U=="" and P=="" and M=="false":
  88.         msg1 = "Please register an account at http://theblackboxostv.co.uk and enter your forum username and password in the wizard settings panel to continue. "
  89.         msg2 = "Would you like to enter your username and password now?"
  90.         yes_pressed=plugintools.message_yes_no(AddonTitle + " - Authentication",msg1,msg2)
  91.         plugintools.set_setting('submessage','true')
  92.         if yes_pressed:
  93.             plugintools.open_settings_dialog()
  94.  
  95.     INDEX()
  96.  
  97. # Inital Menu
  98. def INDEX():
  99.  
  100.     addDir('Install Paradox',BASEURL,2,INSTALLICON,FANART,'')
  101.     addDir('Maintenance',BASEURL,3,MAINTAINANCEICON,FANART,'')
  102.     addDir('Contact',BASEURL,8,CONTACTICON,FANART,'')
  103.     setView('movies', 'MAIN')
  104.  
  105. # Build Menu
  106. def BUILDMENU():
  107.  
  108.     data = OPEN_URL(CHECKURL + "?action=listbuilds&user=" + U + "&pass=" + smf_hash(P,U))
  109.     parsed = json.loads(data)
  110.  
  111.     for build in parsed:
  112.         addDir(build['bfriendlyname'] + ' - ' + build['bversion'],build['bslug'],5,build['bicon'],FANART,'')
  113.         setView('movies', 'MAIN')
  114.  
  115. # Maintenance menu
  116. def MAINTENANCE():
  117.     addDir('Clear Cache','url',4,CLEARCACHEICON,FANART,'')
  118.     addDir('Fresh Start','url',6,FRESHSTARTICON,FANART,'')
  119.     addDir('Purge Packages','url',7,PURGEICON,FANART,'')
  120.     setView('movies', 'MAIN')
  121.  
  122. # Popup script
  123. def TextBoxes(heading,announce):
  124.   class TextBox():
  125.     WINDOW=10147
  126.     CONTROL_LABEL=1
  127.     CONTROL_TEXTBOX=5
  128.     def __init__(self,*args,**kwargs):
  129.       xbmc.executebuiltin("ActivateWindow(%d)" % (self.WINDOW, )) # activate the text viewer window
  130.       self.win=xbmcgui.Window(self.WINDOW) # get window
  131.       xbmc.sleep(500) # give window time to initialize
  132.       self.setControls()
  133.     def setControls(self):
  134.       self.win.getControl(self.CONTROL_LABEL).setLabel(heading) # set heading
  135.       try: f=open(announce); text=f.read()
  136.       except: text=announce
  137.       self.win.getControl(self.CONTROL_TEXTBOX).setText(str(text))
  138.       return
  139.   TextBox()
  140.  
  141. # About us text
  142. def facebook():
  143.     TextBoxes(AddonTitle,'[COLOR=orange]Welcome to Paradox[/COLOR][CR][CR]')       
  144.    
  145. # Install builds
  146. def WIZARD(name,url,description):
  147.  
  148.     xbmc.executebuiltin( "ActivateWindow(busydialog)" )
  149.  
  150.     # Check the username and password set in the wizard
  151.     whatami = platform()
  152.     burl = CHECKURL + "?action=getbuild&devos=" + whatami + "&build=" + url + "&user=" + U + "&pass=" + smf_hash(P,U)
  153.     data = OPEN_URL(burl)
  154.     parsed = json.loads(data)
  155.     build = str(parsed.get('bfriendlyname'))
  156.     version = str(parsed.get('bversion'))
  157.  
  158.     # See if we have a version file
  159.     versionpath = xbmc.translatePath(os.path.join('special://','home'))
  160.     versionfile = versionpath + 'version.txt'
  161.     versionfileexists = os.path.isfile(versionfile)
  162.     parser = SafeConfigParser()
  163.     parser.read(versionfile)
  164.  
  165.     # Check the version of the build against the latest available version
  166.     if versionfileexists and parser.get('versioninfo', 'version') == version and parser.get('versioninfo', 'build') == build:
  167.         dialog = xbmcgui.Dialog()
  168.         xbmc.executebuiltin( "Dialog.Close(busydialog)" )
  169.         dialog.ok(AddonTitle, "You already have the most recent version","", str(parser.get('versioninfo', 'build')) + " " + str(parser.get('versioninfo', 'version')))
  170.     else:
  171.  
  172.         path = xbmc.translatePath(os.path.join('special://home/addons','packages/'))
  173.         fileexists = os.path.isfile(path+url+version+'.zip')
  174.         existingfile = os.path.join(path+url+version+'.zip')
  175.  
  176.         if fileexists:
  177.             lib = existingfile
  178.             dp = xbmcgui.DialogProgress()
  179.             xbmc.executebuiltin( "Dialog.Close(busydialog)" )
  180.             tempfolder = xbmc.translatePath(os.path.join('special://','home','temp'))
  181.             addonfolder = xbmc.translatePath(os.path.join('special://','home'))
  182.             time.sleep(2)
  183.             dp.create(AddonTitle,"Extracting "+ name, "Please Wait...")
  184.             extract.all(lib,addonfolder,dp)
  185.             # copytree(tempfolder, addonfolder)
  186.             # shutil.rmtree(tempfolder)
  187.             dp.close()
  188.             ADDON.setSetting(id="username", value="")
  189.             ADDON.setSetting(id="password", value="")
  190.             dialog = xbmcgui.Dialog()
  191.             dialog.ok(AddonTitle, name + " has been installed from your existing packages")
  192.             dialog.ok(AddonTitle, " ", "To save changes you now need to force close Kodi, Press OK to force close Kodi")
  193.             killxbmc()
  194.  
  195.         else:
  196.  
  197.             if parsed.get('auth'):
  198.                 rid = parsed.get('recid')
  199.                 dlurl = parsed.get('bdlurl')
  200.                
  201.                 if parsed.get('brsurl'):
  202.                     dlurl = parsed.get('brsurl')
  203.                
  204.                 print dlurl
  205.  
  206.                 dp = xbmcgui.DialogProgress()
  207.                 xbmc.executebuiltin( "Dialog.Close(busydialog)" )
  208.  
  209.                 # if whatami == "windows":
  210.                 #    FRESHSTARTBUILD(params)
  211.  
  212.                 dp.create(AddonTitle,"Downloading "+ parsed.get('bfriendlyname')+ " - " + parsed.get('bversion'), "Please Wait...")
  213.                 lib = existingfile
  214.  
  215.                 # added to remove any partially downloaded files
  216.                 try:
  217.                     downloader.download(dlurl, lib, dp)
  218.                 except Exception as e:
  219.                     if str(e) == "Canceled":
  220.                         os.remove(lib)
  221.                     return
  222.  
  223.                 addonfolder = xbmc.translatePath(os.path.join('special://','home'))
  224.                 tempfolder = xbmc.translatePath(os.path.join('special://','home','temp'))
  225.                 time.sleep(2)
  226.                 dp.update(0,"", "Extracting "+ parsed.get('bfriendlyname') +" Zip","Please Wait...")
  227.                 extract.all(lib,addonfolder,dp)
  228.                 # copytree(tempfolder, addonfolder)
  229.                 # shutil.rmtree(tempfolder)
  230.                 dp.close()
  231.                 successdata = OPEN_URL(CHECKURL + "?action=installed&instid=" + str(rid) + "&user=" + U + "&pass=" + smf_hash(P,U))
  232.                 suceess = json.loads(successdata)
  233.                 dialog = xbmcgui.Dialog()
  234.                 dialog.ok(AddonTitle, suceess.get('mtit'),"", suceess.get('mmsg'))
  235.                 dialog.ok(AddonTitle, " ", "To save changes you now need to force close Kodi, Press OK to force close Kodi")
  236.                 ADDON.setSetting(id="username", value="")
  237.                 ADDON.setSetting(id="password", value="")
  238.                 killxbmc()
  239.  
  240.             else:
  241.                 xbmc.executebuiltin( "Dialog.Close(busydialog)" )
  242.                 dialog = xbmcgui.Dialog()
  243.                 dialog.ok(AddonTitle, parsed.get('etit'),"", parsed.get('emsg'))
  244.  
  245. # Copy directories from one laction to another
  246. def copytree(src, dst, symlinks=False, ignore=None):
  247.     if not os.path.exists(dst):
  248.         os.makedirs(dst)
  249.     for item in os.listdir(src):
  250.         s = os.path.join(src, item)
  251.         d = os.path.join(dst, item)
  252.         if os.path.isdir(s):
  253.             copytree(s, d, symlinks, ignore)
  254.         else:
  255.             if not os.path.exists(d) or os.stat(s).st_mtime - os.stat(d).st_mtime > 1:
  256.                 shutil.copy2(s, d)
  257.  
  258. # Open URL (Changed to use urllib2.request)
  259. def OPEN_URL(url):
  260.     headers = {
  261.         'User-Agent': USER_AGENT
  262.     }
  263.     sess = requests.session()
  264.     req = sess.get(url, headers=headers)
  265.     link = req.content
  266.     req.close()
  267.     return link
  268.  
  269. # Delete Packages
  270. def DeletePackages(url):
  271.     print '############################################################    DELETING PACKAGES             ###############################################################'
  272.     packages_cache_path = xbmc.translatePath(os.path.join('special://home/addons/packages', ''))
  273.     try:   
  274.         for root, dirs, files in os.walk(packages_cache_path):
  275.             file_count = 0
  276.             file_count += len(files)
  277.            
  278.         # Count files and give option to delete
  279.             if file_count > 0:
  280.    
  281.                 dialog = xbmcgui.Dialog()
  282.                 if dialog.yesno("Delete Package Cache Files", str(file_count) + " files found", "Do you want to delete them?"):
  283.                            
  284.                     for f in files:
  285.                         os.unlink(os.path.join(root, f))
  286.                     for d in dirs:
  287.                         shutil.rmtree(os.path.join(root, d))
  288.                     dialog = xbmcgui.Dialog()
  289.                     dialog.ok(AddonTitle, "Packages Successfuly Removed", "[COLOR yellow]Brought To You By Paradox Wizard[/COLOR]")
  290.     except:
  291.         dialog = xbmcgui.Dialog()
  292.         dialog.ok(AddonTitle, "Sorry we were not able to remove Package Files", "[COLOR yellow]Brought To You By Paradox Wizard[/COLOR]")
  293.    
  294. # Delete Cache  
  295. def deletecachefiles(url):
  296.     print '############################################################    DELETING STANDARD CACHE           ###############################################################'
  297.     xbmc_cache_path = os.path.join(xbmc.translatePath('special://home'), 'cache')
  298.     if os.path.exists(xbmc_cache_path)==True:  
  299.         for root, dirs, files in os.walk(xbmc_cache_path):
  300.             file_count = 0
  301.             file_count += len(files)
  302.        
  303.         # Count files and give option to delete
  304.             if file_count > 0:
  305.    
  306.                 dialog = xbmcgui.Dialog()
  307.                 if dialog.yesno("Delete Cache Files", str(file_count) + " files found", "Do you want to delete them?"):
  308.                
  309.                     for f in files:
  310.                         try:
  311.                             os.unlink(os.path.join(root, f))
  312.                         except:
  313.                             pass
  314.                     for d in dirs:
  315.                         try:
  316.                             shutil.rmtree(os.path.join(root, d))
  317.                         except:
  318.                             pass
  319.                        
  320.             else:
  321.                 pass
  322.     if xbmc.getCondVisibility('system.platform.ATV2'):
  323.         atv2_cache_a = os.path.join('/private/var/mobile/Library/Caches/AppleTV/Video/', 'Other')
  324.        
  325.         for root, dirs, files in os.walk(atv2_cache_a):
  326.             file_count = 0
  327.             file_count += len(files)
  328.        
  329.             if file_count > 0:
  330.  
  331.                 dialog = xbmcgui.Dialog()
  332.                 if dialog.yesno("Delete ATV2 Cache Files", str(file_count) + " files found in 'Other'", "Do you want to delete them?"):
  333.                
  334.                     for f in files:
  335.                         os.unlink(os.path.join(root, f))
  336.                     for d in dirs:
  337.                         shutil.rmtree(os.path.join(root, d))
  338.                        
  339.             else:
  340.                 pass
  341.         atv2_cache_b = os.path.join('/private/var/mobile/Library/Caches/AppleTV/Video/', 'LocalAndRental')
  342.        
  343.         for root, dirs, files in os.walk(atv2_cache_b):
  344.             file_count = 0
  345.             file_count += len(files)
  346.        
  347.             if file_count > 0:
  348.  
  349.                 dialog = xbmcgui.Dialog()
  350.                 if dialog.yesno("Delete ATV2 Cache Files", str(file_count) + " files found in 'LocalAndRental'", "Do you want to delete them?"):
  351.                
  352.                     for f in files:
  353.                         os.unlink(os.path.join(root, f))
  354.                     for d in dirs:
  355.                         shutil.rmtree(os.path.join(root, d))
  356.                        
  357.             else:
  358.                 pass
  359.               # Set path to Cydia Archives cache files
  360.                              
  361.  
  362.     # Set path to What th Furk cache files
  363.     wtf_cache_path = os.path.join(xbmc.translatePath('special://profile/addon_data/plugin.video.whatthefurk/cache'), '')
  364.     if os.path.exists(wtf_cache_path)==True:   
  365.         for root, dirs, files in os.walk(wtf_cache_path):
  366.             file_count = 0
  367.             file_count += len(files)
  368.        
  369.         # Count files and give option to delete
  370.             if file_count > 0:
  371.    
  372.                 dialog = xbmcgui.Dialog()
  373.                 if dialog.yesno("Delete WTF Cache Files", str(file_count) + " files found", "Do you want to delete them?"):
  374.                
  375.                     for f in files:
  376.                         os.unlink(os.path.join(root, f))
  377.                     for d in dirs:
  378.                         shutil.rmtree(os.path.join(root, d))
  379.                        
  380.             else:
  381.                 pass
  382.                
  383.                 # Set path to 4oD cache files
  384.     channel4_cache_path= os.path.join(xbmc.translatePath('special://profile/addon_data/plugin.video.4od/cache'), '')
  385.     if os.path.exists(channel4_cache_path)==True:  
  386.         for root, dirs, files in os.walk(channel4_cache_path):
  387.             file_count = 0
  388.             file_count += len(files)
  389.        
  390.         # Count files and give option to delete
  391.             if file_count > 0:
  392.    
  393.                 dialog = xbmcgui.Dialog()
  394.                 if dialog.yesno("Delete 4oD Cache Files", str(file_count) + " files found", "Do you want to delete them?"):
  395.                
  396.                     for f in files:
  397.                         os.unlink(os.path.join(root, f))
  398.                     for d in dirs:
  399.                         shutil.rmtree(os.path.join(root, d))
  400.                        
  401.             else:
  402.                 pass
  403.                
  404.                 # Set path to BBC iPlayer cache files
  405.     iplayer_cache_path= os.path.join(xbmc.translatePath('special://profile/addon_data/plugin.video.iplayer/iplayer_http_cache'), '')
  406.     if os.path.exists(iplayer_cache_path)==True:   
  407.         for root, dirs, files in os.walk(iplayer_cache_path):
  408.             file_count = 0
  409.             file_count += len(files)
  410.        
  411.         # Count files and give option to delete
  412.             if file_count > 0:
  413.    
  414.                 dialog = xbmcgui.Dialog()
  415.                 if dialog.yesno("Delete BBC iPlayer Cache Files", str(file_count) + " files found", "Do you want to delete them?"):
  416.                
  417.                     for f in files:
  418.                         os.unlink(os.path.join(root, f))
  419.                     for d in dirs:
  420.                         shutil.rmtree(os.path.join(root, d))
  421.                        
  422.             else:
  423.                 pass
  424.                
  425.                
  426.                 # Set path to Simple Downloader cache files
  427.     downloader_cache_path = os.path.join(xbmc.translatePath('special://profile/addon_data/script.module.simple.downloader'), '')
  428.     if os.path.exists(downloader_cache_path)==True:
  429.         for root, dirs, files in os.walk(downloader_cache_path):
  430.             file_count = 0
  431.             file_count += len(files)
  432.        
  433.         # Count files and give option to delete
  434.             if file_count > 0:
  435.    
  436.                 dialog = xbmcgui.Dialog()
  437.                 if dialog.yesno("Delete Simple Downloader Cache Files", str(file_count) + " files found", "Do you want to delete them?"):
  438.                
  439.                     for f in files:
  440.                         os.unlink(os.path.join(root, f))
  441.                     for d in dirs:
  442.                         shutil.rmtree(os.path.join(root, d))
  443.                        
  444.             else:
  445.                 pass
  446.                
  447.                 # Set path to ITV cache files
  448.     itv_cache_path = os.path.join(xbmc.translatePath('special://profile/addon_data/plugin.video.itv/Images'), '')
  449.     if os.path.exists(itv_cache_path)==True:   
  450.         for root, dirs, files in os.walk(itv_cache_path):
  451.             file_count = 0
  452.             file_count += len(files)
  453.        
  454.         # Count files and give option to delete
  455.             if file_count > 0:
  456.    
  457.                 dialog = xbmcgui.Dialog()
  458.                 if dialog.yesno("Delete ITV Cache Files", str(file_count) + " files found", "Do you want to delete them?"):
  459.                
  460.                     for f in files:
  461.                         os.unlink(os.path.join(root, f))
  462.                     for d in dirs:
  463.                         shutil.rmtree(os.path.join(root, d))
  464.                        
  465.             else:
  466.                 pass
  467.                
  468.                 # Set path to temp cache files
  469.     temp_cache_path = os.path.join(xbmc.translatePath('special://home/temp'), '')
  470.     if os.path.exists(temp_cache_path)==True:  
  471.         for root, dirs, files in os.walk(temp_cache_path):
  472.             file_count = 0
  473.             file_count += len(files)
  474.        
  475.         # Count files and give option to delete
  476.             if file_count > 0:
  477.    
  478.                 dialog = xbmcgui.Dialog()
  479.                 if dialog.yesno("Delete TEMP dir Cache Files", str(file_count) + " files found", "Do you want to delete them?"):
  480.                
  481.                     for f in files:
  482.                         os.unlink(os.path.join(root, f))
  483.                     for d in dirs:
  484.                         shutil.rmtree(os.path.join(root, d))
  485.                        
  486.             else:
  487.                 pass
  488.                
  489.  
  490.     dialog = xbmcgui.Dialog()
  491.     dialog.ok(AddonTitle, " All Cache Files Removed", "[COLOR yellow]Brought To You By Paradox Wizard[/COLOR]")
  492.  
  493. # Delete cached files
  494. def killxbmc():
  495.     choice = xbmcgui.Dialog().yesno('Force Close Kodi', 'You are about to close Kodi', 'Would you like to continue?', nolabel='No, Cancel',yeslabel='Yes, Close')
  496.     if choice == 0:
  497.         return
  498.     elif choice == 1:
  499.         pass
  500.     myplatform = platform()
  501.     print "Platform: " + str(myplatform)
  502.     if myplatform == 'osx': # OSX
  503.         print "############   try osx force close  #################"
  504.         try: os.system('killall -9 XBMC')
  505.         except: pass
  506.         try: os.system('killall -9 Kodi')
  507.         except: pass
  508.         dialog.ok("[COLOR=red][b]WARNING  !!![/COLOR][/b]", "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.",'')
  509.     elif myplatform == 'linux': #Linux
  510.         print "############   try linux force close  #################"
  511.         try: os.system('killall XBMC')
  512.         except: pass
  513.         try: os.system('killall Kodi')
  514.         except: pass
  515.         try: os.system('killall -9 xbmc.bin')
  516.         except: pass
  517.         try: os.system('killall -9 kodi.bin')
  518.         except: pass
  519.         dialog.ok("[COLOR=red][b]WARNING  !!![/COLOR][/b]", "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.",'')
  520.     elif myplatform == 'android': # Android  
  521.         print "############   try android force close  #################"
  522.         try: os.system('adb shell am force-stop org.xbmc.kodi')
  523.         except: pass
  524.         try: os.system('adb shell am force-stop org.kodi')
  525.         except: pass
  526.         try: os.system('adb shell am force-stop org.xbmc.xbmc')
  527.         except: pass
  528.         try: os.system('adb shell am force-stop org.xbmc')
  529.         except: pass       
  530.         dialog.ok("[COLOR=yellow][b]TO COMPLETE PARADOX UPDATE[/COLOR][/b]", "Press the HOME button on your remote and [COLOR=red][b]FORCE STOP[/COLOR][/b] KODI via the Manage Installed Applications menu in settings on your Amazon home page then re-launch KODI")
  531.     elif myplatform == 'windows': # Windows
  532.         print "############   try windows force close  #################"
  533.         try:
  534.             os.system('@ECHO off')
  535.             os.system('tskill XBMC.exe')
  536.         except: pass
  537.         try:
  538.             os.system('@ECHO off')
  539.             os.system('tskill Kodi.exe')
  540.         except: pass
  541.         try:
  542.             os.system('@ECHO off')
  543.             os.system('TASKKILL /im Kodi.exe /f')
  544.         except: pass
  545.         try:
  546.             os.system('@ECHO off')
  547.             os.system('TASKKILL /im XBMC.exe /f')
  548.         except: pass
  549.         dialog.ok("[COLOR=red][b]WARNING  !!![/COLOR][/b]", "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")
  550.     else: #ATV
  551.         print "############   try atv force close  #################"
  552.         try: os.system('killall AppleTV')
  553.         except: pass
  554.         print "############   try raspbmc force close  #################" #OSMC / Raspbmc
  555.         try: os.system('sudo initctl stop kodi')
  556.         except: pass
  557.         try: os.system('sudo initctl stop xbmc')
  558.         except: pass
  559.         dialog.ok("[COLOR=red][b]WARNING  !!![/COLOR][/b]", "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.")  
  560.  
  561. # Get Current platform   
  562. def platform():
  563.     if xbmc.getCondVisibility('system.platform.android'):
  564.         return 'android'
  565.     elif xbmc.getCondVisibility('system.platform.linux'):
  566.         return 'linux'
  567.     elif xbmc.getCondVisibility('system.platform.windows'):
  568.         return 'windows'
  569.     elif xbmc.getCondVisibility('system.platform.osx'):
  570.         return 'osx'
  571.     elif xbmc.getCondVisibility('system.platform.atv2'):
  572.         return 'atv2'
  573.     elif xbmc.getCondVisibility('system.platform.ios'):
  574.         return 'ios'
  575.    
  576. # Fresh start
  577. def FRESHSTART(params):
  578.     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?")
  579.     if yes_pressed:
  580.         addonPath=xbmcaddon.Addon(id=AddonID).getAddonInfo('path'); addonPath=xbmc.translatePath(addonPath);
  581.         xbmcPath=os.path.join(addonPath,"..",".."); xbmcPath=os.path.abspath(xbmcPath); plugintools.log("freshstart.main_list xbmcPath="+xbmcPath); failed=False
  582.         try:
  583.             for root, dirs, files in os.walk(xbmcPath,topdown=True):
  584.                 dirs[:] = [d for d in dirs if d not in EXCLUDES]
  585.                 for name in files:
  586.                     try: os.remove(os.path.join(root,name))
  587.                     except:
  588.                         if name not in ["Addons15.db","MyVideos75.db","Textures13.db","xbmc.log"]: failed=True
  589.                         plugintools.log("Error removing "+root+" "+name)
  590.                 for name in dirs:
  591.                     try: os.rmdir(os.path.join(root,name))
  592.                     except:
  593.                         if name not in ["Database","userdata"]: failed=True
  594.                         plugintools.log("Error removing "+root+" "+name)
  595.             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")
  596.             else: plugintools.log("freshstart.main_list User files partially removed"); plugintools.message(AddonTitle,"The process is complete","click OK to begin clean installation")
  597.         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")
  598.         plugintools.add_item(action="",title="Now Exit Kodi",folder=False)
  599.     else: plugintools.message(AddonTitle,"Your settings","has not been changed"); plugintools.add_item(action="",title="Done",folder=False)
  600.  
  601. # Fix bad zip files
  602. def fixBadZipfile(zipFile):  
  603.     f = open(zipFile, 'r+b')  
  604.     data = f.read()  
  605.     pos = data.find('\x50\x4b\x05\x06') # End of central directory signature  
  606.     if (pos > 0):  
  607.         print "Trancating file at location " + str(pos + 22)+ "."  
  608.         f.seek(pos + 22)   # size of 'ZIP end of central directory record'
  609.         f.truncate()  
  610.         f.close()  
  611.     else:
  612.         pass
  613.         # raise error, file is truncated  
  614.  
  615. # SMF Password Hashing
  616. def smf_hash(password, username):
  617.     """
  618.     Python implementation of the smf check hash function
  619.     """
  620.     return sha1(username.lower().encode('utf8') + password).hexdigest()  
  621.    
  622. # Get params     
  623. def get_params():
  624.         param=[]
  625.         paramstring=sys.argv[2]
  626.         if len(paramstring)>=2:
  627.                 params=sys.argv[2]
  628.                 cleanedparams=params.replace('?','')
  629.                 if (params[len(params)-1]=='/'):
  630.                         params=params[0:len(params)-2]
  631.                 pairsofparams=cleanedparams.split('&')
  632.                 param={}
  633.                 for i in range(len(pairsofparams)):
  634.                         splitparams={}
  635.                         splitparams=pairsofparams[i].split('=')
  636.                         if (len(splitparams))==2:
  637.                                 param[splitparams[0]]=splitparams[1]
  638.                                
  639.         return param
  640.  
  641. N = base64.decodestring('')
  642. T = base64.decodestring('L2FkZG9ucy50eHQ=')
  643. b = base64.decodestring('')
  644. F = base64.decodestring('')
  645.  
  646. # Add directory
  647. def addDir(name,url,mode,iconimage,fanart,description):
  648.         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)
  649.         ok=True
  650.         liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
  651.         liz.setInfo( type="Video", infoLabels={ "Title": name, "Plot": description } )
  652.         liz.setProperty( "Fanart_Image", fanart )
  653.         if mode==5 :
  654.             ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=False)
  655.         else:
  656.             ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
  657.         return ok
  658.  
  659.        
  660.                      
  661. params=get_params()
  662. url=None
  663. name=None
  664. mode=None
  665. iconimage=None
  666. fanart=None
  667. description=None
  668.  
  669.  
  670. try:
  671.         url=urllib.unquote_plus(params["url"])
  672. except:
  673.         pass
  674. try:
  675.         name=urllib.unquote_plus(params["name"])
  676. except:
  677.         pass
  678. try:
  679.         iconimage=urllib.unquote_plus(params["iconimage"])
  680. except:
  681.         pass
  682. try:       
  683.         mode=int(params["mode"])
  684. except:
  685.         pass
  686. try:       
  687.         fanart=urllib.unquote_plus(params["fanart"])
  688. except:
  689.         pass
  690. try:       
  691.         description=urllib.unquote_plus(params["description"])
  692. except:
  693.         pass
  694.  
  695. # Set the current window view
  696. def setView(content, viewType):
  697.     # set content type so library shows more views and info
  698.     if content:
  699.         xbmcplugin.setContent(int(sys.argv[1]), content)
  700.     if ADDON.getSetting('auto-view')=='true':
  701.         xbmc.executebuiltin("Container.SetViewMode(%s)" % ADDON.getSetting(viewType) )
  702.        
  703.        
  704. if mode==None or url==None or len(url)<1: SETUP()
  705. elif mode==2: BUILDMENU()
  706. elif mode==3: MAINTENANCE()
  707. elif mode==4: deletecachefiles(url)
  708. elif mode==5: WIZARD(name,url,description)
  709. elif mode==6: FRESHSTART(params)
  710. elif mode==7: DeletePackages(url)
  711. elif mode==8: facebook()
  712. elif mode==9: donation()
  713. elif mode==11: DELETEIVUEDB()
  714.  
  715. xbmcplugin.endOfDirectory(int(sys.argv[1]))
Add Comment
Please, Sign In to add comment