Skip to content

Instantly share code, notes, and snippets.

@v2px
Forked from anonymous/icecast.rb
Last active December 14, 2015 07:19
Show Gist options
  • Save v2px/5049894 to your computer and use it in GitHub Desktop.
Save v2px/5049894 to your computer and use it in GitHub Desktop.
require 'mechanize'
require 'xmlsimple'
plugin = Plugin.new "icecast"
plugin.handle(/^stream$/i) do |data|
next data[:room].say "Punkrockers Stream: http://stream.punkrockers-radio.de:8000/prr"
end
plugin.handle(/^np$/i) do |data|
# icecast server details
server = 'example.net'
port = 8000
user = 'gist'
password = 'hackme'
mount = '/listen'
# connect and get status xml
agent = Mechanize.new
agent.user_agent_alias = 'Linux Firefox'
agent.add_auth("http://#{server}:#{port}/admin/status.xml", user, password)
agent.get("http://#{server}:#{port}/admin/status.xml")
page = agent.current_page.content.to_s
xml = XmlSimple.xml_in(page)
# check status of mount point
xml['source'].each do |source|
# if correct mount point, get status info
if source['mount'].eql? mount
status = "Jetzt im Radio: " + source['title'].join + " (" + source['server_name'].join + ": " + source['listeners'].join + " H\u{F6}rer)"
end
end
next data[:room].say status
end
$bot.plugins.add(plugin)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment