ADD list command to CLI for displaying all markers

This commit is contained in:
2025-12-18 20:17:54 +00:00
parent 3c870c7a69
commit 143f4e0c8d
2 changed files with 41 additions and 17 deletions

View File

@@ -1,7 +1,28 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import sys import sys
import argparse 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: def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
@@ -11,21 +32,9 @@ def build_parser() -> argparse.ArgumentParser:
sub = parser.add_subparsers(dest="command", required=True) sub = parser.add_subparsers(dest="command", required=True)
save = sub.add_parser("save", help="Save a section from the current recording") build_save_parser(sub)
save.add_argument( build_mark_parser(sub)
"-s", "--seconds", build_list_parser(sub)
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"
)
return parser return parser
@@ -37,6 +46,8 @@ def main(argv=None) -> int:
clip(args.seconds) clip(args.seconds)
elif args.command == "mark": elif args.command == "mark":
mark(args.name) mark(args.name)
elif args.command == "list":
print_markers()
else: else:
parser.error("Unknown command") parser.error("Unknown command")

View File

@@ -80,11 +80,24 @@ def mark(name: str) -> None:
"name": name, "name": name,
"timestamp": datetime.datetime.now().timestamp() "timestamp": datetime.datetime.now().timestamp()
}) })
with open(markers_file, "w") as f: with open(markers_file, "w") as f:
json.dump(markers, f, indent=4) json.dump(markers, f, indent=4)
print(f"Added marker: {name}") 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: def get_duration(file_path: str) -> float:
result = subprocess.run( result = subprocess.run(
["ffprobe", "-v", "error", "-show_entries", ["ffprobe", "-v", "error", "-show_entries",