Permalink
Browse files

Actual database code and debug messages for when a DB hit/miss occurs

  • Loading branch information...
1 parent 0a1e89f commit bc7b924918dcda242dc003e1466f787b2f0b25a5 @jbillo committed Sep 30, 2012
Showing with 12 additions and 3 deletions.
  1. +12 −3 musik/library/importer.py
View
@@ -123,8 +123,7 @@ def importFile(self, uri):
# Try to read the metadata appropriately.
metadata = self.readMp3MetaData(uri)
- print metadata
-
+
def readMp3MetaData(self, uri):
# TODO: check that the uri doesn't already exist
@@ -155,8 +154,9 @@ def readMp3MetaData(self, uri):
track.conductor = self.findArtist(metadata['conductor'])
track.lyricist = self.findArtist(metadata['lyricist'])
track.performer = self.findArtist(metadata['performer'])
+ track.title = metadata['title']
- track.album = self.findAlbum(metadata['album'], metadata['albumsort'], metadata['musicbrainz_albumid'], metadata)
+ track.album = self.findAlbum(metadata['album'], metadata['albumsort'], metadata['musicbrainz_albumid'])
if track.album != None:
disc = self.findDisc(track.album, metadata['discnumber'], metadata['discsubtitle'], metadata['musicbrainz_discid'])
@@ -193,6 +193,7 @@ def findArtist(self, name=None, name_sort=None, musicbrainz_id=None):
# artist in our db, try to find an existing artist by name
artist = self.sa_session.query(Artist).filter(Artist.name == name).first()
if artist != None:
+ self.log.debug(u'Found existing artist %s in database' % name)
# found an existing artist in our db - compare its metadata
# to the new info. Always prefer existing metadata over new.
if name_sort != None:
@@ -202,11 +203,14 @@ def findArtist(self, name=None, name_sort=None, musicbrainz_id=None):
self.log.warning(u'Artist sort name conflict for artist %s: %s != %s', artist.name, artist.name_sort, name_sort)
else:
# an existing artist could not be found in our db. Make a new one
+ self.log.debug(u'Artist not found in database; creating %s' % name)
artist = Artist(name)
if name_sort != None:
artist.name_sort = name_sort
if musicbrainz_id != None:
artist.musicbrainz_artistid = musicbrainz_id
+ # add the artist object to the DB
+ self.sa_session.add(artist)
# return the artist that we found and/or created
return artist
@@ -250,20 +254,23 @@ def findAlbum(self, title=None, title_sort=None, musicbrainz_id=None, artist=Non
if album != None:
# found an existing album in our db - compare its metadata
# to the new info. Always prefer existing metadata over new.
+ self.log.debug(u'Found existing album %s in database' % title)
if title_sort != None:
if album.title_sort == None:
album.title_sort = title_sort
elif album.title_sort != title_sort:
self.log.warning(u'Album sort title conflict for album %s: %s != %s', album.title, album.title_sort, title_sort)
else:
# an existing album could not be found in our db. Make a new one
+ self.log.debug(u'Album not found in database; creating %s' % title)
album = Album(title)
if title_sort != None:
album.title_sort = title_sort
if musicbrainz_id != None:
album.musicbrainz_albumid = musicbrainz_id
if artist != None:
album.artist = artist
+ self.sa_session.add(album)
# we either found or created the album. now verify its metadata
if album != None and metadata != None:
@@ -370,13 +377,15 @@ def findDisc(self, album=None, discnumber=None, discsubtitle=None, musicbrainz_i
self.log.warning(u'Disc musicbrainz_discid conflict for disc %s: %s != %s', disc, disc.musicbrainz_discid, musicbrainz_id)
else:
# could not find the disc in question. Create a new one instead
+ self.log.debug(u'Could not find disc in database; creating %s' % discnumber)
disc = Disc(discnumber)
if album != None:
disc.album = album
if discsubtitle != None:
disc.discsubtitle = discsubtitle
if musicbrainz_id != None:
disc.musicbrainz_discid = musicbrainz_id
+ self.sa_session.add(disc)
return disc

0 comments on commit bc7b924

Please sign in to comment.