Last active
December 17, 2015 08:49
-
-
Save mxswd/5583116 to your computer and use it in GitHub Desktop.
Stream a video to an Apple TV.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/boxen/rbenv/shims/ruby | |
# You need these gems, set your host on the lan | |
# plus use the correct ruby path above. | |
# Also install the puma gem. | |
# You need to launch this with the FULL path to the video file. | |
require 'sinatra' | |
require 'airplay' | |
require 'socket' | |
VIDEO = ARGV[0] | |
LANHOST = "192.168.2.136:4567" | |
# For best results, go to TorrentCell.m in Transmission and replace final | |
# `if (fMouseDownRevealButton)` case to be: | |
# NSString *path = @"/opt/boxen/rbenv/shims/ruby"; | |
# NSArray *args = @[@"/usr/local/bin/airplay.rb", location]; | |
# [NSTask launchedTaskWithLaunchPath:path arguments:args]; | |
# instead of revealing in Finder. | |
# from stackoverflow | |
def local_ip | |
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true | |
UDPSocket.open do |s| | |
s.connect '64.233.187.99', 1 | |
s.addr.last | |
end | |
ensure | |
Socket.do_not_reverse_lookup = orig | |
end | |
configure do | |
set :server, :puma | |
set :bind, '0.0.0.0' | |
mime_type :video, "video/mp4" | |
end | |
fork do | |
airplay = Airplay::Client.new | |
airplay.send_video("http://#{LANHOST}/video.mp4") | |
while true | |
sleep 5 # MAGIC! | |
if airplay.scrub["duration"] == 0 | |
puts "Finished Playing" | |
exit | |
end | |
end | |
end | |
get '/video.mp4' do | |
content_type :video | |
send_file VIDEO | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment