OK.. I was able to "pair" up to the AppleTV and can send it commands and get info... now it's just a matter of writing something nice and Indigo friendly to use it.
Remember - my python skills SUCK... and this could easily be automated...
first you need a python helper script to pair up... copy and paste to a file. Edit the script and change "devicename" to something memorable (this will show up in your AppleTV and iTunes windows -- I used Indigo when I did it):
- Code: Select all
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import struct
class PairingHandler(BaseHTTPRequestHandler):
def do_GET(self):
# any incoming requests are just pairing code related
# return our guid regardless of input
values = {
'cmpg': '\x00\x00\x00\x00\x00\x00\x00\x01',
'cmnm': 'devicename',
'cmty': 'ipod',
}
encoded = ''
for key, value in values.iteritems():
encoded += '%s%s%s' % (key, struct.pack('>i', len(value)), value)
header = 'cmpa%s' % (struct.pack('>i', len(encoded)))
encoded = '%s%s' % (header, encoded)
self.send_response(200)
self.end_headers()
self.wfile.write(encoded)
return
try:
port = 1024
server = HTTPServer(('', port), PairingHandler)
print 'started server on port %s' % (port)
server.serve_forever()
except KeyboardInterrupt:
server.socket.close()
Open up a terminal, and run the script; it will tell you it's listening on a certain port -- likely 1024
In a second window, execute this command, swapping out the port and DvNm) (this, of course, will only work on a Mac):
- Code: Select all
mDNS -R myPython _touch-remote._tcp . <port> DvNm="Indigo" RevV=10000 DvTy=iPod txtVers=1 Pair=0000000000000001
This sends out a Bonjour broadcast that tells the AppleTV/iTunes that something wants to talk to them. You should now see your device name show up on the AppleTV Remotes Settings page. Select it, and enter any number for the PIN code. Hit Done -- and your python script will show a response line from the AppleTV that looks sort of like this (and you get your AppleTV's IP address):
- Code: Select all
10.0.75.100 - - [08/May/2009 16:31:46] "GET /pair?pairingcode=1DF5CF004F9D7AEDD088FD875D02&servicename=3BAB04A31784FE4F HTTP/1.1" 200 -
You don't need anything from this. You can Control-C out of the python script now. Your new "Remote" will show up in the linked remotes list on AppleTV.
You're paired up.
Now, to actually talk to the AppleTV, you have to have something decoding what comes back. Normally, you'd have whatever is making your requests do this, but in our case, we're going to use this simple script:
http://dacp.jsharkey.org/decode.txt ... save it to disk.
Now to actually do something, you have to get a session ID from the AppleTV. You do this by sending it a login HTTP request; your GUID is your device ID; if you don't want it to be ...0001, you'd have to set it in the above responder python script (cmpg). Unless you're going to have two computers running this, I wouldn't worry about it.
- Code: Select all
curl -vvv -H "" "http://10.0.75.100:3689/login?pairing-guid=0x0000000000000001" | python decode.txt
If all goes right, you'll get a response back with your session ID.
- Code: Select all
mlog --+
mstt 4 000000c8 == 200
mlid 4 5d923ba8 == 1569864616
The mlid is your session ID; you need the decimal value (second one), not hex.
Now you can make the AppleTV do stuff:
- Code: Select all
curl -vvv -H "" "http://10.0.75.100:3659/ctrl-int/1/playstatusupdate?revision-number=1&session-id=1569864616" | python decode.txt
and you get back...
- Code: Select all
cmst --+
mstt 4 000000c8 == 200
cmsr 4 0000004c == 76
caps 1 03 == 3
cash 1 00 == 0
carp 1 00 == 0
cavc 1 01 == 1
caas 4 00000001 == 1
caar 4 00000001 == 1
cann 16 Very Busy People
cana 14 The Limousines
canl 25 Very Busy People - Single
cant 4 0003bd08 == 245000
cast 4 0003c0f0 == 246000
from here, the website I grabbed this from is correct:
http://dacp.jsharkey.org/ -- jump down to "Protocol and common tasks" -- it tells you the protocol commands and what the different values mean when they come back.
So this is the backbone of it. Now I have to write something to receive commands from Indigo, get a session ID (I have no idea how long a session ID lasts)... the AppleTV even has a "push" mode so you can have something just camp out and listen for changes.