diff --git a/ytplaylist/cli.py b/ytplaylist/cli.py index 61ced11..ce4d907 100644 --- a/ytplaylist/cli.py +++ b/ytplaylist/cli.py @@ -27,7 +27,8 @@ def main(): parser = argparse.ArgumentParser(prog="yt-playlist") parser.add_argument("-c", "--config", default="yt-playlist-config.json", help="Path to config file") parser.add_argument("-d", "--debug", action="store_true", help="Enable debug logging and show binary output") - parser.add_argument("-y", "--yes", "--non-interactive", dest="yes", action="store_true", help="Run non-interactively (auto-confirm prompts)") + parser.add_argument("-p", "--prune", dest="prune", action="store_true", help="Enable pruning: delete files not present in the playlist") + parser.add_argument("-y", "--yes", "--non-interactive", dest="yes", action="store_true", help="Run non-interactively (auto-confirm prompts, used with --prune)") args = parser.parse_args() configure_logging(args.debug) @@ -40,5 +41,6 @@ def main(): manager = PlaylistManager(cfg, debug=args.debug) # support non-interactive mode for CI setattr(cfg, "non_interactive", bool(args.yes)) + setattr(cfg, "prune", bool(args.prune)) logger.debug("Starting PlaylistManager with debug=%s", args.debug) manager.run() diff --git a/ytplaylist/downloader.py b/ytplaylist/downloader.py index 421e17d..50c0a5c 100644 --- a/ytplaylist/downloader.py +++ b/ytplaylist/downloader.py @@ -20,6 +20,8 @@ class PlaylistDownloader: self.debug = bool(config.debug) # non-interactive mode for CI/automated runs self.non_interactive = bool(getattr(config, "non_interactive", False)) + # prune controls whether cleanup actually deletes files; default False + self.prune = bool(getattr(config, "prune", False)) self.url = playlist.get("url") self.skip = False @@ -359,6 +361,10 @@ class PlaylistDownloader: for f in to_delete: self.logger.warning(" %s", f.name) + if not self.prune: + self.logger.info("Prune disabled; no files will be deleted in '%s'.", folder) + return + try: if self.non_interactive: confirm = "y"