mirror of
https://github.com/oddluck/limnoria-plugins.git
synced 2025-04-28 22:41:08 -05:00
AzuraCast: video stream viewers
This commit is contained in:
parent
f9487be74b
commit
2e6f9141da
@ -31,11 +31,19 @@ AzuraCast = conf.registerPlugin("AzuraCast")
|
|||||||
# This is where your configuration variables (if any) should go. For example:
|
# This is where your configuration variables (if any) should go. For example:
|
||||||
# conf.registerGlobalValue(AzuraCast, 'someConfigVariableName',
|
# conf.registerGlobalValue(AzuraCast, 'someConfigVariableName',
|
||||||
# registry.Boolean(False, _("""Help for someConfigVariableName.""")))
|
# registry.Boolean(False, _("""Help for someConfigVariableName.""")))
|
||||||
|
|
||||||
conf.registerGlobalValue(
|
conf.registerGlobalValue(
|
||||||
AzuraCast, "AzuraAPI", registry.String("", _("""AzuraCast local API URL"""))
|
AzuraCast, "AzuraAPI", registry.String("", _("""AzuraCast local API URL"""))
|
||||||
)
|
)
|
||||||
|
|
||||||
conf.registerGlobalValue(
|
conf.registerGlobalValue(
|
||||||
AzuraCast, "PublicURL", registry.String("", _("""Public URL for your radio"""))
|
AzuraCast, "PublicURL", registry.String("", _("""Public URL for your radio"""))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
conf.registerGlobalValue(
|
||||||
|
AzuraCast,
|
||||||
|
"VideoURL",
|
||||||
|
registry.String("", _("""Video URL. Should end in /stats.json.php""")),
|
||||||
|
)
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
###
|
###
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from supybot import utils, plugins, ircutils, callbacks
|
from supybot import utils, plugins, ircutils, callbacks
|
||||||
from supybot.commands import *
|
from supybot.commands import *
|
||||||
|
|
||||||
@ -28,9 +27,9 @@ class AzuraCast(callbacks.Plugin):
|
|||||||
def __init__(self, irc):
|
def __init__(self, irc):
|
||||||
self.__parent = super(AzuraCast, self)
|
self.__parent = super(AzuraCast, self)
|
||||||
self.__parent.__init__(irc)
|
self.__parent.__init__(irc)
|
||||||
|
|
||||||
self.BASE_API = self.registryValue("AzuraAPI")
|
self.BASE_API = self.registryValue("AzuraAPI")
|
||||||
self.PUB_URL = self.registryValue("PublicURL") + "#{name}"
|
self.PUB_URL = self.registryValue("PublicURL") + "#{name}"
|
||||||
|
self.VID_URL = self.registryValue("VideoURL")
|
||||||
|
|
||||||
def _fetchURL(self, url, headers=None):
|
def _fetchURL(self, url, headers=None):
|
||||||
return requests.get(url, headers=headers).json()
|
return requests.get(url, headers=headers).json()
|
||||||
@ -66,15 +65,11 @@ class AzuraCast(callbacks.Plugin):
|
|||||||
options = dict(options)
|
options = dict(options)
|
||||||
station = options.get("station")
|
station = options.get("station")
|
||||||
url = self.BASE_API + "nowplaying"
|
url = self.BASE_API + "nowplaying"
|
||||||
|
|
||||||
data = self._fetchURL(url)
|
data = self._fetchURL(url)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
irc.reply("ERROR: Something went wrong fetching data @ {}".format(url))
|
irc.reply("ERROR: Something went wrong fetching data @ {}".format(url))
|
||||||
return
|
return
|
||||||
|
|
||||||
data = self._parseData(data)
|
data = self._parseData(data)
|
||||||
|
|
||||||
output = []
|
output = []
|
||||||
if station:
|
if station:
|
||||||
# one station only
|
# one station only
|
||||||
@ -112,10 +107,8 @@ class AzuraCast(callbacks.Plugin):
|
|||||||
prefix, np, album, listeners, url, listen
|
prefix, np, album, listeners, url, listen
|
||||||
)
|
)
|
||||||
output.append(string)
|
output.append(string)
|
||||||
|
|
||||||
for string in output:
|
for string in output:
|
||||||
irc.reply(string)
|
irc.reply(string)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@wrap([getopts({"station": "somethingWithoutSpaces"})])
|
@wrap([getopts({"station": "somethingWithoutSpaces"})])
|
||||||
@ -126,15 +119,11 @@ class AzuraCast(callbacks.Plugin):
|
|||||||
options = dict(options)
|
options = dict(options)
|
||||||
station = options.get("station")
|
station = options.get("station")
|
||||||
url = self.BASE_API + "nowplaying"
|
url = self.BASE_API + "nowplaying"
|
||||||
|
|
||||||
data = self._fetchURL(url)
|
data = self._fetchURL(url)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
irc.reply("ERROR: Something went wrong fetching data @ {}".format(url))
|
irc.reply("ERROR: Something went wrong fetching data @ {}".format(url))
|
||||||
return
|
return
|
||||||
|
|
||||||
data = self._parseData(data)
|
data = self._parseData(data)
|
||||||
|
|
||||||
output = []
|
output = []
|
||||||
if station:
|
if station:
|
||||||
# one station only
|
# one station only
|
||||||
@ -166,10 +155,18 @@ 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"]))
|
||||||
output.append(string)
|
output.append(string)
|
||||||
|
if self.VID_URL:
|
||||||
|
data = self._fetchURL(self.VID_URL)
|
||||||
|
d = data.get("applications")
|
||||||
|
if d:
|
||||||
|
d = d[0].get("users")
|
||||||
|
if d:
|
||||||
|
views = d.get("online")
|
||||||
|
if views:
|
||||||
|
string = "There are {} viewers on the video stream".format(views)
|
||||||
|
output.append(string)
|
||||||
for string in output:
|
for string in output:
|
||||||
irc.reply(string)
|
irc.reply(string)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user