#!/usr/bin/python # -*- Mode: Python ; tab-width: 4 -*- import sys import os import string import getopt import common mainFName = "songs.html" byNameFName = "songsByName.html" byDateFName = "songsByDate.html" byCountFName = "songsByCount.html" byTimeFName = "songsByTime.html" def usage(): sys.stderr.write( "Usage: %s\n" % (os.path.basename(sys.argv[0])) ) sys.exit( 1 ) def main(): try: (odict, args) = getOptions() except getopt.error: sys.stderr.write( str(sys.exc_info()[1]) + "\n" ) usage() gen() def gen(): d = common.loadAlbumData() l = getSongs( d.values() ) genByDate( l ) genByCount( l ) genByName( l ) genByTime( l ) def getSongs( albums ): l = [] for album in albums: for song in album.songs: l.append( song ) return l def genByDate( l ): genInner( l, byDateFName, byLastPlayed ) for fname in [mainFName]: if os.path.exists( fname ): os.unlink( fname ) os.symlink( byDateFName, fname ) def genByCount( l ): genInner( l, byCountFName, byCount ) def genByName( l ): genInner( l, byNameFName, byName ) def genByTime( l ): genInner( l, byTimeFName, byTime ) def genInner( l, fname, sortfunc ): #print "Writing page %s..." % (fname) f = open( fname, "w" ) f.write( common.getHeader( "Dr. Zeus' Playlist: Songs", currentTab="songs" ) ) genTableHeader( f, sortfunc ) l.sort( sortfunc ) genTableRows( f, l ) genTableFooter( f, l ) f.write( common.getFooter() ) f.close() def genTableHeader( f, sortfunc ): f.write( "
Song | " ) f.write( "Artist | " ) f.write( "Album | " ) f.write( "Time | " % (byTimeFName) ) f.write( "Last Played | " % (byDateFName) ) f.write( "Play Count | " % (byCountFName) ) elif (sortfunc == byTime): f.write( "Song | " % (byNameFName) ) f.write( "Artist | " ) f.write( "Album | " ) f.write( "Time | " ) f.write( "Last Played | " % (byDateFName) ) f.write( "Play Count | " % (byCountFName) ) elif (sortfunc == byCount): f.write( "Song | " % (byNameFName) ) f.write( "Artist | " ) f.write( "Album | " ) f.write( "Time | " % (byTimeFName) ) f.write( "Last Played | " % (byDateFName) ) f.write( "Play Count | " ) else: f.write( "Song | " % (byNameFName) ) f.write( "Artist | " ) f.write( "Album | " ) f.write( "Time | " % (byTimeFName) ) f.write( "Last Played | " ) f.write( "Play Count | " % (byCountFName) ) f.write( "
%s | " % (song.name) ) f.write( "%s | " % (song.artist.getLink()) ) f.write( "%s | " % (song.album.getLink()) ) f.write( "%s | " % (common.formatDuration(song.duration)) ) f.write( "%s | " % (common.formatPlayDate(song.last_played)) ) f.write( "%s | " % (song.play_count) ) f.write( "||||||||||||||||||
%d Song%s | " % (len(l), common.plural(len(l))) ) f.write( "%d Artist%s | " % (len(artists), common.plural(len(artists))) ) f.write( "%d Album%s | " % (len(albums), common.plural(len(albums))) ) f.write( "%s | " % (common.formatDuration(duration)) ) f.write( "-- | " ) f.write( "%d Play%s | " % (count, common.plural(count)) ) f.write( "