def set_media_folder(self, path): logger.info("set media folder %s" % path) if not self.disk.exists(path): return Result.failed("Media path '%s' doesn't exists" % path) if not self.disk.is_dir(path): return Result.failed("Media path '%s' isn't directory" % path) self.media_folder = path return Result.success()
def get_listdir(self, url): if self.check_url(url): if self.disk.is_public_dir(url): listdir = list(self.disk.public_listdir(url)) listdir.sort(key=lambda x: x.type == "dir", reverse=True) names = [self.header, ] for i in listdir: names.append(self.get_info(i)) return Result.success((names, url)) else: return Result.failed("Url isn't public") return Result.failed("Url doesnt't exist")
def download_media(self, media_name, dir_name): # check media media_path = Path(self.media_folder) / media_name logger.info("Check path %s" % media_path.as_posix()) if not self.disk.exists(media_path.as_posix()): return Result.failed("Media path isn't found") temp_path = Path(dir_name) / media_name download_result = self.download(media_path.as_posix(), temp_path.as_posix()) if download_result.is_ok(): if download_result.result(): return Result.success(temp_path.as_posix()) else: return Result.failed("Something has gone wrong") else: return download_result
def get_listdir(self, path=None): logger.info("Open path %s" % path) if path is None: path = magic_const.YADISK_PREFIX if not self.disk.is_dir(path): return Result.failed("Path doesn't exist") names = [ self.header, ] listdir = list(self.disk.listdir(path)) listdir.sort(key=lambda x: x.type == "dir", reverse=True) for i in listdir: names.append(self.get_info(i)) return Result.success((names, path))
def get_key(self, algorithm_type, key_type, key, media_path, media_type): logger.info("Key-file path %s" % media_path) if key_type == KeyType.new_symbols: if not key: return Result.failed("Why have you deleted the key?") return Result.success(key) elif key_type == KeyType.existing_symbols: if not key: return Result.failed("Write down password") return Result.success(key) elif key_type == KeyType.new_binary: if not media_path: return Result.failed("Select file for key") key = self.generate_key(algorithm_type) with open(media_path, "wb") as f: f.write(key) return Result.success(key) elif key_type == KeyType.existing_binary: if not media_path: return Result.failed("Select file with key") with open(media_path, "rb") as f: key = f.read() return Result.success(key) elif key_type == KeyType.new_media: if not key: return Result.failed("Write down password") if not media_path: return Result.failed("Select media file") if media_type == MediaType.f5steganography: key_key = self.generate_key(algorithm_type) embed_into_image(media_path, key_key.decode("utf-8"), key) elif media_type == MediaType.fractals: key_size = magic_const.KEY_LENGTH[algorithm_type] key_key = fractals.generate_key(media_path, key.decode("utf-8"), key_size) elif media_type == MediaType.dct: key_size = magic_const.KEY_LENGTH[algorithm_type] key_key = dct_algorithm.generate_key(media_path, key.decode("utf-8"), key_size) else: logger.error("Bad media type %s" % media_type) return Result.success(key_key) elif key_type == KeyType.existing_media: if not key: return Result.failed("Write down password") if not media_path: return Result.failed("Select media file") if media_type == MediaType.f5steganography: key_key = extract_from_image(media_path, key.decode("utf-8")) key_key = key_key.encode("utf-8") logger.info("Key len %d" % len(key_key)) elif media_type == MediaType.fractals: key_size = magic_const.KEY_LENGTH[algorithm_type] key_key = fractals.generate_key(media_path, key.decode("utf-8"), key_size) elif media_type == MediaType.dct: key_size = magic_const.KEY_LENGTH[algorithm_type] key_key = dct_algorithm.generate_key(media_path, key.decode("utf-8"), key_size) else: logger.error("Bad media type %s" % media_type) return Result.success(key_key)