MODULARISE clip file into separate functions & ADD argparser
This commit is contained in:
@@ -1,29 +1,59 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from video import clip
|
from rewind.video import clip
|
||||||
|
|
||||||
import obsws_python as obs
|
import obsws_python as obs
|
||||||
import sys, os
|
import sys, argparse
|
||||||
|
|
||||||
command = sys.argv[1] if len(sys.argv) > 1 else None
|
command = sys.argv[1] if len(sys.argv) > 1 else None
|
||||||
|
|
||||||
con = obs.ReqClient()
|
def start_recording(con):
|
||||||
response = con.get_version()
|
|
||||||
print(f"OBS WebSocket Version: {response.obs_web_socket_version}")
|
|
||||||
|
|
||||||
if command == "start":
|
|
||||||
con.start_record()
|
con.start_record()
|
||||||
print(f"Started recording")
|
print("Started recording")
|
||||||
elif command == "stop":
|
|
||||||
|
def stop_recording(con):
|
||||||
con.stop_record()
|
con.stop_record()
|
||||||
print("Stopped recording")
|
print("Stopped recording")
|
||||||
elif command == "clip":
|
|
||||||
|
def create_clip(con):
|
||||||
record_dir = con.get_record_directory()
|
record_dir = con.get_record_directory()
|
||||||
output_file_name = f"{datetime.now().strftime("%Y-%m-%d %H:%M:%S")}.mp4"
|
output_file_name = f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}.mp4"
|
||||||
clip(record_dir.record_directory, output_file_name)
|
clip(record_dir.record_directory, output_file_name)
|
||||||
|
|
||||||
print(f"Created clip: {output_file_name}")
|
print(f"Created clip: {output_file_name}")
|
||||||
else:
|
|
||||||
print("Unknown command. Use 'start', 'stop', or 'clip'.")
|
|
||||||
|
|
||||||
|
def build_parser():
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
prog="rewind",
|
||||||
|
description="Control OBS recording and create instant clips",
|
||||||
|
)
|
||||||
|
|
||||||
|
sub = parser.add_subparsers(dest="command", required=True)
|
||||||
|
|
||||||
|
sub.add_parser("start", help="Start OBS recording")
|
||||||
|
sub.add_parser("stop", help="Stop OBS recording")
|
||||||
|
sub.add_parser("clip", help="Create a clip from the current recording")
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def main(argv=None):
|
||||||
|
parser = build_parser()
|
||||||
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
|
con = obs.ReqClient()
|
||||||
|
|
||||||
|
try:
|
||||||
|
if args.command == "start":
|
||||||
|
start_recording(con)
|
||||||
|
elif args.command == "stop":
|
||||||
|
stop_recording(con)
|
||||||
|
elif args.command == "clip":
|
||||||
|
create_clip(con)
|
||||||
|
else:
|
||||||
|
parser.error("Unknown command")
|
||||||
|
|
||||||
|
finally:
|
||||||
con.disconnect()
|
con.disconnect()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
||||||
Reference in New Issue
Block a user