def send_update(metadata): if metadata.hifiberry_cover_found: return if metadata.mbid is None: return key = "update" + metadata.songId() best_picture_url(key, metadata.externalArtUrl) artUrl = best_picture_url(key, metadata.artUrl) if artUrl is not None: (width, height) = best_picture_size(key) else: return if metadata.albummbid is not None: mbid = metadata.albummbid else: mbid = metadata.mbid data = {"mbid": mbid, "url": artUrl, "width": width, "height": height} try: logging.info("sending cover update to hifiberry musicdb") url = "{}/cover-update".format(BASE_URL) post_data(url, data) except Exception as e: logging.exception(e)
def notify(self, metadata): if metadata.artist is None or metadata.title is None: logging.debug("ignoring undefined metatdata") return data = { "frames": [{ "text": metadata.artist + "-" + metadata.title, "icon": "a22046", "duration": 10000, }] } headers = { "X-Access-Token": ACCESS_TOKEN, "Accept": "application/json", "Cache-Control": "no-cache" } for url in self.urls: logging.info("sending update to LaMetric at %s", url) report_usage("audiocontrol_lametric_metadata", 1) post_data(url, json.dumps(data), headers=headers, verify=False)
def guess_stream_order(stream, field1, field2, use_cloud=True): MIN_STAT_RATIO = 0.1 MIN_STATS=10 if stream.startswith("http"): caching_supported = True else: caching_supported = False logging.warn("not a web radio stream, won't use caching") stats = stream_stats.get(stream,{"ta": 0, "at": 0, "order": ORDER_UNKNOWN, "cloud": ORDER_UNKNOWN}) at = stats["at"] ta = stats["ta"] cloud = stats["cloud"] if stats["order"] != ORDER_UNKNOWN: return stats["order"] if stats["cloud"] != ORDER_UNKNOWN: return stats["cloud"] # Check hifiberry cloud if order is known for this stream if caching_supported: try: cacheinfo = retrieve_url(cloud_url(CACHE_PATH), params = { 'stream' : stream }) if cacheinfo is not None: cloud = int(cacheinfo.content) else: cloud = ORDER_UNKNOWN except Exception as e: logging.exception(e) if cloud in [ ORDER_ARTIST_TITLE, ORDER_TITLE_ARTIST]: order = cloud stream_order = cloud else: stream_order = ORDER_UNKNOWN order = guess_order(field1, field2) if order == ORDER_ARTIST_TITLE: at += 1 elif order == ORDER_TITLE_ARTIST: ta += 1 logging.debug("at/ta: %s/%s",at,ta) if stream_order == ORDER_UNKNOWN and at+ta > MIN_STATS: if float(at)*MIN_STAT_RATIO > ta: stream_order = ORDER_ARTIST_TITLE elif float(ta)*MIN_STAT_RATIO > at: stream_order = ORDER_TITLE_ARTIST else: stream_order = ORDER_UNKNOWN logging.info("guess stream %s is using %s encoding (%s/%s)", stream, verbose[stream_order], at, ta) if use_cloud and caching_supported and stream_order != ORDER_UNKNOWN: post_data(cloud_url(CACHE_PATH), { "stream": stream, "order": stream_order}) else: stream_order = ORDER_UNKNOWN stream_stats[stream]={"order": stream_order, "ta": ta, "at": at, "cloud": cloud} return order
def test_post(self): res = post_data(POST, {"test": "testdata"}) self.assertIsNotNone(res)