From 0237f79adafb8ef274b9bf7d1462f864901265fb Mon Sep 17 00:00:00 2001 From: zucham Date: Sun, 4 May 2025 18:21:44 +0200 Subject: [PATCH] Add subtitles and start offset to playvideo command --- README.md | 6 +++++- main.py | 14 ++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ca8d504..f50be29 100644 --- a/README.md +++ b/README.md @@ -126,12 +126,16 @@ curl -X POST http://localhost:8000/control -H "Content-Type: application/json" - ___ -- Tell the client to play a video, defined by the filename parameter: +- Tell the client to play a video, defined by the `filename` parameter. It has optional parameters `subtitles`, which should point to a subtitle file and defaults to `null`, and `secondsfromstart` which indicated the timestap at what the video should start, which defaults to `0`: ` curl -X POST http://localhost:8000/control -H "Content-Type: application/json" -d '{"command": "playvideo", "filename": "stallman.webm"}' ` +` +curl -X POST http://localhost:8000/control -H "Content-Type: application/json" -d '{"command": "playvideo", "filename": "stallman.webm", "subtitles": "stallman.vtt", "secondsfromstart": 69}' +` + ___ - Seek the currently played video to a timestamp (in seconds): diff --git a/main.py b/main.py index 6ed792b..7087784 100644 --- a/main.py +++ b/main.py @@ -150,8 +150,14 @@ async def control_endpoint(request: Request): elif data['command'] == "playvideo" and 'filename' in data: filename = data['filename'] - await playvideo(filename) - logger.info(f"Video playback requested: {filename}") + subtitles = None + seconds_from_start = 0 + if 'subtitles' in data: + subtitles = data['subtitles'] + if 'secondsfromstart' in data: + seconds_from_start = data['secondsfromstart'] + await playvideo(filename, subtitles, seconds_from_start) + logger.info(f"Video playback requested: {filename} with subtitles {subtitles} starting {seconds_from_start} seconds from start.") elif data['command'] == "seekvideo" and 'timestamp' in data: timestamp = data['timestamp'] @@ -301,8 +307,8 @@ async def setscreen_single(ws: WebSocket, screen: str): async def setscreen(screen: str): return await manager.broadcast_binary({"type": "setscreen", "screen": screen}) -async def playvideo(filename: str): - return await manager.broadcast_binary({"type": "playvideo", "filename": filename}) +async def playvideo(filename: str, subtitles: str, seconds_from_start: int): + return await manager.broadcast_binary({"type": "playvideo", "filename": filename, "subtitles": subtitles, "seconds_from_start": seconds_from_start}) async def seekvideo(timestamp: int): return await manager.broadcast_binary({"type": "seekvideo", "timestamp": timestamp})