metadata fixes
This commit is contained in:
@@ -89,7 +89,14 @@ class CallRecorder:
|
|||||||
logger.warning("Recording file empty or missing — discarding.")
|
logger.warning("Recording file empty or missing — discarding.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def upload_recording(self, file_path: Path, call_id: str) -> Optional[str]:
|
async def upload_recording(
|
||||||
|
self,
|
||||||
|
file_path: Path,
|
||||||
|
call_id: str,
|
||||||
|
talkgroup_id: Optional[int] = None,
|
||||||
|
talkgroup_name: Optional[str] = None,
|
||||||
|
system_id: Optional[str] = None,
|
||||||
|
) -> Optional[str]:
|
||||||
if not settings.c2_url:
|
if not settings.c2_url:
|
||||||
logger.info("No C2_URL configured — skipping upload.")
|
logger.info("No C2_URL configured — skipping upload.")
|
||||||
return None
|
return None
|
||||||
@@ -98,13 +105,21 @@ class CallRecorder:
|
|||||||
api_key = credentials.get_api_key()
|
api_key = credentials.get_api_key()
|
||||||
headers = {"Authorization": f"Bearer {api_key}"} if api_key else {}
|
headers = {"Authorization": f"Bearer {api_key}"} if api_key else {}
|
||||||
|
|
||||||
|
form: dict = {"call_id": call_id, "node_id": settings.node_id}
|
||||||
|
if talkgroup_id is not None:
|
||||||
|
form["talkgroup_id"] = str(talkgroup_id)
|
||||||
|
if talkgroup_name:
|
||||||
|
form["talkgroup_name"] = talkgroup_name
|
||||||
|
if system_id:
|
||||||
|
form["system_id"] = system_id
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with httpx.AsyncClient(timeout=120) as client:
|
async with httpx.AsyncClient(timeout=120) as client:
|
||||||
with open(file_path, "rb") as f:
|
with open(file_path, "rb") as f:
|
||||||
r = await client.post(
|
r = await client.post(
|
||||||
upload_url,
|
upload_url,
|
||||||
files={"file": (file_path.name, f, "audio/mpeg")},
|
files={"file": (file_path.name, f, "audio/mpeg")},
|
||||||
data={"call_id": call_id, "node_id": settings.node_id},
|
data=form,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
)
|
)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class MetadataWatcher:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._running = False
|
self._running = False
|
||||||
self._current_tgid: Optional[int] = None
|
self._current_tgid: Optional[int] = None
|
||||||
|
self._current_tgid_name: Optional[str] = None
|
||||||
self._hang_counter: int = 0
|
self._hang_counter: int = 0
|
||||||
self._active_call_id: Optional[str] = None
|
self._active_call_id: Optional[str] = None
|
||||||
self._call_started_at: Optional[datetime] = None
|
self._call_started_at: Optional[datetime] = None
|
||||||
@@ -82,10 +83,11 @@ class MetadataWatcher:
|
|||||||
async def _start_call(self, tgid: int, meta: dict):
|
async def _start_call(self, tgid: int, meta: dict):
|
||||||
self._active_call_id = str(uuid.uuid4())
|
self._active_call_id = str(uuid.uuid4())
|
||||||
self._call_started_at = datetime.now(timezone.utc)
|
self._call_started_at = datetime.now(timezone.utc)
|
||||||
|
self._current_tgid_name = meta.get("tag") or meta.get("tgid_tag") or ""
|
||||||
payload = {
|
payload = {
|
||||||
"call_id": self._active_call_id,
|
"call_id": self._active_call_id,
|
||||||
"tgid": tgid,
|
"tgid": tgid,
|
||||||
"tgid_name": meta.get("tag") or meta.get("tgid_tag") or "",
|
"tgid_name": self._current_tgid_name,
|
||||||
"freq": meta.get("freq"),
|
"freq": meta.get("freq"),
|
||||||
"srcaddr": meta.get("srcaddr"),
|
"srcaddr": meta.get("srcaddr"),
|
||||||
"started_at": self._call_started_at.isoformat(),
|
"started_at": self._call_started_at.isoformat(),
|
||||||
@@ -100,12 +102,14 @@ class MetadataWatcher:
|
|||||||
payload = {
|
payload = {
|
||||||
"call_id": self._active_call_id,
|
"call_id": self._active_call_id,
|
||||||
"tgid": self._current_tgid,
|
"tgid": self._current_tgid,
|
||||||
|
"tgid_name": self._current_tgid_name or "",
|
||||||
"started_at": self._call_started_at.isoformat() if self._call_started_at else None,
|
"started_at": self._call_started_at.isoformat() if self._call_started_at else None,
|
||||||
"ended_at": datetime.now(timezone.utc).isoformat(),
|
"ended_at": datetime.now(timezone.utc).isoformat(),
|
||||||
}
|
}
|
||||||
logger.info(f"Call end: id={self._active_call_id}")
|
logger.info(f"Call end: id={self._active_call_id}")
|
||||||
self._active_call_id = None
|
self._active_call_id = None
|
||||||
self._current_tgid = None
|
self._current_tgid = None
|
||||||
|
self._current_tgid_name = None
|
||||||
self._hang_counter = 0
|
self._hang_counter = 0
|
||||||
self._call_started_at = None
|
self._call_started_at = None
|
||||||
if self.on_call_end:
|
if self.on_call_end:
|
||||||
|
|||||||
@@ -31,7 +31,14 @@ async def on_call_end(data: dict):
|
|||||||
radio_bot.stop_stream()
|
radio_bot.stop_stream()
|
||||||
file_path = await call_recorder.stop_recording()
|
file_path = await call_recorder.stop_recording()
|
||||||
if file_path:
|
if file_path:
|
||||||
audio_url = await call_recorder.upload_recording(file_path, data["call_id"])
|
node_cfg = load_node_config()
|
||||||
|
audio_url = await call_recorder.upload_recording(
|
||||||
|
file_path,
|
||||||
|
data["call_id"],
|
||||||
|
talkgroup_id=data.get("tgid"),
|
||||||
|
talkgroup_name=data.get("tgid_name"),
|
||||||
|
system_id=node_cfg.assigned_system_id,
|
||||||
|
)
|
||||||
if audio_url:
|
if audio_url:
|
||||||
data["audio_url"] = audio_url
|
data["audio_url"] = audio_url
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user