Display recorder system highlights
This commit is contained in:
@@ -4,8 +4,10 @@ import concurrent.futures
|
||||
import json
|
||||
import re
|
||||
import subprocess
|
||||
import struct
|
||||
import threading
|
||||
import os
|
||||
from datetime import datetime
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
from pathlib import Path
|
||||
from urllib.parse import parse_qs, urlparse
|
||||
@@ -63,6 +65,24 @@ def normalize_date(value):
|
||||
return date
|
||||
|
||||
|
||||
def scan_system_highlights(root):
|
||||
try:
|
||||
data = (root / "fileindex.dat").read_bytes()
|
||||
except OSError:
|
||||
return []
|
||||
highlights = []
|
||||
for offset in range(0, len(data) - 15, 16):
|
||||
timestamp, packed, _, _ = struct.unpack_from("<4I", data, offset)
|
||||
duration = packed & 0xffff
|
||||
event = (packed >> 16) & 1
|
||||
if not event or not duration:
|
||||
continue
|
||||
moment = datetime.fromtimestamp(timestamp)
|
||||
start = moment.hour * 3600 + moment.minute * 60 + moment.second
|
||||
highlights.append({"date": moment.strftime("%Y%m%d"), "start": start, "end": min(86400, start + duration)})
|
||||
return highlights
|
||||
|
||||
|
||||
class PlayerHandler(BaseHTTPRequestHandler):
|
||||
protocol_version = "HTTP/1.1"
|
||||
|
||||
@@ -82,6 +102,9 @@ class PlayerHandler(BaseHTTPRequestHandler):
|
||||
return self.send_json(self.server.encode_status)
|
||||
if request.path == "/api/highlights":
|
||||
return self.send_json(self.server.highlights)
|
||||
if request.path == "/api/system-highlights":
|
||||
date = parse_qs(request.query).get("date", [""])[0]
|
||||
return self.send_json([item for item in self.server.system_highlights if item["date"] == date])
|
||||
if request.path == "/video":
|
||||
return self.send_video(request.query)
|
||||
self.send_error(404)
|
||||
@@ -276,6 +299,7 @@ def main():
|
||||
server.output_root = args.root.expanduser().resolve()
|
||||
server.highlights_path = server.output_root / "highlights.json"
|
||||
server.highlights = load_highlights(server.highlights_path)
|
||||
server.system_highlights = scan_system_highlights(server.source_root)
|
||||
server.encode_status = {"running": False, "total": 0, "completed": 0, "skipped": 0, "failed": 0}
|
||||
count = sum(map(len, recordings.values()))
|
||||
print(f"Indexed {count} recordings across {len(recordings)} days")
|
||||
|
||||
Reference in New Issue
Block a user