Skip to content

Instantly share code, notes, and snippets.

@donSchoe
Created February 27, 2013 23:01
Show Gist options
  • Save donSchoe/5052649 to your computer and use it in GitHub Desktop.
Save donSchoe/5052649 to your computer and use it in GitHub Desktop.
icecast plugin for fantasy-irc
# icecast2 plugin for fantasy-irc.
# quick and dirty.
# not for public use.
require 'mechanize'
require 'xmlsimple'
def update_xml
# icecast server details
@server = ''
@port = 8000
@user = ''
@password = ''
@mount = ''
# 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")
end
def get_now_playing
update_xml
page = @agent.current_page.content.to_s
xml = XmlSimple.xml_in(page)
# check status of mount point
i = 0
status = "Mount point #{@mount} kann nicht gefunden werden: Stream offline?"
xml['source'].each do
tmpmount = xml['source'][i]['mount']
# if correct mount point, get status info
if tmpmount.eql? @mount
status = "Jetzt im Radio: " + xml['source'][i]['title'].join + " (" + xml['source'][i]['server_name'].join + ": " + xml['source'][i]['listeners'].join + " H\u{F6}rer)"
end
i +=1
end
status = status
end
def get_full_status
update_xml
page = @agent.current_page.content.to_s
xml = XmlSimple.xml_in(page)
# check status of mount point
i = 0
status = "Mount point #{@mount} kann nicht gefunden werden: Stream offline?"
xml['source'].each do
tmpmount = xml['source'][i]['mount']
# if correct mount point, get status info
if tmpmount.eql? @mount
status = "Titel: " + xml['source'][i]['title'].join + ", Sendung: " + xml['source'][i]['server_name'].join + ", H\u{F6}rer aktuell: " + xml['source'][i]['listeners'].join + ", H\u{F6}rer-Verbindungen: " + xml['listener_connections'].join + ", H\u{F6}rer-Peak: " + xml['source'][i]['listener_peak'].join + ", H\u{F6}rer-Limit: " + xml['source'][i]['max_listeners'].join + ", Software: " + xml['source'][i]['user_agent'].join + ", Quell-IP: " + xml['source'][i]['source_ip'].join + ", Stand: " + xml['source'][i]['metadata_updated'].join
end
i +=1
end
status = status
end
plugin = Plugin.new "icecast"
plugin.handle(/^help$/i) do |data|
if data[:room].name.eql? "#karl-moiks"
next data[:room].say "Punkrockers Radio Bot Commands: .help .stream .prr .status"
else
next data[:room].say "Punkrockers Radio Bot Commands: .help .stream .prr"
end
end
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|
status = get_now_playing
next data[:room].say status
end
plugin.handle(/^prr$/i) do |data|
status = get_now_playing
next data[:room].say status
end
plugin.handle(/^status$/i) do |data|
if data[:room].name.eql? "#karl-moiks"
status = get_full_status
next data[:room].say status
end
end
$bot.plugins.add(plugin)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment