def update_folder(self, details, folder): """ :type details: Details :type folder: Folder """ media_path = self.get_media_path(details.section, details.title) if not direxists(media_path): self.log.info("Creating library folder: %s", media_path) xbmcvfs.mkdir(media_path) else: self.log.info("Updating library folder: %s", media_path) self.storage[folder.id] = (details.media_id, media_path, details.section) files = folder.files """ :type : list of File """ for f in files: file_path = os.path.join(media_path, self.get_file_name(folder.id, f.title)) if not xbmcvfs.exists(file_path): self.log.info("Adding file: %s", file_path) fp = xbmcvfs.File(file_path, 'w') can_mark_watched = len(files) == 1 and not details.section.is_series() url = plugin.url_for('play_file', section=details.section.filter_val, media_id=details.media_id, url=f.link, title=f.title, can_mark_watched=int(can_mark_watched)) fp.write(ensure_str(url)) fp.close() return media_path
def has_folder(self, folder_id): if folder_id in self.storage: if direxists(self.storage[folder_id][1]): return True else: del self.storage[folder_id] return False
def save_path(local=False): path = plugin.get_setting('save-path', unicode) if path == plugin.get_setting('temp-path', unicode): raise LocalizedError(33032, "Path for downloaded files and temporary path should not be the same", check_settings=True) if not direxists(path): raise LocalizedError(33031, "Invalid save path", check_settings=True) if local: path = ensure_path_local(path) return ensure_unicode(path)
def save_path(local=False): path = plugin.get_setting('save-path', unicode) if path == plugin.get_setting('temp-path', unicode): raise LocalizedError(33032, "Path for downloaded files and temporary path should not be the same", check_settings=True) if not direxists(path): raise LocalizedError(33031, "Invalid save path", check_settings=True) if local: path = ensure_path_local(path) path = path.strip("\\/") return ensure_unicode(path)
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 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 remove_folder(self, folder_id): if folder_id not in self.storage: return media_path = self.storage[folder_id][1] del self.storage[folder_id] if not direxists(media_path): return self.log.info("Removing from library folder: %s", media_path) files = xbmcvfs.listdir(media_path)[1] count_deleted = 0 for f in files: if f.endswith("[%d].strm" % folder_id): path = os.path.join(media_path, f) self.log.info("Removing file: %s", path) xbmcvfs.delete(path) count_deleted += 1 if len(files) == count_deleted: self.log.info("All files deleted, removing folder: %s", media_path) xbmcvfs.rmdir(media_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