require 'cgi' class Radio include Cinch::Plugin match /radio play (.*)$/, :method => :on_play match /radio pialla/, :method => :on_pialla match /radio help/, :method => :on_help match /radio info/, :method => :on_info match /radio next/, :method => :on_next def on_play(m, link) if link =~ /http(s):\/\/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-]+)(&(amp;)?[\w\?=]*)?/ File.open('/tmp/radio', 'w') do |f| f.puts(link) f.flush end if open(link).read =~ /(.*?) - YouTube<\/title>/ m.reply "New song \""+CGI.unescapeHTML($1)+"\"" File.open('/tmp/notify-send', 'w') do |f| f.puts($1) f.flush end end end end def on_help(m) m.reply 'curl "http://soyuz.labr.xyz:8080/" | play -q - 2>/dev/null' m.reply 'comandi: ' m.reply ' info - ti dice la canzone che stai sentendo' m.reply ' pialla - cancella la canzone che stai sentendo' m.reply ' play <linkdiyoutube> - mette una canzone in playlist' m.reply ' next - ti fa sentire un altra roba' end def on_pialla(m) File.open('/tmp/notify-send', 'w') do |f| f.puts("Sto piallando") f.flush end system("mpc del $(mpc -f %position% | head -n 1)") end def on_info(m) title = `mpc | head -n 1 | cut -d '#' -f 2 | base64 -d` title.gsub("\n","") m.reply CGI.unescapeHTML(title) end def on_next(m) `mpc next` end end