Guest User

Untitled

a guest
Jan 22nd, 2018
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. require 'shout'
  2. require 'open-uri'
  3.  
  4. class TestWorker
  5. include Sidekiq::Worker
  6. sidekiq_options :queue => :testworker
  7. def perform(*_args)
  8. prev_song = nil
  9. s = Shout.new # ruby-shout instance
  10. s.mount = "/hiphop" # our mountpoint
  11. s.charset = "UTF-8"
  12. s.port = 35689 # the port we've specified earlier
  13. s.host = 'localhost' # hostname
  14. s.user = 'source' # credentials
  15. s.pass = 'hackme'
  16. s.format = Shout::MP3 # format is MP3
  17. s.description = 'Geek Radio' # an arbitrary name
  18. s.connect
  19.  
  20.  
  21. loop do # endless loop to peform streaming
  22. #Song.where(current: true).each do |song| # make sure all songs are not `current`
  23. #song.toggle! :current
  24. #end
  25. Song.where(genre: "hiphop").each do |song|
  26. #prev_song.toggle!(:current) if prev_song # if there was a previously played song, set `current` to `false`
  27. #song.toggle! :current # a new song is playing so it is `current` now
  28.  
  29. open("https://s3.amazonaws.com/ramunity-development#{song.mp3.path}") do |file| # open the public URL
  30. m = ShoutMetadata.new # add metadata
  31. m.add 'filename', song.mp3_file_name
  32. m.add 'title', song.title
  33. m.add 'artist', song.artist
  34. s.metadata = m
  35.  
  36. while data = file.read(16384) # read the portions of the file
  37. s.send data # send portion of the file to Icecast
  38. s.sync
  39. end
  40. end
  41. #prev_song = song # the song has finished playing
  42. end
  43. end # end of the endless loop
  44.  
  45. s.disconnect # disconnect from the server
  46. end
  47. end
Add Comment
Please, Sign In to add comment