Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'shout'
- require 'open-uri'
- class TestWorker
- include Sidekiq::Worker
- sidekiq_options :queue => :testworker
- def perform(*_args)
- prev_song = nil
- s = Shout.new # ruby-shout instance
- s.mount = "/hiphop" # our mountpoint
- s.charset = "UTF-8"
- s.port = 35689 # the port we've specified earlier
- s.host = 'localhost' # hostname
- s.user = 'source' # credentials
- s.pass = 'hackme'
- s.format = Shout::MP3 # format is MP3
- s.description = 'Geek Radio' # an arbitrary name
- s.connect
- loop do # endless loop to peform streaming
- #Song.where(current: true).each do |song| # make sure all songs are not `current`
- #song.toggle! :current
- #end
- Song.where(genre: "hiphop").each do |song|
- #prev_song.toggle!(:current) if prev_song # if there was a previously played song, set `current` to `false`
- #song.toggle! :current # a new song is playing so it is `current` now
- open("https://s3.amazonaws.com/ramunity-development#{song.mp3.path}") do |file| # open the public URL
- m = ShoutMetadata.new # add metadata
- m.add 'filename', song.mp3_file_name
- m.add 'title', song.title
- m.add 'artist', song.artist
- s.metadata = m
- while data = file.read(16384) # read the portions of the file
- s.send data # send portion of the file to Icecast
- s.sync
- end
- end
- #prev_song = song # the song has finished playing
- end
- end # end of the endless loop
- s.disconnect # disconnect from the server
- end
- end
Add Comment
Please, Sign In to add comment