A python scripting interface for iTunes.
Mac OSx only
pip install tunes
git clone git://github.com/robertf224/pyTunes.git && cd pyTunes
python setup.py install
pyTunes contains several useful convenience functions.
import pyTunes as pytunes
pytunes.playtrack('Someday')
pytunes.playartist('The Strokes')
pytunes.playalbum('Room on Fire')
These functions are all case insensitive, and playtrack also filters out terms in parentheses and brackets.
# This will play "Runaway [feat. Pusha T]"
pytunes.playtrack('rUnAwAY')
These functions could easily be applied to create interesting hacks. For example, they could be tied with an API like that provied by Twilio to create a jukebox application, or be combined with a speech-to-text engine to make a voice-controlled iTunes remote.
These are all pretty self-explanatory. These functions could be used with a library like BreakfastSerial to create an Arduino-based iTunes remote.
pytunes.skip()
# Will only go to beginning of song depending on how far into the song we are, may go to previous song
pytunes.back()
# Will definitely go to the previous song
pytunes.prev()
# Toggle Play/Pause
pytunes.playpause()
pytunes.play()
pytunes.pause()
# Toggle Mute/Unmute
pytunes.muteunmute()
pytunes.mute()
pytunes.unmute()
pytunes.setvolume(100)
pytunes.getvolume()
# Move to 1 minute 40 seconds into current song
pytunes.setposition(100)
pytunes.getposition()
pyTunes also provides a Track wrapper class that internally handles some track-related things. Track objects can be obtained through several functions of pyTunes.
# Gets current track
track = pytunes.playing()
# info now holds a reference to a dictionary containing some metadata about the track
info = track.getinfo()
# matches now holds a reference to an array containing Track objects that match the search term (by name, artist, album, etc.)
matches = pytunes.search('rain')
# We can play a 5 second preview of each match
import time
for track in matches:
track.play()
time.sleep(5)