Unicode fixes, lifted search result limit (eh, its now 100 instead of 20), use meta artist/album/track before mbid

This commit is contained in:
Remy
2011-08-19 19:43:02 -07:00
parent ec8a5e1bc3
commit 61af5f6bb2
5 changed files with 37 additions and 31 deletions

View File

@@ -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": []
});

View File

@@ -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']

View File

@@ -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)

View File

@@ -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):

View File

@@ -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