def _getSong(self, songname, artistid, filename, tracknum, albumid="", year="", metaartistid=-1, genreid=-1): sid = -1 songname = string.strip(songname) filename = string.strip(filename) cursor = self.import_cursor #SQL = "select songid from songs where filename = %s" #cursor.execute(SQL, filename) #for row in cursor.fetchall(): # log.debug("sqlresult", "Row: %s", row) # sid = row['songid'] #metadata = self.cursong.getMetaData() metadata = {} try: #Jef 07/30/2003: Not sure why but metadata=metadata.id3.getTag(filename) isnt working metadata = getTag(filename) log.debug("import", "Metadata %s", metadata) except: log.debug("import", "No metadata for %s", filename) if "bitrate" not in metadata or "songlength" not in metadata: pass #print "before set filename" #self.cursong.songint.filename = filename #print "before open" #self.cursong.songOpen() #print "before metadata" #metadata = self.cursong.getMetaData() #self.cursong.songClose() #print "after metadata" statinfo = os.stat(filename) songlength = 0 if metadata['songlength'] is not None and str(metadata['songlength']) != 'inf': songlength = metadata['songlength'] now = time.time() artistid = int(artistid) albumid = int(albumid) year = int(year) if filename not in self.i_songcache: SQL = "insert into songs (songname, artistid, albumid, year, tracknum, filename, filesize, songlength, bitrate, metaartistid, create_date, modified_date, timesplayed, weight, flags) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, 0, 0, 0)" cursor.execute(SQL, songname, artistid, albumid, year, tracknum, filename, statinfo.st_size, songlength, metadata['bitrate'], metaartistid, now, now) self.getalbumstatus = True sid = cursor.lastrowid if genreid > -1: SQL = "insert into genre_data(songid, genreid, create_date, modified_date) VALUES (%s, %s, %s, %s)" cursor.execute(SQL, sid, genreid, now, now) self.i_songcache[filename] = sid #TODO: Check to see if there are changes else: SQL = "update songs set modified_date = %s, songname = %s, artistid = %s, albumid = %s, year = %s, tracknum = %s, filename = %s, songlength = %s, bitrate = %s, metaartistid = %s, filesize = %s where songid = %s" cursor.execute(SQL, now, songname, artistid, albumid, year, tracknum, filename, metadata['songlength'], metadata['bitrate'], metaartistid, statinfo.st_size, sid) if genreid > -1: SQL = "update genre_data set genreid=%s, modified_date=%s WHERE songid=%s" cursor.execute(SQL, genreid, now, sid) self.getalbumstatus = False return sid
def importUpload(self, filename, songdata): log.debug("funcs", "Database.importUpload()") log.debug("import", "getting tag info for: %s" % self.checkBinary(filename)) return getTag(self.checkBinary(filename))
def getmetadata(self, filename): log.debug("funcs", "Database.getmetadata(%s)", filename) return getTag(filename)