costaplus

Config_plus

Jun 18th, 2016
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.20 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. import sys
  4. import os
  5. import shutil
  6. import xbmcaddon
  7. import xbmc
  8. import logger
  9.  
  10.  
  11. #PLATFORM_NAME="kodi-jarvis"
  12. #PLUGIN_NAME="pelisaplus"
  13.  
  14.  
  15. #---------------------------
  16. # Classe config
  17. #===========================
  18. class config(object):
  19.     log=logger
  20.     platform = "unknown"
  21.     #===========================================
  22.     # Instanziamento della classe config con parametri assegnati
  23.     #
  24.     def __init__(self,PLATFORM_NAME="kodi-jarvis",PLUGIN_NAME="pelisaplus"):
  25.         self.platform_name=PLATFORM_NAME
  26.         self.plugin_name=PLUGIN_NAME
  27.         self.setting=xbmcaddon.Addon(id="plugin.video." + PLUGIN_NAME)
  28.         self.language=self.setting.getLocalizedString
  29.  
  30.  
  31.     #============================================
  32.     # Metodo pubblico ritorna nome piattaforma
  33.     #
  34.     def get_platform(self):
  35.         return self.platform_name
  36.  
  37.     # ============================================
  38.     # Metodo pubblico ritorna nome piattaforma
  39.     #
  40.     def is_xbmc(self):
  41.         return True
  42.  
  43.     # ============================================
  44.     # Metodo pubblico ritorna supporto a librerie
  45.     #
  46.     def get_library_support(self):
  47.         return True
  48.  
  49.     #=============================================
  50.     # Metodo pubblico ritorna il tipo di piattaforma utlizzata
  51.     #
  52.     def get_system_platform(self):
  53.         if xbmc.getCondVisibility("system.platform.linux"):self.platform="linux"
  54.         elif xbmc.getCondVisibility("system.platform.xbox"):self.platform="xbox"
  55.         elif xbmc.getCondVisibility("system.platform.windows"):self.platform="windows"
  56.         elif xbmc.getCondVisibility("system.platform.osx"):self.platform = "osx"
  57.  
  58.         return self.platform
  59.  
  60.     # =============================================
  61.     # Metodo pubblico ritorna apertura file setting
  62.     #
  63.     def open_settings(self):
  64.         self.setting.openSetting()
  65.  
  66.     # =============================================
  67.     # Metodo pubblico ritorna il valore del settaggio
  68.     #
  69.     def get_setting(self,name):
  70.         self.setting.getSetting(name)
  71.  
  72.     # =============================================
  73.     # Metodo pubblico assegna il valore del settaggio
  74.     #
  75.     def set_setting(self, name, value):
  76.         self.setting.setSetting(name,value)
  77.  
  78.  
  79.     # =============================================
  80.     # Metodo pubblico ritorna codice linguaggio
  81.     #
  82.     def get_localized_string(self,code):
  83.         dev = self.language(code)
  84.         try:
  85.             dev=dev.encode("utf-8")
  86.         except:
  87.             pass
  88.  
  89.         return dev
  90.  
  91.     # =============================================
  92.     # Metodo pubblico ritorna il percorso delle library
  93.     #
  94.     def get_library_patch(self):
  95.         if self.get_platform()=="xbox":
  96.             default = xbmc.xbmc.translatePath(os.path.join(self.get_runtime_path(),"library"))
  97.         else:
  98.             default = xbmc.translatePath("special://profile/addon_data/plugin.video." + self.plugin_name + "/library")
  99.  
  100.         value = self.get_setting("librarypath")
  101.  
  102.         if value == "": value = default
  103.  
  104.         return value
  105.  
  106.     # =============================================
  107.     # Metodo pubblico ritorna il percorso
  108.     #
  109.     def get_runtime_path(self):
  110.         return xbmc.translatePath(self.setting.getAddonInfo("Path"))
  111.  
  112.     # =============================================
  113.     # Metodo pubblico ritorna il percorso del profilo
  114.     #
  115.     def get_data_path(self):
  116.         dev = xbmc.translatePath(self.setting.getAddonInfo("Profile"))
  117.         # per  XBMC4XBOX
  118.         if not os.path.exists(dev):
  119.             os.makedirs(dev)
  120.  
  121.         return dev
  122.  
  123.     # =============================================
  124.     # Metodo pubblico ritorna il percorso del profilo
  125.     #
  126.     def get_temp_file(self,filename):
  127.         return xbmc.translatePath(os.path.join("special://temp/", filename))
  128.  
  129.     # =============================================
  130.     # Metodo pubblico ritorna il percorso il contenuto del cookie
  131.     #
  132.     def get_cookie_data(self):
  133.         filmcookies = os.path.join(self.get_data_path(), 'cookies.dat')
  134.         cookiedatafile = open(filmcookies, 'r')
  135.         cookiedata = cookiedatafile.read()
  136.         cookiedatafile.close()
  137.  
  138.         return cookiedata
  139.  
  140.     # =============================================
  141.     # Metodo pubblico che verifica se il percorso รจ stato creato
  142.     #
  143.     def verify_directories_created(self):
  144.         self.log.info("pelisalacarta.core.config.verify_directories_created")
  145.  
  146.         # Force download path if empty
  147.         download_path = self.get_setting("downloadpath")
  148.         if download_path=="": download_path = os.path.join(self.get_data_path(), "downloads")
  149.         self.set_setting("downloadpath",download_path)
  150.  
  151.         # Force download list path if empty
  152.         download_list_path = self.get_setting("downloadlistpath")
  153.         if download_list_path == "": download_list_path = os.path.join(self.get_data_path(), "downloads", "list")
  154.         self.set_setting("downloadlistpath", download_list_path)
  155.  
  156.         # Force bookmark path if empty
  157.         bookmark_path = self.get_setting("bookmarkpath")
  158.         if bookmark_path == "":bookmark_path = os.path.join(self.get_data_path(), "bookmarks")
  159.         self.set_setting("bookmarkpath", bookmark_path)
  160.  
  161.         # Create data_path if not exists
  162.         if not os.path.exists(self.get_data_path()):
  163.             self.log.debug("Creating data_path " + self.get_data_path())
  164.         try:
  165.             os.mkdir(self.get_data_path())
  166.         except:
  167.             pass
  168.  
  169.         # Create download_path if not exists
  170.         if not download_path.lower().startswith("smb") and not os.path.exists(download_path):
  171.             self.log.debug("Creating download_path " + download_path)
  172.             try:
  173.                 os.mkdir(download_path)
  174.             except:
  175.                 pass
  176.  
  177.         # Create download_list_path if not exists
  178.         if not download_list_path.lower().startswith("smb") and not os.path.exists(download_list_path):
  179.             self.log.debug("Creating download_list_path " + download_list_path)
  180.             try:
  181.                 os.mkdir(download_list_path)
  182.             except:
  183.                 pass
  184.  
  185.         # Create bookmark_path if not exists
  186.         if not bookmark_path.lower().startswith("smb") and not os.path.exists(bookmark_path):
  187.             self.log.debug("Creating bookmark_path " + bookmark_path)
  188.             try:
  189.                os.mkdir(bookmark_path)
  190.             except:
  191.                pass
  192.  
  193.         # Create library_path if not exists
  194.         if not self.get_library_patch().lower().startswith("smb") and not os.path.exists(self.get_library_patch()):
  195.             self.log.debug("Creating library_path " + self.get_library_patch())
  196.             try:
  197.                 os.mkdir(self.get_library_patch())
  198.             except:
  199.                 pass
  200.  
  201.         # Checks that a directory "xbmc" is not present on platformcode
  202.         old_xbmc_directory = os.path.join(self.get_runtime_path(), "platformcode", "xbmc")
  203.         if os.path.exists(old_xbmc_directory):
  204.             self.log.debug("Removing old platformcode.xbmc directory")
  205.             try:
  206.                shutil.rmtree(old_xbmc_directory)
  207.             except:
  208.                pass
Advertisement
Add Comment
Please, Sign In to add comment