#!/usr/bin/python # # A simple script to post a playlist from iTunes on to a metaweblog API enabled blog. # import os import xmlrpclib # The URL for the XML-RPC interface to the blog blogURL = "http://www.yourserver.org/cgi-bin/mt-xmlrpc.cgi" # The id of the blog to post to. blogID = "2" # Username/password that has permission to post to the blog blogUsername = "" blogPassword = "" postTitle = "Top 25 Most Played Songs for the Week" # Applescript to get the content of playlist in XML format. To use a different playlist edit it here. getPlaylist = """tell application "iTunes" set crlf to (ASCII character 13) & (ASCII character 10) set thePlaylist to (user playlist "Top 25 This Month") 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 playcount to (get played count of every track of thePlaylist) set songs to "" repeat with i from 1 to (count of items in allsongs) set songs to songs & (item i in allsongs) & "|:" set songs to songs & (item i in artists) & "|:" set songs to songs & (item i in albums) & "|:" set songs to songs & (item i in playcount) & crlf end repeat end tell """ # Read the contents of the playlist from iTunes content = os.popen("osascript -e '" + getPlaylist + "'").read() # Munge the list into the format for posting resultHTML = "" songs = content.splitlines() for song in songs: try: (title, artist, album, playcount) = song.split("|:") resultHTML = resultHTML + "" except ValueError: pass resultHTML = resultHTML + "
ArtistSongAlbumPlay Count
" + artist + "" + title resultHTML = resultHTML + "" + album + "" + playcount + "
" # Post to the blog using the MetaWeblog API server = xmlrpclib.Server(blogURL) content = { 'title':postTitle, 'description':resultHTML } server.metaWeblog.newPost(blogID, blogUsername, blogPassword, content, 1)