Skip to content

Instantly share code, notes, and snippets.

@lidio601
Last active August 29, 2015 14:01
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 lidio601/24a0638d08288d0e9d67 to your computer and use it in GitHub Desktop.
Save lidio601/24a0638d08288d0e9d67 to your computer and use it in GitHub Desktop.
Python script + AppScript python binding to export an iTunes Music Playlist to an Android phone directory or a car USB key.
#!/opt/local/bin/python2.4
from appscript import *
import shutil
import os
itunes = app('itunes')
# nome della playlist da copiare
playlist_name = "toUSB"
# directory di destinazione
destination_path = "/Volumes/USBKEY"
# gather the current playlists
playlists = {}
album_folder = False
# cerco la playlist
for playlist in itunes.playlists():
playlists[playlist.name()] = playlist
if playlist.name() == playlist_name:
album_folder = playlist
# se la trovo scorro i file audio e
# li copio nella directory di destinazione
if album_folder:
tracks = album_folder.tracks()
for track in tracks:
filename = track.location().path
if os.path.exists(filename):
to = "%s/%s" % (destination_path,filename.split("/")[-1])
if os.path.exists(to) == False:
shutil.copy2(filename,to)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment