| |||||
Playlist to XML
Since Syncato is an XML microcontent management system the playlists I've been posting are of course XML data like everything else in Syncato. To create the lists I use iTunes to create a playlist, fill it with the songs and then extract the playlist using a combination of Python and Applescript. This could of course be accomplished with just Applescript, but I'm much more comfortable with Python then I am with Applescript. This script is actually mostly Applescript since it was originally part of a larger Python program.
#!/usr/bin/python
#
# A simple script to get a playlist from iTunes and convert it to XML
import os, sys
if (len(sys.argv) != 2):
print "Usage: playlistToXML.py playlist"
sys.exit()
playlist = sys.argv[1]
# Applescript to get the content of playlist in XML format..
getPlaylist = """tell application "iTunes"
set thePlaylist to (user playlist \"""" + playlist + """\")
set allsongs to (get name of every track of thePlaylist)
set artists to (get artist of every track of thePlaylist)
set albums to (get album of every track of thePlaylist)
set trackTime to (get time of every track of thePlaylist)
set songs to "<songlist>"
repeat with i from 1 to (count of items in allsongs)
set songs to songs & "<song><title>" & (item i in allsongs) & "</title>"
set songs to songs & "<artist>" & (item i in artists) & "</artist>"
set songs to songs & "<album>" & (item i in albums) & "</album>"
set songs to songs & "<length>" & (item i in trackTime) & "</length>"
set songs to songs & "</song>"
end repeat
set songs to songs & "</songlist>"
end tell
"""
# Read the contents of the playlist from iTunes
content = os.popen("osascript -e '" + getPlaylist + "'").read()
print content
I haven't really had much time to experiment and develop the microcontent aspect of Syncato, I've been rather caught up with other things. There are a lot of interesting things that can be done with it, but it will take sometime to build the necessary concepts and tools. Posting playlists is fun, but isn't the most compelling thing that can be done. We'll see what happens over the coming months as I get more of the pieces in place. Posted by Kimbro Staken Friday Dec 5, 2003 at 2:33 AM | Recommended Sites JumpBox Virtual Appliances Virtualization Daily Grid7 Venturecast Inspirational Technology Scrollin on Dubs MC Ping - Microcontent Notfications
Archives
XML --
subscribe
Music -- subscribe Programming -- subscribe Python -- subscribe Syncato -- subscribe Photography -- subscribe Mac OS X -- subscribe General -- subscribe Canon EOS 1D -- subscribe Canon EOS 10D -- subscribe Canon EOS Digital Rebel -- subscribe Samsung Digimax V50 -- subscribe | ||||
Copyright 2002, 2003 Kimbro Staken
Powered By: Syncato 0.8 | |||||