Skip to content

Instantly share code, notes, and snippets.

@IdoBn
Last active December 16, 2021 02:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save IdoBn/2a398bdd9fd46572637c to your computer and use it in GitHub Desktop.
Save IdoBn/2a398bdd9fd46572637c to your computer and use it in GitHub Desktop.
ras pi version of jook box
require 'json'
require 'rest-client'
URL = "http://music-hasalon-api.herokuapp.com"
AWS_URL = 'http://ec2-54-85-146-44.compute-1.amazonaws.com:8989/api/info?url='
$current_song = nil
def direct_url(yt_link)
JSON.parse(RestClient.get("#{AWS_URL}#{yt_link.split('&feature=')[0]}"))["direct_url"]
end
Thread.new do
puts "Thread is running..."
loop do
begin
party = JSON.parse(RestClient.get("#{URL}/parties/27"))["party"]
request = party["requests"].first
unless request["id"] == $current_song
puts 'killing all!'
`sudo killall omxplayer.bin`
`sudo killall poptart`
puts 'all have been killed!'
end
rescue
puts 'unless troubles'
end
sleep 5
puts "."
end
end
loop do
begin
puts 'getting requests'
party = JSON.parse(RestClient.get("#{URL}/parties/27"))["party"]
request = party["requests"].first
puts "\nfirst request: #{request}\n"
puts 'getting direct url'
dir_uri = direct_url(request["url"])
puts dir_uri
puts 'playing song'
$current_song = request["id"]
system "/home/pi/poptart/poptart -s 80 -t 60000 'by: #{request['user']['name'].split(' ')[0]}' &"
`omxplayer #{dir_uri}`
puts 'song is done setting to played'
RestClient.patch("#{URL}/requests/#{request['id']}/played", {
user_access_token: "54f37dcce50f53fe37f8653160aa1c56"
})
puts 'song set played!'
rescue
puts "\nno songs :(\n"
end
sleep 5
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment