Skip to content

Instantly share code, notes, and snippets.

@sorah
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sorah/9dc74fedbf1ea7c1bfbe to your computer and use it in GitHub Desktop.
Save sorah/9dc74fedbf1ea7c1bfbe to your computer and use it in GitHub Desktop.
require 'socket'
require 'securerandom'
session = SecureRandom.uuid
TCPSocket.open('Apple-TV.local', 7000) do |io|
payload = <<-EOF
Content-Location: ...
Start-Position: 0
EOF
request = <<-EOF
POST /play HTTP/1.1
User-Agent: MediaControl/1.0
Content-Length: #{payload.size}
X-Apple-Session-ID: #{session}
#{payload}
EOF
io.puts request
Thread.new do
loop do
io.puts <<-EOF
GET /scrub HTTP/1.1
User-Agent: MediaControl/1.0
X-Apple-Session-ID: #{session}
EOF
sleep 10
end
end
Thread.new do
sleep 2
TCPSocket.open('Apple-TV.local', 7000) do |io2|
io2.puts <<-EOF
POST /reverse HTTP/1.1
Upgrade: PTTH/1.0
Connection: Upgrade
X-Apple-Purpose: event
Content-Length: 0
User-Agent: MediaControl/1.0
X-Apple-Session-ID: #{session}
EOF
while buf = io2.gets
p [:event,buf]
end
p [:event, :closed]
end
end
while buf = io.gets
p [:main,buf]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment