Airfoil & iTunes Control
Posted: Sat Nov 29, 2014 2:29 pm
I'd like to share a piece of Indigo Python code with you.
I have several Airplay devices around the house and started to use Airfoil to activate them after they're turned on. Sending a play command to iTunes works fine. If already playing the command is simply ignored. Pausing however should only occur if there's no other device still active. I came up with the following server side script in an action group:
It seems to get the job done. What do you think? Any pointers? Am I missing something? As I'm always on the lookout to improve, comments are appreciated
I have several Airplay devices around the house and started to use Airfoil to activate them after they're turned on. Sending a play command to iTunes works fine. If already playing the command is simply ignored. Pausing however should only occur if there's no other device still active. I came up with the following server side script in an action group:
- Code: Select all
indigo.server.log("Action Group: Pause iTunes")
noPlaying = 0
connectedValue = "connected"
airfoilName = "Airfoil"
libraryName = "My Library"
itunesPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.itunes")
if itunesPlugin.isEnabled():
folderId = indigo.variables.folders[airfoilName].id
libraryId = indigo.devices[libraryName].id
for var in indigo.variables:
if var.folderId == folderId and var.value == connectedValue:
noPlaying += 1
if noPlaying > 1:
indigo.server.log("Still playing. Let it be!")
else:
indigo.server.log("All quiet. Stop the music!")
itunesPlugin.executeAction("pause", deviceId = libraryId)
else:
indigo.server.log("No iTunes! What am I doing here?")
It seems to get the job done. What do you think? Any pointers? Am I missing something? As I'm always on the lookout to improve, comments are appreciated