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://utvghefxggihh5ts.onion/listen" | play -q - 2>/dev/null'
m.reply 'http://soyuz.labr.xyz:8000 - qua sta l\'interfaccia webbosa - poi ritorna'
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 - 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)
info = `mpc`.split("\n")
return if info.empty? || info.count <3
title = Base64.decode64(info[0].split('#').last).chomp
songs,time = "0"
if info[1] =~ /.* #[0-9]+\/([0-9]+)\s(.*)/
songs = $1
time = $2.strip
end
m.reply CGI.unescapeHTML(title)+" ["+time+"] "+songs+" songs in playlist"
end
def on_next(m)
`mpc next`
end
end