AzuraCast: fix error when no video

This commit is contained in:
oddluck 2020-06-30 21:55:44 +00:00
parent 3e33f0eae8
commit e6d5e29e14

View File

@ -89,14 +89,17 @@ class AzuraCast(callbacks.Plugin):
self.BASE_API.replace("/api/", ""), d["id"] self.BASE_API.replace("/api/", ""), d["id"]
) )
if self.VID_URL: if self.VID_URL:
data_url = self.VID_URL + "stats.json.php" try:
data = self._fetchURL(data_url) data_url = self.VID_URL + "stats.json.php"
d = data.get("applications")[0] data = self._fetchURL(data_url)
if d: d = data.get("applications")[0]
c = d.get("channelName") if d:
users = d.get("users") c = d.get("channelName")
if users: users = d.get("users")
views = users.get("online") if users:
views = users.get("online")
except:
pass
if c and views: if c and views:
viewers = " | Viewers: {}".format(views) viewers = " | Viewers: {}".format(views)
watch = " | Video Player: {}?c={}".format(self.VID_URL, c) watch = " | Video Player: {}?c={}".format(self.VID_URL, c)
@ -125,14 +128,17 @@ class AzuraCast(callbacks.Plugin):
self.BASE_API.replace("/api/", ""), d["id"] self.BASE_API.replace("/api/", ""), d["id"]
) )
if self.VID_URL: if self.VID_URL:
data_url = self.VID_URL + "stats.json.php" try:
data = self._fetchURL(data_url) data_url = self.VID_URL + "stats.json.php"
d = data.get("applications")[i] data = self._fetchURL(data_url)
if d: d = data.get("applications")[i]
c = d.get("channelName") if d:
users = d.get("users") c = d.get("channelName")
if users: users = d.get("users")
views = users.get("online") if users:
views = users.get("online")
except:
pass
if c and views: if c and views:
viewers = " | Viewers: {}".format(views) viewers = " | Viewers: {}".format(views)
watch = " | Video Player: {}?c={}".format(self.VID_URL, c) watch = " | Video Player: {}?c={}".format(self.VID_URL, c)
@ -178,17 +184,20 @@ class AzuraCast(callbacks.Plugin):
plr = " " plr = " "
string = "There {}{}on {}".format(cur, plr, ircutils.bold(d["name"])) string = "There {}{}on {}".format(cur, plr, ircutils.bold(d["name"]))
if self.VID_URL: if self.VID_URL:
url = self.VID_URL + "stats.json.php" try:
data = self._fetchURL(url) url = self.VID_URL + "stats.json.php"
d = data.get("applications") data = self._fetchURL(url)
if d: d = data.get("applications")
d = d[0].get("users") if d:
if d: d = d[0].get("users")
views = d.get("online") if d:
if views: views = d.get("online")
string += " and there are \x02{}\x02 viewers on the video stream.".format( if views:
views string += " and there are \x02{}\x02 viewers on the video stream.".format(
) views
)
except:
pass
output.append(string) output.append(string)
else: else:
# all stations? # all stations?
@ -206,17 +215,21 @@ class AzuraCast(callbacks.Plugin):
plr = " " plr = " "
string = "There {}{}on {}".format(cur, plr, ircutils.bold(d["name"])) string = "There {}{}on {}".format(cur, plr, ircutils.bold(d["name"]))
if self.VID_URL: if self.VID_URL:
url = self.VID_URL + "stats.json.php" try:
data = self._fetchURL(url) url = self.VID_URL + "stats.json.php"
d = data.get("applications") data = self._fetchURL(url)
if d: d = data.get("applications")
d = d[i].get("users") if d:
if d: d = d[i].get("users")
views = d.get("online") if d:
if views: views = d.get("online")
string += " and there are \x02{}\x02 viewers on the video stream.".format( if views:
views string += (
) " and there are \x02{}\x02 viewers on the video stream."
.format(views)
)
except:
pass
i += 1 i += 1
output.append(string) output.append(string)
for string in output: for string in output: