I love when you’re able to solve problems in your real life with programming. I had to be able to play YouTube videos on my Apple TV without saving them to the hard drive, converting them and throw ‘em in to iTunes. And to get the Apple Remote and navigate to the video on the Apple TV was not on the map. After a while of googling I found that is was possible to send videos to the Apple TV with some tcp sockets.
This was something new for me, I’ve barely touched sockets in any programming language. So I thought, why not use sockets in a language I admire but never worked with (other than Hello World and some math examples)? I choose you, Python!
After some reading and testing I fell in love Python and its syntax. And everything went really smooth. The world of modules to Python is really large. And as the Apple TV uses ZeroConf (Bonjour) I needed to find a nice bonjour module. And so I did: pybonjour.
Usage:
The program it self lets you pass one parameter to the command which is a url to the video you would like to play. It must be a url at the moment. Either a YouTube link (http://www.youtube.com/watch?v=8To-6VIJZRE) or a url to a mp4 video.
To use this you must install two modules to get this running. pybonjour and requests. If you don’t know how to install a Python module. Check this post.
Download the project from GitHub and browse to the folder in the Terminal. E.g.
cd ~/Forks/AirPlayer
Now to get going you only need to type the following:
python airplayer.py http://www.youtube.com/watch?v=8To-6VIJZRE
# And the output should be something like:
Simons-MacBook-Air:AirPlayer Simon$ python airplayer.py http://www.youtube.com/watch?v=8To-6VIJZRE
Working...
-----
Available AirPlay Devices
-----
1: Apple-TV
-----
Select your airplay device...
1
Connecting to: Apple-TV
If you pass a link to YouTube the script will automatically pick the highes quality available for the Apple TV and lets you choose which device you want to send the video to. If you download the project there is some lines with comments which, if you uncomment, lets you choose video quality to send to the device.
It will soon be able to send local files with the script as well.
Fork or clone the AirPlayer project from GitHub! I appreciate any collaboration.