from os import * from os.path import * import id3reader import glob import os import sqlite3 theList = [] theTitle = [] theArtist = [] theAlbum = [] if not os.path.isfile("dump.db"): con = sqlite3.connect('dump.db') cur = con.cursor() cur.execute('CREATE TABLE lastfm (artist VARCHAR(40), album VARCHAR(40), title VARCHAR(40), path VARCHAR(150) PRIMARY KEY)') con.commit() else: con = sqlite3.connect('dump.db') cur = con.cursor() cur.execute('DROP TABLE IF EXISTS lastfm') con.commit() def recurse_dir(i): path = i+"\\" path2 = i+"\\*.mp3" t = 1 try: directories = os.listdir(path) except WindowsError : t = 0 try: songs = glob.glob(path2) except WindowsError : t = 0 if t == 1: for song in songs: id3r = id3reader.Reader(song) theTitle.append(id3r.getValue('title')) theArtist.append(id3r.getValue('performer')) theAlbum.append(id3r.getValue('album')) theList.append(song) for directory in directories: temppath = path+directory if(os.path.isdir(temppath)): recurse_dir(temppath) def listing(): L=[] for i in range(ord('a'),ord('z')+1): drive=chr(i) if(exists(drive+":\\")): L.append(drive) #print "Drive Found" for l in L: l = l+":" recurse_dir(l) listing() l=len(theList)-1 for i in range(l): artist = theArtist[i] album = theAlbum[i] title = theTitle[i] llist = theList[i] cur.execute('INSERT INTO lastfm (artist, album, title, path) VALUES(?,?,?,?)', (artist, album, title, llist)) con.commit() for row in con.execute("SELECT artist, album, title FROM lastfm"): print row