def get_torrent(url): import support.services as services torrent = services.torrent(url) torrents_path = plugin.addon_data_path("torrents") xbmcvfs.mkdirs(torrents_path) torrent.download_locally(torrents_path) return torrent
def __init__(self, name=None, addon_id=None, filepath=None, info_type=None): self._name = name self._routes = [] self._view_functions = {} # addon_id is no longer required as it can be parsed from addon.xml if addon_id: self._addon = xbmcaddon.Addon(id=addon_id) else: self._addon = xbmcaddon.Addon() self._addon_id = addon_id or self._addon.getAddonInfo('id') self._name = name or self._addon.getAddonInfo('name') self._info_type = info_type if not self._info_type: types = { 'video': 'video', 'audio': 'music', 'image': 'pictures', } self._info_type = types.get(self._addon_id.split('.')[1], 'video') # Keeps track of the added list items self._current_items = [] # Gets initialized when self.run() is called self._request = None # A flag to keep track of a call to xbmcplugin.endOfDirectory() self._end_of_directory = False # Keep track of the update_listing flag passed to # xbmcplugin.endOfDirectory() self._update_listing = False # The plugin's named logger self._log = setup_log(self._addon_id) # The path to the storage directory for the addon self._storage_path = self.addon_data_path(".storage/") from xbmcswift2.common import direxists if not direxists(self._storage_path): xbmcvfs.mkdirs(self._storage_path) # If we are runing in CLI, we need to load the strings.xml manually # Since xbmcswift2 currently relies on execution from an addon's root # directly, we can rely on cwd for now... if xbmcswift2.CLI_MODE: from xbmcswift2.mockxbmc import utils if filepath: addon_dir = os.path.dirname(filepath) else: addon_dir = os.getcwd() strings_fn = os.path.join(addon_dir, 'resources', 'language', 'English', 'strings.xml') utils.load_addon_strings(self._addon, strings_fn)
def run(self): if xbmcvfs.exists(self.dst): xbmcvfs.delete(self.dst) xbmcvfs.mkdirs(os.path.dirname(self.dst)) log.info("Copying %s to %s...", self.src, self.dst) xbmcvfs.delete(self.tmp) if xbmcvfs.copy(self.src, self.tmp): log.info("Success.") self.copied = True if xbmcvfs.rename(self.tmp, self.dst): if self.delete and xbmcvfs.delete(self.src): log.info("File %s deleted.", self.src) else: log.info("Renaming %s to %s failed.", self.tmp, self.dst) xbmcvfs.delete(self.tmp) else: log.info("Failed")
def save_files(files, rename=False, on_finish=None): save = plugin.get_setting('save-files', int) if not save: on_finish() return src, dst = temp_path(), save_path() files_dict = {} for old_path in files: old_path = ensure_unicode(old_path) rel_path = os.path.relpath(old_path, src) new_path = os.path.join(dst, rel_path) if xbmcvfs.exists(new_path): if rename: if xbmcvfs.delete(old_path): log.info("File %s deleted.", old_path) continue files_dict[old_path] = new_path if not files_dict: if on_finish: on_finish() return files_to_copy = {} if save != 2 or xbmcgui.Dialog().yesno(lang(30000), *lang(40162).split("|")): for n, old_path in enumerate(files): old_path = ensure_unicode(old_path) if old_path not in files_dict: continue new_path = files_dict[old_path] xbmcvfs.mkdirs(os.path.dirname(new_path)) if rename: log.info("Renaming %s to %s...", old_path, new_path) if not xbmcvfs.rename(old_path, new_path): log.info("Renaming failed. Trying to copy and delete old file...") files_to_copy[old_path] = new_path else: log.info("Success.") else: files_to_copy[old_path] = new_path if files_to_copy: copy_files(files_to_copy, delete=rename, on_finish=on_finish) elif on_finish: on_finish()
def purge_temp_dir(): path = temp_path() temp_size = get_dir_size(path) max_size = plugin.get_setting('temp-max-size', int) * 1024 * 1024 * 1024 log.info("Current temporary folder size / Max size: %d / %d", temp_size, max_size) if temp_size > max_size: log.info("Purging temporary folder...") shutil.rmtree(path, True) if not direxists(path): # noinspection PyBroadException if xbmcvfs.mkdirs(path): log.info("New temporary folder size: %d", get_dir_size(path))
def create_folders(self): for s in list(Section): path = self.get_section_path(s) if not direxists(path): self.log.info("Creating directory: %s", path) xbmcvfs.mkdirs(path)
def temp_path(): path = ensure_path_local(plugin.get_setting('temp-path', unicode)) if not direxists(path) and not xbmcvfs.mkdirs(path): raise LocalizedError(33030, "Invalid temporary path", check_settings=True) return path