radio.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. require 'cgi'
  2. class Radio
  3. include Cinch::Plugin
  4. match /radio play (.*)$/, :method => :on_play
  5. match /radio pialla/, :method => :on_pialla
  6. match /radio help/, :method => :on_help
  7. match /radio info/, :method => :on_info
  8. match /radio next/, :method => :on_next
  9. def on_play(m, link)
  10. if link =~ /http(s):\/\/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-]+)(&(amp;)?[\w\?=]*)?/
  11. File.open('/tmp/radio', 'w') do |f|
  12. f.puts(link)
  13. f.flush
  14. end
  15. if open(link).read =~ /<title>(.*?) - YouTube<\/title>/
  16. m.reply "New song \""+CGI.unescapeHTML($1)+"\""
  17. File.open('/tmp/notify-send', 'w') do |f|
  18. f.puts($1)
  19. f.flush
  20. end
  21. end
  22. end
  23. end
  24. def on_help(m)
  25. m.reply 'curl "http://utvghefxggihh5ts.onion/listen" | play -q - 2>/dev/null'
  26. m.reply 'http://soyuz.labr.xyz:8000 - qua sta l\'interfaccia webbosa - poi ritorna'
  27. m.reply 'comandi: '
  28. m.reply ' info - ti dice la canzone che stai sentendo'
  29. m.reply ' pialla - cancella la canzone che stai sentendo'
  30. m.reply ' play <linkdiyoutube> - mette una canzone in playlist'
  31. m.reply ' next - ti fa sentire un altra roba'
  32. end
  33. def on_pialla(m)
  34. File.open('/tmp/notify-send', 'w') do |f|
  35. f.puts("Sto piallando")
  36. f.flush
  37. end
  38. system("mpc del $(mpc -f %position% | head -n 1)")
  39. end
  40. def on_info(m)
  41. info = `mpc`.split("\n")
  42. return if info.empty? || info.count <3
  43. title = Base64.decode64(info[0].split('#').last).chomp
  44. songs,time = "0"
  45. if info[1] =~ /.* #[0-9]+\/([0-9]+)\s(.*)/
  46. songs = $1
  47. time = $2.strip
  48. end
  49. m.reply CGI.unescapeHTML(title)+" ["+time+"] "+songs+" songs in playlist"
  50. end
  51. def on_next(m)
  52. `mpc next`
  53. end
  54. end