def setPluginCategory(handle, category): """ Sets the plugins name for skins to display. :param int handle: integer - handle the plugin was started with. :param category: string or unicode - plugins sub category. :type category: str or unicode Example:: xbmcplugin.setPluginCategory(int(sys.argv[1]), 'Comedy') """ plugin_data["category"] = ensure_unicode(category)
def find_addons(*dirs): """ Search given directory for addons. A folder is considered to be an addon, if it contains an 'addon.xml' file. :param dirs: A list of directorys to scan. """ filename = safe_path("addon.xml") for path in dirs: path = safe_path(path) for item in os.listdir(path): plugin_file = os.path.join(path, item, filename) if os.path.exists(plugin_file): yield ensure_unicode(plugin_file)
def setSettingString(self, id, value): """ Sets a script setting. :param str id: string - id of the setting that the module needs to access. :param value: string or unicode - value of the setting. :returns: True if the value of the setting was set, false otherwise :rtype: bool .. note:: You can use the above as keywords for arguments. Example:: self.Addon.setSettingString(id='username', value='teamkodi') """ return self.setSetting(id, ensure_unicode(value))
def setContent(handle, content): """ Sets the plugins content type. :param int handle: integer - handle the plugin was started with. :param str content: string - content type (eg. movies). Possible values for content:: Possible values for content: files, songs, artists, albums, movies, tvshows, episodes, musicvideos, videos, games Example:: xbmcplugin.setContent(int(sys.argv[1]), 'movies') """ plugin_data["contenttype"] = ensure_unicode(content)
def setup_paths(): # Location of support files system_dir = os.path.join( ensure_unicode(os.path.dirname(__file__), sys.getfilesystemencoding()), u"data") kodi_paths["support"] = system_dir # Kodi path structure kodi_paths["home"] = home = appdirs.user_cache_dir(u"kodi_mock") kodi_paths["addons"] = addon_dir = os.path.join(home, u"addons") kodi_paths["packages"] = os.path.join(addon_dir, u"packages") kodi_paths["temp"] = temp_dir = os.path.join(home, u"temp") kodi_paths["system"] = os.path.join(home, u"system") kodi_paths["profile"] = userdata = os.path.join(home, u"userdata") kodi_paths["data"] = os.path.join(userdata, u"addon_data") kodi_paths["database"] = os.path.join(userdata, u"Database") kodi_paths["thumbnails"] = os.path.join(userdata, u"Thumbnails") kodi_paths["playlists"] = playlists = os.path.join(userdata, u"playlists") kodi_paths["musicplaylists"] = os.path.join(playlists, u"music") kodi_paths["videoplaylists"] = os.path.join(playlists, u"video") # Ensure that all directories exists for path in kodi_paths.values(): path = safe_path(path) if not os.path.exists(path): os.makedirs(path) # Rest of kodi's special paths kodi_paths["logpath"] = os.path.join(temp_dir, u"kodi.log") kodi_paths["masterprofile"] = userdata kodi_paths["masterprofile"] = userdata kodi_paths["userdata"] = userdata kodi_paths["subtitles"] = temp_dir kodi_paths["recordings"] = temp_dir kodi_paths["screenshots"] = temp_dir kodi_paths["cdrips"] = temp_dir kodi_paths["skin"] = temp_dir kodi_paths["xbmc"] = home # Return the support system directory and addon directory return system_dir, addon_dir
def addDirectoryItem(handle, url, listitem, isFolder=False, totalItems=0): """ Callback function to pass directory contents back to XBMC. Returns a bool for successful completion. :param int handle: integer - handle the plugin was started with. :param str url: string - url of the entry. would be plugin:// for another virtual directory. :param listitem: ListItem - item to add. :param bool isFolder: [opt] bool - True=folder / False=not a folder. :param int totalItems: [opt] integer - total number of items that will be passed. (used for progressbar) :returns: Returns a bool for successful completion. :rtype: bool Example:: if not xbmcplugin.addDirectoryItem(int(sys.argv[1]), 'F:\\Trailers\\300.mov', listitem, totalItems=50): break """ data = (ensure_unicode(url), listitem, isFolder) plugin_data["listitem"].append(data) return True
def main(): # Parse the cli arguments args = parser.parse_args(sys.argv[1:]) # Enable debug logging if logging flag was given if args.debug: logger.setLevel(logging.DEBUG) # Convert any preselection into a list of selections preselect = list(map( int, args.preselect.split(","))) if args.preselect else None # Set the repo to use for dependency resolving Repo.repo = args.repo # Execute the addon in interactive mode plugin_path = os.path.realpath(decode_arg(args.addonpath)) arguments = [plugin_path, preselect] if args.content_type: arguments.append(args.content_type) # Check if plugin actually exists if os.path.exists(safe_path(plugin_path)): interactive(*arguments, compact_mode=args.compact, no_crop=args.no_crop) # Check if we are already in the requested plugin directory if pluginpath was a plugin id elif args.pluginpath.startswith("plugin.") and os.path.basename( os.getcwd()) == args.pluginpath: arguments[0] = ensure_unicode(os.getcwd(), sys.getfilesystemencoding()) interactive(*arguments, compact_mode=args.compact, no_crop=args.no_crop) else: raise RuntimeError("unable to find requested add-on: {}".format( plugin_path.encode("utf8")))
def __getitem__(self, item): return ensure_unicode(self.get(item, u""))
def __getitem__(self, key): return ensure_unicode(self._strings.get(key, u""))