From 4596d11200ff50db736e0101062434f7cf0e2137 Mon Sep 17 00:00:00 2001 From: Patrick Moessler Date: Mon, 22 May 2023 01:08:22 +0200 Subject: [PATCH] add overwrite feature --- src/add_tracks.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/add_tracks.py b/src/add_tracks.py index 88511c1..c5d342c 100644 --- a/src/add_tracks.py +++ b/src/add_tracks.py @@ -24,11 +24,17 @@ def test_dir(files: List[str], pattern: str) -> List[str]: log.debug("trying:\n " + "\n ".join(files)) valid_files = fnmatch.filter(files, pattern) if valid_files: - log.debug("found:\n " + "\n ".join(valid_files)) + log.info("found:\n " + "\n ".join(valid_files)) return valid_files -def main(media_path: str, tag: str, pattern: str, recursive: bool = False) -> None: +def main( + media_path: str, + tag: str, + pattern: str, + recursive: bool = False, + overwrite: bool = False, +) -> None: abs_media_path = os.path.abspath(media_path) log.info( f"Scanning {abs_media_path}{' recursively' if recursive else ''} for {pattern}" @@ -58,7 +64,7 @@ def main(media_path: str, tag: str, pattern: str, recursive: bool = False) -> No if config is None: raise FileNotFoundError(f"Config file could not be loaded for tag id: {tag}") - tracks: List[str] = config.get("tracks", []) + tracks: List[str] = config.get("tracks", []) if not overwrite else [] tracks.extend(sorted((f.replace("\\", "/") for f in valid_paths))) config["tracks"] = tracks @@ -94,6 +100,13 @@ if __name__ == "__main__": help="Search recursively. Pattern applies to whole path (relative to media_path).", ) + parser.add_argument( + "-o", + "--overwrite", + action="store_true", + help="Overwrite and replace existing track list.", + ) + args = parser.parse_args() logging.basicConfig(level=logging.INFO) @@ -104,4 +117,5 @@ if __name__ == "__main__": tag=args.tag, pattern=args.pattern, recursive=args.recursive, + overwrite=args.overwrite, )