Add subtitles and start offset to playvideo command

This commit is contained in:
2025-05-04 18:21:44 +02:00
parent 7dd61daaf5
commit 0237f79ada
2 changed files with 15 additions and 5 deletions

View File

@@ -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"}'
` `
`
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): - Seek the currently played video to a timestamp (in seconds):

14
main.py
View File

@@ -150,8 +150,14 @@ async def control_endpoint(request: Request):
elif data['command'] == "playvideo" and 'filename' in data: elif data['command'] == "playvideo" and 'filename' in data:
filename = data['filename'] filename = data['filename']
await playvideo(filename) subtitles = None
logger.info(f"Video playback requested: {filename}") 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: elif data['command'] == "seekvideo" and 'timestamp' in data:
timestamp = data['timestamp'] timestamp = data['timestamp']
@@ -301,8 +307,8 @@ async def setscreen_single(ws: WebSocket, screen: str):
async def setscreen(screen: str): async def setscreen(screen: str):
return await manager.broadcast_binary({"type": "setscreen", "screen": screen}) return await manager.broadcast_binary({"type": "setscreen", "screen": screen})
async def playvideo(filename: str): async def playvideo(filename: str, subtitles: str, seconds_from_start: int):
return await manager.broadcast_binary({"type": "playvideo", "filename": filename}) return await manager.broadcast_binary({"type": "playvideo", "filename": filename, "subtitles": subtitles, "seconds_from_start": seconds_from_start})
async def seekvideo(timestamp: int): async def seekvideo(timestamp: int):
return await manager.broadcast_binary({"type": "seekvideo", "timestamp": timestamp}) return await manager.broadcast_binary({"type": "seekvideo", "timestamp": timestamp})