show callsigns for ham radio dmr ids
This commit is contained in:
		| @@ -80,6 +80,8 @@ digimodes_fft_size=1024 | ||||
| # determines the quality, and thus the cpu usage, for the ambe codec used by digital voice modes | ||||
| # if you're running on a Raspi (up to 3B+) you'll want to leave this on 1 | ||||
| digital_voice_unvoiced_quality = 1 | ||||
| # enables lookup of DMR ids using the radioid api | ||||
| digital_voice_dmr_id_lookup = True | ||||
|  | ||||
| """ | ||||
| Note: if you experience audio underruns while CPU usage is 100%, you can:  | ||||
|   | ||||
| @@ -1318,7 +1318,15 @@ function update_metadata(meta) { | ||||
|             if (meta.slot) { | ||||
|                 var html = 'Timeslot: ' + meta.slot; | ||||
|                 if (meta.type) html += ' Typ: ' + meta.type; | ||||
|                 if (meta.source && meta.target) html += ' Source: ' + meta.source + ' Target: ' + meta.target; | ||||
|                 if (meta.additional && meta.additional.callsign) { | ||||
|                     html += ' Source: ' + meta.additional.callsign; | ||||
|                     if (meta.additional.fname) { | ||||
|                         html += ' (' + meta.additional.fname + ')'; | ||||
|                     } | ||||
|                 } else if (meta.source) { | ||||
|                     html += ' Source: ' + meta.source; | ||||
|                 } | ||||
|                 if (meta.target) html += ' Target: ' + meta.target; | ||||
|                 update = function(_, el) { | ||||
|                     var slotEl = el.getElementsByClassName('slot-' + meta.slot); | ||||
|                     if (!slotEl.length) { | ||||
|   | ||||
							
								
								
									
										54
									
								
								owrx/meta.py
									
									
									
									
									
								
							
							
						
						
									
										54
									
								
								owrx/meta.py
									
									
									
									
									
								
							| @@ -1,7 +1,57 @@ | ||||
| from owrx.config import PropertyManager | ||||
| from urllib import request | ||||
| import json | ||||
| from datetime import datetime, timedelta | ||||
| import logging | ||||
|  | ||||
| logger = logging.getLogger(__name__) | ||||
|  | ||||
| class DmrMetaEnricher(object): | ||||
|     def __init__(self): | ||||
|         self.cache = {} | ||||
|         self.cacheTimeout = timedelta(seconds = 86400) | ||||
|     def cacheEntryValid(self, id): | ||||
|         if not id in self.cache: return False | ||||
|         entry = self.cache[id] | ||||
|         return entry["timestamp"] + self.cacheTimeout > datetime.now() | ||||
|     def enrich(self, meta): | ||||
|         if not PropertyManager.getSharedInstance()["digital_voice_dmr_id_lookup"]: return None | ||||
|         if not "source" in meta: return None | ||||
|         source = meta["source"] | ||||
|         if not self.cacheEntryValid(source): | ||||
|             try: | ||||
|                 logger.debug("requesting DMR metadata for id=%s", source) | ||||
|                 res = request.urlopen("https://www.radioid.net/api/dmr/user/?id={0}".format(source), timeout=5).read() | ||||
|                 data = json.loads(res.decode("utf-8")) | ||||
|                 self.cache[source] = { | ||||
|                     "timestamp": datetime.now(), | ||||
|                     "data": data | ||||
|                 } | ||||
|             except json.JSONDecodeError: | ||||
|                 self.cache[source] = { | ||||
|                     "timestamp": datetime.now(), | ||||
|                     "data": None | ||||
|                 } | ||||
|         data = self.cache[source]["data"] | ||||
|         if "count" in data and data["count"] > 0 and "results" in data: | ||||
|             return data["results"][0] | ||||
|         return None | ||||
|  | ||||
|  | ||||
| class MetaParser(object): | ||||
|     enrichers = { | ||||
|         "DMR": DmrMetaEnricher() | ||||
|     } | ||||
|     def __init__(self, handler): | ||||
|         self.handler = handler | ||||
|     def parse(self, meta): | ||||
|         fields = meta.split(";") | ||||
|         dict = {v[0] : "".join(v[1:]) for v in map(lambda x: x.split(":"), fields)} | ||||
|         self.handler.write_metadata(dict) | ||||
|         meta = {v[0] : "".join(v[1:]) for v in map(lambda x: x.split(":"), fields)} | ||||
|  | ||||
|         if "protocol" in meta: | ||||
|             protocol = meta["protocol"] | ||||
|             if protocol in MetaParser.enrichers: | ||||
|                 additional_data = MetaParser.enrichers[protocol].enrich(meta) | ||||
|                 if additional_data is not None: meta["additional"] = additional_data | ||||
|         self.handler.write_metadata(meta) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jakob Ketterl
					Jakob Ketterl