class Library(): """holds and organizes songs Probably other things, once I figure out what those things are """ def __init__(self, database): """ set the location of database """ self.database = Interface(database) self.load_songs() def load_songs(self): """ loads library contents can be used to refresh contents as well """ self.songs = self.database.load() self.artists = self.database.load_artists() self.albums = self.database.load_albums() self.song_count = len(self.songs) def import_songs(self, loc): """pass in name of folder containing music files""" found_songs = [] for root, dirs, files in os.walk(loc): for f in files: filename = os.path.join(root, f) try: song = Song(filename) except Exception as inst: print inst.args[0] print "Exception library.py <import_songs>" continue else: found_songs.append(song) self.database.insert_songs(found_songs) self.load_songs() def flush(): """empty database and reset data""" self.database.clear_table() self.load_songs()
def __init__(self, database): """ set the location of database """ self.database = Interface(database) self.load_songs()