radio.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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://soyuz.labr.xyz:8080/" | play -q - 2>/dev/null'
  26. m.reply 'comandi: '
  27. m.reply ' info - ti dice la canzone che stai sentendo'
  28. m.reply ' pialla - cancella la canzone che stai sentendo'
  29. m.reply ' play <linkdiyoutube> - mette una canzone in playlist'
  30. m.reply ' next - ti fa sentire un altra roba'
  31. end
  32. def on_pialla(m)
  33. File.open('/tmp/notify-send', 'w') do |f|
  34. f.puts("Sto piallando")
  35. f.flush
  36. end
  37. system("mpc del $(mpc -f %position% | head -n 1)")
  38. end
  39. def on_info(m)
  40. title = `mpc | head -n 1 | cut -d '#' -f 2 | base64 -d`
  41. title.gsub("\n","")
  42. m.reply CGI.unescapeHTML(title)
  43. end
  44. def on_next(m)
  45. `mpc next`
  46. end
  47. end