From 808fcb48b83ec74f1018f67dca5056da1b83f2e0 Mon Sep 17 00:00:00 2001 From: Remy Date: Thu, 18 Aug 2011 14:46:00 -0700 Subject: [PATCH 1/8] Updated version.py --- headphones/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/headphones/version.py b/headphones/version.py index 0dda129e..b6c5af53 100644 --- a/headphones/version.py +++ b/headphones/version.py @@ -1 +1 @@ -HEADPHONES_VERSION = "master" \ No newline at end of file +HEADPHONES_VERSION = "develop" \ No newline at end of file From 1d362bcd5eeccdd3e8f86ecf98b5fcad0128431f Mon Sep 17 00:00:00 2001 From: Remy Date: Fri, 19 Aug 2011 15:32:30 -0700 Subject: [PATCH 2/8] 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: From ec8a5e1bc3e48340b4782922dc2b45d83186027e Mon Sep 17 00:00:00 2001 From: Remy Date: Fri, 19 Aug 2011 15:44:53 -0700 Subject: [PATCH 3/8] Fixed (hopefully) the isfile unicode error --- headphones/librarysync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/headphones/librarysync.py b/headphones/librarysync.py index 81808890..c3c672f5 100644 --- a/headphones/librarysync.py +++ b/headphones/librarysync.py @@ -12,7 +12,7 @@ def libraryScan(dir=None): tracks = myDB.select('SELECT Location, TrackID from tracks WHERE Location IS NOT NULL') for track in tracks: - if not os.path.isfile(track['Location']): + if not os.path.isfile(track['Location'].encode(headphones.SYS_ENCODING)): myDB.action('UPDATE tracks SET Location=? WHERE TrackID=?', [None, track['TrackID']]) if not dir: From 61af5f6bb262da23447904ace97a6c7ad0b7c214 Mon Sep 17 00:00:00 2001 From: Remy Date: Fri, 19 Aug 2011 19:43:02 -0700 Subject: [PATCH 4/8] Unicode fixes, lifted search result limit (eh, its now 100 instead of 20), use meta artist/album/track before mbid --- data/interfaces/default/searchresults.html | 6 +++--- headphones/importer.py | 16 ++++++++-------- headphones/librarysync.py | 22 +++++++++++----------- headphones/postprocessor.py | 20 +++++++++++++------- headphones/webserve.py | 4 ++-- 5 files changed, 37 insertions(+), 31 deletions(-) diff --git a/data/interfaces/default/searchresults.html b/data/interfaces/default/searchresults.html index 5109d10b..b02fedd6 100644 --- a/data/interfaces/default/searchresults.html +++ b/data/interfaces/default/searchresults.html @@ -57,11 +57,11 @@ "oLanguage": { "sLengthMenu":"Show _MENU_ results per page", "sEmptyTable": "No results", - "sInfo":"Showing _TOTAL_ results", + "sInfo":"Showing _START_ to _END_ of _TOTAL_ results", "sInfoEmpty":"Showing 0 to 0 of 0 results", "sInfoFiltered":"(filtered from _MAX_ total results)"}, - "bPaginate": false, - "bFilter": false, + "iDisplayLength": 25, + "sPaginationType": "full_numbers", "aaSorting": [] }); diff --git a/headphones/importer.py b/headphones/importer.py index b186d0c7..740114dd 100644 --- a/headphones/importer.py +++ b/headphones/importer.py @@ -161,12 +161,12 @@ def addArtisttoDB(artistid, extrasonly=False): "CleanName": cleanname } - match = myDB.action('SELECT Location, BitRate from have WHERE TrackID=?', [track['id']]).fetchone() + match = myDB.action('SELECT Location, BitRate from have WHERE CleanName=?', [cleanname]).fetchone() - if not match: - match = myDB.action('SELECT Location, BitRate from have WHERE CleanName=?', [cleanname]).fetchone() if not match: match = myDB.action('SELECT Location, BitRate from have WHERE ArtistName LIKE ? AND AlbumTitle LIKE ? AND TrackTitle LIKE ?', [artist['artist_name'], rg['title'], track['title']]).fetchone() + if not match: + match = myDB.action('SELECT Location, BitRate from have WHERE TrackID=?', [track['id']]).fetchone() if match: newValueDict['Location'] = match['Location'] newValueDict['BitRate'] = match['BitRate'] @@ -286,14 +286,14 @@ def addReleaseById(rid): "TrackNumber": track['number'], "CleanName": cleanname } - - match = myDB.action('SELECT Location, BitRate from have WHERE TrackID=?', [track['id']]).fetchone() - - if not match: - match = myDB.action('SELECT Location, BitRate from have WHERE CleanName=?', [cleanname]).fetchone() + match = myDB.action('SELECT Location, BitRate from have WHERE CleanName=?', [cleanname]).fetchone() + if not match: match = myDB.action('SELECT Location, BitRate from have WHERE ArtistName LIKE ? AND AlbumTitle LIKE ? AND TrackTitle LIKE ?', [release_dict['artist_name'], release_dict['rg_title'], track['title']]).fetchone() + + if not match: + match = myDB.action('SELECT Location, BitRate from have WHERE TrackID=?', [track['id']]).fetchone() if match: newValueDict['Location'] = match['Location'] diff --git a/headphones/librarysync.py b/headphones/librarysync.py index c3c672f5..b63e340f 100644 --- a/headphones/librarysync.py +++ b/headphones/librarysync.py @@ -51,17 +51,6 @@ def libraryScan(dir=None): if f.bitrate: bitrates.append(f.bitrate) - # Try to match on metadata first, starting with the track id - if f.mb_trackid: - - # Wondering if theres a better way to do this -> do one thing if the row exists, - # do something else if it doesn't - track = myDB.action('SELECT TrackID from tracks WHERE TrackID=?', [f.mb_trackid]).fetchone() - - if track: - myDB.action('UPDATE tracks SET Location=?, BitRate=? WHERE TrackID=?', [file, f.bitrate, track['TrackID']]) - continue - # Try to find a match based on artist/album/tracktitle if f.albumartist: f_artist = f.albumartist @@ -81,6 +70,17 @@ def libraryScan(dir=None): myDB.action('UPDATE tracks SET Location=?, BitRate=? WHERE TrackID=?', [file, f.bitrate, track['TrackID']]) continue + # Try to match on mbid if available and we couldn't find a match based on metadata + if f.mb_trackid: + + # Wondering if theres a better way to do this -> do one thing if the row exists, + # do something else if it doesn't + track = myDB.action('SELECT TrackID from tracks WHERE TrackID=?', [f.mb_trackid]).fetchone() + + if track: + myDB.action('UPDATE tracks SET Location=?, BitRate=? WHERE TrackID=?', [file, f.bitrate, track['TrackID']]) + continue + # if we can't find a match in the database on a track level, it might be a new artist or it might be on a non-mb release new_artists.append(f_artist) diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index 10db91bd..f1f869c5 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -329,7 +329,9 @@ def moveFiles(albumpath, release, tracks): folder = newfolder break - logger.info('Moving files from %s to %s' % (albumpath, destination_path.encode('utf-8'))) + logger.info('Moving files from %s to %s' % (unicode(albumpath, headphones.SYS_ENCODING, errors="replace"), destination_path)) + + destination_path = destination_path.encode(headphones.SYS_ENCODING) try: os.makedirs(destination_path) @@ -337,7 +339,7 @@ def moveFiles(albumpath, release, tracks): except Exception, e: logger.error('Could not create folder for %s. Not moving: %s' % (release['AlbumTitle'], e)) return albumpath - + for r,d,f in os.walk(albumpath): for files in f: shutil.move(os.path.join(r, files), destination_path) @@ -362,13 +364,17 @@ def correctMetadata(albumid, release, downloaded_track_list): logger.info('Writing metadata') items = [] for downloaded_track in downloaded_track_list: + try: items.append(beets.library.Item.from_path(downloaded_track)) except Exception, e: logger.error("Beets couldn't create an Item from: " + downloaded_track + " - not a media file?" + str(e)) - cur_artist, cur_album, out_tuples, rec = autotag.tag_album(items, search_artist=release['ArtistName'], search_album=release['AlbumTitle']) - + try: + cur_artist, cur_album, out_tuples, rec = autotag.tag_album(items, search_artist=helpers.latinToAscii(release['ArtistName']), search_album=helpers.latinToAscii(release['AlbumTitle'])) + except Exception, e: + logger.error('Error getting recommendation: %s. Not writing metadata' % e) + return if rec == 'RECOMMEND_NONE': logger.warn('No accurate album match found for %s, %s - not writing metadata' % (release['ArtistName'], release['AlbumTitle'])) return @@ -420,8 +426,8 @@ def renameFiles(albumpath, downloaded_track_list, release): new_file_name = new_file_name.replace('?','_').replace(':', '_') new_file = os.path.join(albumpath, new_file_name) - - logger.debug('Renaming %s ---> %s' % (downloaded_track, new_file_name.encode('utf-8'))) + + logger.debug('Renaming %s ---> %s' % (unicode(downloaded_track, headphones.SYS_ENCODING, errors="replace"), new_file_name)) try: os.rename(downloaded_track, new_file) except Exception, e: @@ -456,7 +462,7 @@ def updateHave(albumpath): else: continue - myDB.action('UPDATE tracks SET Location=?, BitRate=? WHERE ArtistName LIKE ? AND AlbumTitle LIKE ? AND TrackTitle LIKE ?', [song, f.bitrate, artist, f.album, f.title]) + myDB.action('UPDATE tracks SET Location=?, BitRate=? WHERE ArtistName LIKE ? AND AlbumTitle LIKE ? AND TrackTitle LIKE ?', [unicode(song, headphones.SYS_ENCODING, errors="replace"), f.bitrate, artist, f.album, f.title]) def renameUnprocessedFolder(albumpath): diff --git a/headphones/webserve.py b/headphones/webserve.py index 17c4f5aa..aa0bbb75 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -62,9 +62,9 @@ class WebInterface(object): if len(name) == 0: raise cherrypy.HTTPRedirect("home") if type == 'artist': - searchresults = mb.findArtist(name, limit=20) + searchresults = mb.findArtist(name, limit=100) else: - searchresults = mb.findRelease(name, limit=20) + searchresults = mb.findRelease(name, limit=100) return serve_template(templatename="searchresults.html", title='Search Results for: "' + name + '"', searchresults=searchresults, type=type) search.exposed = True From 91a2716ca4685e581c8a38de0524d422d5d2a6bf Mon Sep 17 00:00:00 2001 From: Remy Date: Fri, 19 Aug 2011 20:06:44 -0700 Subject: [PATCH 5/8] changed unicode encoding for destination path --- headphones/postprocessor.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index f1f869c5..7f78f84c 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -316,13 +316,13 @@ def moveFiles(albumpath, release, tracks): if folder.endswith('.'): folder = folder.replace(folder[len(folder)-1], '_') - destination_path = os.path.normpath(os.path.join(headphones.DESTINATION_DIR, folder)) + destination_path = os.path.normpath(os.path.join(headphones.DESTINATION_DIR, folder)).encode(headphones.SYS_ENCODING) if os.path.exists(destination_path): i = 1 while True: newfolder = folder + '[%i]' % i - destination_path = os.path.normpath(os.path.join(headphones.DESTINATION_DIR, newfolder)) + destination_path = os.path.normpath(os.path.join(headphones.DESTINATION_DIR, newfolder)).encode(headphones.SYS_ENCODING) if os.path.exists(destination_path): i += 1 else: @@ -331,8 +331,6 @@ def moveFiles(albumpath, release, tracks): logger.info('Moving files from %s to %s' % (unicode(albumpath, headphones.SYS_ENCODING, errors="replace"), destination_path)) - destination_path = destination_path.encode(headphones.SYS_ENCODING) - try: os.makedirs(destination_path) From 86b13d9687da9a4d170603769e8de2f73c911c4f Mon Sep 17 00:00:00 2001 From: Remy Date: Fri, 19 Aug 2011 20:41:39 -0700 Subject: [PATCH 6/8] More unicode fixes --- headphones/postprocessor.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index 7f78f84c..ef2d11c9 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -110,10 +110,7 @@ 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') + albumpath = albumpath.encode(headphones.SYS_ENCODING) downloaded_track_list = [] @@ -328,8 +325,8 @@ def moveFiles(albumpath, release, tracks): else: folder = newfolder break - - logger.info('Moving files from %s to %s' % (unicode(albumpath, headphones.SYS_ENCODING, errors="replace"), destination_path)) + + logger.info('Moving files from %s to %s' % (unicode(albumpath, headphones.SYS_ENCODING, errors="replace"), unicode(destination_path, headphones.SYS_ENCODING, errors="replace"))) try: os.makedirs(destination_path) @@ -421,11 +418,11 @@ def renameFiles(albumpath, downloaded_track_list, release): new_file_name = helpers.replace_all(headphones.FILE_FORMAT, values).replace('/','_') + ext - new_file_name = new_file_name.replace('?','_').replace(':', '_') + new_file_name = new_file_name.replace('?','_').replace(':', '_').encode(headphones.SYS_ENCODING) new_file = os.path.join(albumpath, new_file_name) - logger.debug('Renaming %s ---> %s' % (unicode(downloaded_track, headphones.SYS_ENCODING, errors="replace"), new_file_name)) + logger.debug('Renaming %s ---> %s' % (downloaded_track, new_file_name)) try: os.rename(downloaded_track, new_file) except Exception, e: From af0995930bba7e2f835eb7812d241db162a1a3c8 Mon Sep 17 00:00:00 2001 From: Remy Date: Fri, 19 Aug 2011 20:54:19 -0700 Subject: [PATCH 7/8] Unicode chmod fix --- headphones/postprocessor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index ef2d11c9..353e60b4 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -344,7 +344,7 @@ def moveFiles(albumpath, release, tracks): temp_f = headphones.DESTINATION_DIR for f in folder_list: - temp_f = os.path.join(temp_f, f) + temp_f = os.path.join(temp_f, f).encode(headphones.SYS_ENCODING) os.chmod(temp_f, int(headphones.FOLDER_PERMISSIONS, 8)) try: From 60a4e63ae09e0a2fefb6feace2e8574a43c87a79 Mon Sep 17 00:00:00 2001 From: Remy Date: Fri, 19 Aug 2011 21:00:02 -0700 Subject: [PATCH 8/8] Changed permissions back to 644 --- Headphones.py | 0 headphones/__init__.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 Headphones.py mode change 100755 => 100644 headphones/__init__.py diff --git a/Headphones.py b/Headphones.py old mode 100755 new mode 100644 diff --git a/headphones/__init__.py b/headphones/__init__.py old mode 100755 new mode 100644