From 1d362bcd5eeccdd3e8f86ecf98b5fcad0128431f Mon Sep 17 00:00:00 2001 From: Remy Date: Fri, 19 Aug 2011 15:32:30 -0700 Subject: [PATCH] Unicode changes --- headphones/librarysync.py | 15 +++++++-------- headphones/postprocessor.py | 9 +++++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/headphones/librarysync.py b/headphones/librarysync.py index 990c2d3c..81808890 100644 --- a/headphones/librarysync.py +++ b/headphones/librarysync.py @@ -8,6 +8,13 @@ from headphones import db, logger, helpers, importer def libraryScan(dir=None): + # Clean up bad filepaths + tracks = myDB.select('SELECT Location, TrackID from tracks WHERE Location IS NOT NULL') + + for track in tracks: + if not os.path.isfile(track['Location']): + myDB.action('UPDATE tracks SET Location=? WHERE TrackID=?', [None, track['TrackID']]) + if not dir: dir = headphones.MUSIC_DIR @@ -162,14 +169,6 @@ def libraryScan(dir=None): continue logger.info('Done checking empty filepaths') - - # Clean up bad filepaths - tracks = myDB.select('SELECT Location, TrackID from tracks WHERE Location IS NOT NULL') - - for track in tracks: - if not os.path.isfile(track['Location']): - myDB.action('UPDATE tracks SET Location=? WHERE TrackID=?', [None, track['TrackID']]) - logger.info('Done syncing library with directory: %s' % dir) # Clean up the new artist list diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index 7a779e6e..10db91bd 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -110,6 +110,11 @@ def verify(albumid, albumpath): release = myDB.action('SELECT * from albums WHERE AlbumID=?', [albumid]).fetchone() tracks = myDB.select('SELECT * from tracks WHERE AlbumID=?', [albumid]) + try: + albumpath = str(albumpath) + except UnicodeEncodeError: + albumpath = unicode(albumpath).encode('unicode_escape') + downloaded_track_list = [] for r,d,f in os.walk(albumpath): @@ -324,7 +329,7 @@ def moveFiles(albumpath, release, tracks): folder = newfolder break - logger.info('Moving files from %s to %s' % (albumpath, destination_path)) + logger.info('Moving files from %s to %s' % (albumpath, destination_path.encode('utf-8'))) try: os.makedirs(destination_path) @@ -416,7 +421,7 @@ def renameFiles(albumpath, downloaded_track_list, release): new_file = os.path.join(albumpath, new_file_name) - logger.debug('Renaming %s ---> %s' % (downloaded_track, new_file_name)) + logger.debug('Renaming %s ---> %s' % (downloaded_track, new_file_name.encode('utf-8'))) try: os.rename(downloaded_track, new_file) except Exception, e: