fix now playing info

This commit is contained in:
Ben Harris 2020-09-07 22:29:27 -04:00
parent 727e563a3e
commit a391496a0e
1 changed files with 17 additions and 5 deletions

View File

@ -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())
)