From a391496a0e1ca9f452800001b2bb8a364fa27361 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Mon, 7 Sep 2020 22:29:27 -0400 Subject: [PATCH] fix now playing info --- tilderadio.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tilderadio.py b/tilderadio.py index a68ffd3..ede045b 100644 --- a/tilderadio.py +++ b/tilderadio.py @@ -13,7 +13,8 @@ NOTIFY_CHANNELS = [CHANNEL, "#meta", "#team", "#club"] LISTEN_URL = "https://tilderadio.org/listen" SCHEDULE_URL = "https://tilderadio.org/schedule/" SOURCE_URL = "https://tildegit.org/ben/bitbot-modules" -RADIO_API_BASE = "https://radio.tildeverse.org/api" +AZURACAST_API_BASE = "https://radio.tildeverse.org/api" +ICECAST_API_BASE = "https://radio.tildeverse.org/radio/8000" TOOT_CREDS_FILE = "/home/ben/.bitbot/tilderadio-toot.json" SLOGANS = [ "The soundtrack in your cat's head", @@ -70,13 +71,19 @@ class Module(ModuleManager.BaseModule): def save_nowplaying(self, jsontxt): if jsontxt == "": - data = utils.http.request(RADIO_API_BASE + "/nowplaying/1").json() + data = utils.http.request(AZURACAST_API_BASE + "/nowplaying/1").json() else: data = json.loads(jsontxt) + # get the song name directly from icecast + icecast_data = utils.http.request(ICECAST_API_BASE + "/status-json.xsl").json() + self.song = icecast_data["icestats"]["source"][0]["title"] + + # azuracast's now playing info is broken + # https://github.com/AzuraCast/AzuraCast/issues/3142 + # self.song = data["now_playing"]["song"]["text"] self.is_online = data["live"]["is_live"] self.dj = data["live"]["streamer_name"] - self.song = data["now_playing"]["song"]["text"] self.listeners = data["listeners"]["current"] def format_nowplaying(self): @@ -180,6 +187,7 @@ class Module(ModuleManager.BaseModule): @utils.hook("received.command.nowplaying") @utils.kwarg("help", "show the current song on tilderadio") def nowplaying(self, event): + self.save_nowplaying("") event["stdout"].write(self.format_nowplaying()) @utils.hook("received.command.schedule") @@ -191,7 +199,9 @@ class Module(ModuleManager.BaseModule): @utils.hook("received.command.upnext") @utils.kwarg("help", "show who's up next to stream") def upnext(self, event): - js = utils.http.request(RADIO_API_BASE + "/station/1/schedule?rows=1").json() + js = utils.http.request( + AZURACAST_API_BASE + "/station/1/schedule?rows=1" + ).json() if len(js) < 1: event["stdout"].write("nothing scheduled") else: @@ -305,4 +315,6 @@ class Module(ModuleManager.BaseModule): @utils.hook("received.command.utcnow") @utils.kwarg("help", "show current utc time") def utcnow(self, event): - event["stdout"].write(utils.datetime.format.datetime_human(utils.datetime.utcnow())) + event["stdout"].write( + utils.datetime.format.datetime_human(utils.datetime.utcnow()) + )