August 17, 2005
All Quiet

I seem to have left my iPod playing when I got home last night, 'cos it was dead this morning. I hate commuting without music. (It's happy enough now though - it was just the battery.)

Besides which, being the nerd I am, I had to knock this up to make sure that my metadata is still correct:

import win32com.client
def main():
    iTunes = win32com.client.gencache.EnsureDispatch("iTunes.Application")
    quiet_tracks_playlist = iTunes.LibrarySource.Playlists.ItemByName('Reduce Played Count')
    for track in quiet_tracks_playlist.Tracks:
        print 'reducing played count for', track.Artist, '-', track.Album, '-', track.Name, 'from', track.PlayedCount,
        track.PlayedCount -= 1       
        print 'to', track.PlayedCount
if __name__ == '__main__':

How sad is that?

(I suppose that I'll be learning how to script iTunes all over again once I've got my new Mac.)

Why do I care about re-setting the played count? 'Cos I want this to be right:

import datetime
import time
import win32com.client
def main():
    iTunes = win32com.client.gencache.EnsureDispatch("iTunes.Application")
    total_time = datetime.timedelta(0)
    for track in iTunes.LibraryPlaylist.Tracks:
            track_time = time.strptime(track.Time, '%M:%S')
        except ValueError:
            track_time = time.strptime(track.Time, '%H:%M:%S')
        track_length = datetime.timedelta(hours=track_time.tm_hour,
        track_time = track_length * track.PlayedCount
        total_time += track_time
    print 'Total iPod time:', total_time
if __name__ == '__main__':
    raw_input('Hit enter to continue...')

And how sad is that?

Posted to iPod by Simon Brunning at August 17, 2005 05:08 PM
Post a comment

Email Address:



Remember info?