diff --git a/rewind/cli.py b/rewind/cli.py index d975a15..ab71a46 100755 --- a/rewind/cli.py +++ b/rewind/cli.py @@ -1,7 +1,28 @@ #!/usr/bin/env python3 import sys import argparse -from rewind.core import clip, mark +from rewind.core import clip, mark, print_markers + +def build_save_parser(subparsers: argparse._SubParsersAction) -> None: + save_parser = subparsers.add_parser("save", help="Save a section from the current recording") + save_parser.add_argument( + "-s", "--seconds", + type=int, + default=30, + help="Number of seconds to include in the clip (default: 30)" + ) + +def build_mark_parser(subparsers: argparse._SubParsersAction) -> None: + mark_parser = subparsers.add_parser("mark", help="Mark the current time in the recording for later reference") + mark_parser.add_argument( + "-n", "--name", + type=str, + required=True, + help="Name of the marker" + ) + +def build_list_parser(subparsers: argparse._SubParsersAction) -> None: + list_parser = subparsers.add_parser("list", help="List all markers in the recording") def build_parser() -> argparse.ArgumentParser: parser = argparse.ArgumentParser( @@ -11,21 +32,9 @@ def build_parser() -> argparse.ArgumentParser: sub = parser.add_subparsers(dest="command", required=True) - save = sub.add_parser("save", help="Save a section from the current recording") - save.add_argument( - "-s", "--seconds", - type=int, - default=30, - help="Number of seconds to include in the clip (default: 30)" - ) - - mark = sub.add_parser("mark", help="Mark the current time in the recording for later reference") - mark.add_argument( - "-n", "--name", - type=str, - required=True, - help="Name of the marker" - ) + build_save_parser(sub) + build_mark_parser(sub) + build_list_parser(sub) return parser @@ -37,6 +46,8 @@ def main(argv=None) -> int: clip(args.seconds) elif args.command == "mark": mark(args.name) + elif args.command == "list": + print_markers() else: parser.error("Unknown command") diff --git a/rewind/core.py b/rewind/core.py index bb35eaa..dbc1ead 100644 --- a/rewind/core.py +++ b/rewind/core.py @@ -80,11 +80,24 @@ def mark(name: str) -> None: "name": name, "timestamp": datetime.datetime.now().timestamp() }) - + with open(markers_file, "w") as f: json.dump(markers, f, indent=4) print(f"Added marker: {name}") +def print_markers() -> None: + markers_file = os.path.join(os.path.dirname(__file__), "markers.json") + if not os.path.exists(markers_file): + print("No markers found.") + return + + with open(markers_file, "r") as f: + markers = json.load(f) + + for marker in markers: + format_time = datetime.datetime.fromtimestamp(marker['timestamp']).strftime('%Y-%m-%d %H:%M:%S') + print(f"{format_time} -> {marker['name']}") + def get_duration(file_path: str) -> float: result = subprocess.run( ["ffprobe", "-v", "error", "-show_entries",