From 576d3b5aee670d55b5e6b55755bb420d77e2e909 Mon Sep 17 00:00:00 2001 From: sbuser Date: Tue, 2 Aug 2011 07:47:01 -0500 Subject: [PATCH] Postprocessing fixes: for files on network shares sanity check for manual post-process to prevent errors from names headphones doesn't understand --- headphones/helpers.py | 15 +++++++++------ headphones/postprocessor.py | 36 +++++++++++++++++++----------------- lib/beets/util/__init__.py | 4 +++- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/headphones/helpers.py b/headphones/helpers.py index 6486ac40..54285a7d 100644 --- a/headphones/helpers.py +++ b/headphones/helpers.py @@ -104,9 +104,12 @@ def extract_data(s): pattern = re.compile(r'(?P.*?)\s\-\s(?P.*?)\s\[(?P.*?)\]', re.VERBOSE) match = pattern.match(s) - - name = match.group("name") - album = match.group("album") - year = match.group("year") - - return (name, album, year) \ No newline at end of file + + if match: + name = match.group("name") + album = match.group("album") + year = match.group("year") + + return (name, album, year) + else: + return (None, None, None) \ No newline at end of file diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index a4651703..9d46ed3e 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -237,7 +237,7 @@ def correctMetadata(albumid, release, downloaded_track_list): items = [] for downloaded_track in downloaded_track_list: items.append(beets.library.Item.from_path(downloaded_track)) - + cur_artist, cur_album, out_tuples, rec = autotag.tag_album(items, search_artist=release['ArtistName'], search_album=release['AlbumTitle']) if rec == 'RECOMMEND_NONE': @@ -367,21 +367,23 @@ def forcePostProcess(): albumpath = unicode(os.path.join(download_dir, folder)) name, album, year = helpers.extract_data(folder) - - myDB = db.DBConnection() - release = myDB.action('SELECT AlbumID, ArtistName, AlbumTitle from albums WHERE ArtistName=? and AlbumTitle=?', [name, album]).fetchone() - if release: - logger.info('Found a match in the database: %s - %s. Verifying to make sure it is the correct album' % (release['ArtistName'], release['AlbumTitle'])) - verify(release['AlbumID'], albumpath) - else: - logger.info('Querying MusicBrainz for the release group id for: %s - %s' % (name, album)) - from headphones import mb - try: - rgid = mb.findAlbumID(name, album) - except: - logger.error('Can not get release information for this album') - if rgid: - rgid = unicode(rgid) - verify(rgid, albumpath) + if name and album and year: + + myDB = db.DBConnection() + release = myDB.action('SELECT AlbumID, ArtistName, AlbumTitle from albums WHERE ArtistName=? and AlbumTitle=?', [name, album]).fetchone() + if release: + logger.info('Found a match in the database: %s - %s. Verifying to make sure it is the correct album' % (release['ArtistName'], release['AlbumTitle'])) + verify(release['AlbumID'], albumpath) + else: + logger.info('Querying MusicBrainz for the release group id for: %s - %s' % (name, album)) + from headphones import mb + try: + rgid = mb.findAlbumID(name, album) + except: + logger.error('Can not get release information for this album') + continue + if rgid: + rgid = unicode(rgid) + verify(rgid, albumpath) \ No newline at end of file diff --git a/lib/beets/util/__init__.py b/lib/beets/util/__init__.py index 45f94522..0916321e 100644 --- a/lib/beets/util/__init__.py +++ b/lib/beets/util/__init__.py @@ -162,7 +162,9 @@ def syspath(path, pathmod=None): path = path.decode('utf8', 'replace') # Add the magic prefix if it isn't already there - if not path.startswith(u'\\\\?\\'): + # Not sure what the magic prefix he was adding actually does but if it's a network path + # it breaks when we add the prefix - ignore the addition if the \\ is already there + if not path.startswith(u'\\\\?\\') and not path.startswith(u'\\'): path = u'\\\\?\\' + path return path