Add pruning option to PlaylistDownloader and update CLI arguments

This commit is contained in:
2025-10-21 22:06:55 +03:00
parent e1ec65094f
commit 599a0751b9
2 changed files with 9 additions and 1 deletions
+3 -1
View File
@@ -27,7 +27,8 @@ def main():
parser = argparse.ArgumentParser(prog="yt-playlist") parser = argparse.ArgumentParser(prog="yt-playlist")
parser.add_argument("-c", "--config", default="yt-playlist-config.json", help="Path to config file") 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("-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() args = parser.parse_args()
configure_logging(args.debug) configure_logging(args.debug)
@@ -40,5 +41,6 @@ def main():
manager = PlaylistManager(cfg, debug=args.debug) manager = PlaylistManager(cfg, debug=args.debug)
# support non-interactive mode for CI # support non-interactive mode for CI
setattr(cfg, "non_interactive", bool(args.yes)) setattr(cfg, "non_interactive", bool(args.yes))
setattr(cfg, "prune", bool(args.prune))
logger.debug("Starting PlaylistManager with debug=%s", args.debug) logger.debug("Starting PlaylistManager with debug=%s", args.debug)
manager.run() manager.run()
+6
View File
@@ -20,6 +20,8 @@ class PlaylistDownloader:
self.debug = bool(config.debug) self.debug = bool(config.debug)
# non-interactive mode for CI/automated runs # non-interactive mode for CI/automated runs
self.non_interactive = bool(getattr(config, "non_interactive", False)) 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.url = playlist.get("url")
self.skip = False self.skip = False
@@ -359,6 +361,10 @@ class PlaylistDownloader:
for f in to_delete: for f in to_delete:
self.logger.warning(" %s", f.name) 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: try:
if self.non_interactive: if self.non_interactive:
confirm = "y" confirm = "y"