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