def backend_video_thumbnails(job): videos_data, job_id, db_folder, thumb_folder, job_notifier = job list_file_path = AbsolutePath.file_path(db_folder, job_id, "thumbnails.list") json_file_path = AbsolutePath.file_path(db_folder, job_id, "thumbnails.json") with open(list_file_path.path, "wb") as file: for file_path, thumb_name in videos_data: file.write(f"{file_path}\t{thumb_folder}\t{thumb_name}\t\n".encode()) nb_loaded = job_video_thumbnails_to_json( ( list_file_path.path, json_file_path.path, len(videos_data), job_id, job_notifier, ) ) assert json_file_path.isfile() arr = parse_json(json_file_path) assert arr[-1] is None arr.pop() assert nb_loaded + len(arr) == len(videos_data) list_file_path.delete() json_file_path.delete() return arr
def __init__(self, path: PathType): path = AbsolutePath.ensure(path) folder = path.get_directory() self.__json_path = path self.__prev_path = AbsolutePath.file_path(folder, path.title, "prev.json") self.__next_path = AbsolutePath.file_path(folder, path.title, "next.json") self.__thumb_folder = AbsolutePath.join(folder, f"{path.title}.thumbnails")
def _move_video_file(self, video_id: int, directory: str): self.provider.register_notifications() try: filename = self.database.get_video_filename(video_id) directory = AbsolutePath.ensure_directory(directory) if not PathTree(self.database.video_folders).in_folders(directory): raise exceptions.ForbiddenVideoFolder( directory, self.database.video_folders) dst = AbsolutePath.file_path(directory, filename.file_title, filename.extension) self.copy_work = FileCopier(filename, dst, notifier=self.notifier, notify_end=False) with Profiler(self.database.lang.profile_move, notifier=self.notifier): done = self.copy_work.move() self.copy_work = None if done: old_path = self.database.change_video_path(video_id, dst) if old_path: old_path.delete() self.provider.refresh() self.notifier.notify(Done()) else: self.notifier.notify(Cancelled()) except Exception as exc: self.database.notifier.notify( End( self.database.lang.error_moving_file.format( name=type(exc).__name__, message=exc))) finally: self.db_loading_thread = None
def generate_non_existing_path(directory, name, extension): file_id = 0 while True: file_path = AbsolutePath.file_path(directory, f"{name}{file_id}", extension) if file_path.exists(): file_id += 1 else: break return file_path
def generate_temp_file_path(extension): temp_file_id = 0 while True: temp_file_path = AbsolutePath.file_path( TEMP_DIR, "%s%s" % (TEMP_PREFIX, temp_file_id), extension) if temp_file_path.exists(): temp_file_id += 1 else: break return temp_file_path
def backend_video_infos(job): file_names, job_id, database_folder, job_notifier = job list_file_path = AbsolutePath.file_path(database_folder, str(job_id), "list") json_file_path = AbsolutePath.file_path(database_folder, str(job_id), "json") with open(list_file_path.path, "wb") as file: for file_name in file_names: file.write(f"{file_name}\n".encode()) count = job_video_to_json( ( list_file_path.path, json_file_path.path, len(file_names), job_id, job_notifier, ) ) assert json_file_path.isfile() arr = parse_json(json_file_path) # assert len(arr) == count, (len(arr), count) list_file_path.delete() json_file_path.delete() return arr
def new_sub_file(folder: AbsolutePath, extension: str): return AbsolutePath.file_path(folder, folder.title, extension)
def generate_thumb_path(folder, thumb_name): # type: (AbsolutePath, str) -> AbsolutePath return AbsolutePath.file_path(folder, thumb_name, THUMBNAIL_EXTENSION)