Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import sys
- import os
- import shutil
- import xbmcaddon
- import xbmc
- import logger
- #PLATFORM_NAME="kodi-jarvis"
- #PLUGIN_NAME="pelisaplus"
- #---------------------------
- # Classe config
- #===========================
- class config(object):
- log=logger
- platform = "unknown"
- #===========================================
- # Instanziamento della classe config con parametri assegnati
- #
- def __init__(self,PLATFORM_NAME="kodi-jarvis",PLUGIN_NAME="pelisaplus"):
- self.platform_name=PLATFORM_NAME
- self.plugin_name=PLUGIN_NAME
- self.setting=xbmcaddon.Addon(id="plugin.video." + PLUGIN_NAME)
- self.language=self.setting.getLocalizedString
- #============================================
- # Metodo pubblico ritorna nome piattaforma
- #
- def get_platform(self):
- return self.platform_name
- # ============================================
- # Metodo pubblico ritorna nome piattaforma
- #
- def is_xbmc(self):
- return True
- # ============================================
- # Metodo pubblico ritorna supporto a librerie
- #
- def get_library_support(self):
- return True
- #=============================================
- # Metodo pubblico ritorna il tipo di piattaforma utlizzata
- #
- def get_system_platform(self):
- if xbmc.getCondVisibility("system.platform.linux"):self.platform="linux"
- elif xbmc.getCondVisibility("system.platform.xbox"):self.platform="xbox"
- elif xbmc.getCondVisibility("system.platform.windows"):self.platform="windows"
- elif xbmc.getCondVisibility("system.platform.osx"):self.platform = "osx"
- return self.platform
- # =============================================
- # Metodo pubblico ritorna apertura file setting
- #
- def open_settings(self):
- self.setting.openSetting()
- # =============================================
- # Metodo pubblico ritorna il valore del settaggio
- #
- def get_setting(self,name):
- self.setting.getSetting(name)
- # =============================================
- # Metodo pubblico assegna il valore del settaggio
- #
- def set_setting(self, name, value):
- self.setting.setSetting(name,value)
- # =============================================
- # Metodo pubblico ritorna codice linguaggio
- #
- def get_localized_string(self,code):
- dev = self.language(code)
- try:
- dev=dev.encode("utf-8")
- except:
- pass
- return dev
- # =============================================
- # Metodo pubblico ritorna il percorso delle library
- #
- def get_library_patch(self):
- if self.get_platform()=="xbox":
- default = xbmc.xbmc.translatePath(os.path.join(self.get_runtime_path(),"library"))
- else:
- default = xbmc.translatePath("special://profile/addon_data/plugin.video." + self.plugin_name + "/library")
- value = self.get_setting("librarypath")
- if value == "": value = default
- return value
- # =============================================
- # Metodo pubblico ritorna il percorso
- #
- def get_runtime_path(self):
- return xbmc.translatePath(self.setting.getAddonInfo("Path"))
- # =============================================
- # Metodo pubblico ritorna il percorso del profilo
- #
- def get_data_path(self):
- dev = xbmc.translatePath(self.setting.getAddonInfo("Profile"))
- # per XBMC4XBOX
- if not os.path.exists(dev):
- os.makedirs(dev)
- return dev
- # =============================================
- # Metodo pubblico ritorna il percorso del profilo
- #
- def get_temp_file(self,filename):
- return xbmc.translatePath(os.path.join("special://temp/", filename))
- # =============================================
- # Metodo pubblico ritorna il percorso il contenuto del cookie
- #
- def get_cookie_data(self):
- filmcookies = os.path.join(self.get_data_path(), 'cookies.dat')
- cookiedatafile = open(filmcookies, 'r')
- cookiedata = cookiedatafile.read()
- cookiedatafile.close()
- return cookiedata
- # =============================================
- # Metodo pubblico che verifica se il percorso รจ stato creato
- #
- def verify_directories_created(self):
- self.log.info("pelisalacarta.core.config.verify_directories_created")
- # Force download path if empty
- download_path = self.get_setting("downloadpath")
- if download_path=="": download_path = os.path.join(self.get_data_path(), "downloads")
- self.set_setting("downloadpath",download_path)
- # Force download list path if empty
- download_list_path = self.get_setting("downloadlistpath")
- if download_list_path == "": download_list_path = os.path.join(self.get_data_path(), "downloads", "list")
- self.set_setting("downloadlistpath", download_list_path)
- # Force bookmark path if empty
- bookmark_path = self.get_setting("bookmarkpath")
- if bookmark_path == "":bookmark_path = os.path.join(self.get_data_path(), "bookmarks")
- self.set_setting("bookmarkpath", bookmark_path)
- # Create data_path if not exists
- if not os.path.exists(self.get_data_path()):
- self.log.debug("Creating data_path " + self.get_data_path())
- try:
- os.mkdir(self.get_data_path())
- except:
- pass
- # Create download_path if not exists
- if not download_path.lower().startswith("smb") and not os.path.exists(download_path):
- self.log.debug("Creating download_path " + download_path)
- try:
- os.mkdir(download_path)
- except:
- pass
- # Create download_list_path if not exists
- if not download_list_path.lower().startswith("smb") and not os.path.exists(download_list_path):
- self.log.debug("Creating download_list_path " + download_list_path)
- try:
- os.mkdir(download_list_path)
- except:
- pass
- # Create bookmark_path if not exists
- if not bookmark_path.lower().startswith("smb") and not os.path.exists(bookmark_path):
- self.log.debug("Creating bookmark_path " + bookmark_path)
- try:
- os.mkdir(bookmark_path)
- except:
- pass
- # Create library_path if not exists
- if not self.get_library_patch().lower().startswith("smb") and not os.path.exists(self.get_library_patch()):
- self.log.debug("Creating library_path " + self.get_library_patch())
- try:
- os.mkdir(self.get_library_patch())
- except:
- pass
- # Checks that a directory "xbmc" is not present on platformcode
- old_xbmc_directory = os.path.join(self.get_runtime_path(), "platformcode", "xbmc")
- if os.path.exists(old_xbmc_directory):
- self.log.debug("Removing old platformcode.xbmc directory")
- try:
- shutil.rmtree(old_xbmc_directory)
- except:
- pass
Advertisement
Add Comment
Please, Sign In to add comment