mirror of
https://github.com/rembo10/headphones.git
synced 2026-05-15 16:19:28 +01:00
Removed the track matching from librarysync. It was probably a longshot anyways, and it was taking a lot of time and causing too many errors to make it worth it
This commit is contained in:
@@ -107,105 +107,7 @@ def libraryScan(dir=None):
|
||||
# The have table will become the new database for unmatched tracks (i.e. tracks with no associated links in the database
|
||||
myDB.action('INSERT INTO have (ArtistName, AlbumTitle, TrackNumber, TrackTitle, TrackLength, BitRate, Genre, Date, TrackID, Location, CleanName, Format) VALUES( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [f_artist, f.album, f.track, f.title, f.length, f.bitrate, f.genre, f.date, f.mb_trackid, file, helpers.cleanName(f_artist+' '+f.album+' '+f.title), f.format])
|
||||
|
||||
logger.info('Completed scanning of directory: %s' % dir)
|
||||
logger.info('Checking filepaths to see if we can find any matches')
|
||||
|
||||
# Now check empty file paths to see if we can find a match based on their folder format
|
||||
tracks = myDB.select('SELECT * from tracks WHERE Location IS NULL')
|
||||
for track in tracks:
|
||||
|
||||
release = myDB.action('SELECT * from albums WHERE AlbumID=?', [track['AlbumID']]).fetchone()
|
||||
|
||||
try:
|
||||
year = release['ReleaseDate'][:4]
|
||||
except TypeError:
|
||||
year = ''
|
||||
|
||||
artist = release['ArtistName'].replace('/', '_')
|
||||
album = release['AlbumTitle'].replace('/', '_')
|
||||
releasetype = release['Type'].replace('/', '_')
|
||||
|
||||
if release['ArtistName'].startswith('The '):
|
||||
sortname = release['ArtistName'][4:]
|
||||
else:
|
||||
sortname = release['ArtistName']
|
||||
|
||||
if sortname.isdigit():
|
||||
firstchar = '0-9'
|
||||
else:
|
||||
firstchar = sortname[0]
|
||||
|
||||
|
||||
albumvalues = { '$Artist': artist,
|
||||
'$Album': album,
|
||||
'$Year': year,
|
||||
'$Type': releasetype,
|
||||
'$First': firstchar,
|
||||
'$artist': artist.lower(),
|
||||
'$album': album.lower(),
|
||||
'$year': year,
|
||||
'$type': releasetype.lower(),
|
||||
'$first': firstchar.lower()
|
||||
}
|
||||
|
||||
|
||||
folder = helpers.replace_all(headphones.FOLDER_FORMAT, albumvalues)
|
||||
folder = folder.replace('./', '_/').replace(':','_').replace('?','_')
|
||||
|
||||
if folder.endswith('.'):
|
||||
folder = folder.replace(folder[len(folder)-1], '_')
|
||||
|
||||
if not track['TrackNumber']:
|
||||
tracknumber = ''
|
||||
else:
|
||||
tracknumber = '%02d' % track['TrackNumber']
|
||||
|
||||
title = track['TrackTitle']
|
||||
|
||||
trackvalues = { '$Track': tracknumber,
|
||||
'$Title': title,
|
||||
'$Artist': release['ArtistName'],
|
||||
'$Album': release['AlbumTitle'],
|
||||
'$Year': year,
|
||||
'$track': tracknumber,
|
||||
'$title': title.lower(),
|
||||
'$artist': release['ArtistName'].lower(),
|
||||
'$album': release['AlbumTitle'].lower(),
|
||||
'$year': year
|
||||
}
|
||||
|
||||
new_file_name = helpers.replace_all(headphones.FILE_FORMAT, trackvalues).replace('/','_') + '.*'
|
||||
|
||||
new_file_name = new_file_name.replace('?','_').replace(':', '_')
|
||||
|
||||
full_path_to_file = os.path.normpath(os.path.join(headphones.MUSIC_DIR, folder, new_file_name)).encode(headphones.SYS_ENCODING, 'replace')
|
||||
|
||||
match = glob.glob(full_path_to_file)
|
||||
|
||||
if match:
|
||||
|
||||
logger.info('Found a match: %s. Writing MBID to metadata' % match[0])
|
||||
|
||||
unipath = unicode(match[0], headphones.SYS_ENCODING, errors='replace')
|
||||
|
||||
myDB.action('UPDATE tracks SET Location=? WHERE TrackID=?', [unipath, track['TrackID']])
|
||||
myDB.action('DELETE from have WHERE Location=?', [unipath])
|
||||
|
||||
# Try to insert the appropriate track id so we don't have to keep doing this
|
||||
try:
|
||||
f = MediaFile(match[0])
|
||||
f.mb_trackid = track['TrackID']
|
||||
f.save()
|
||||
myDB.action('UPDATE tracks SET BitRate=?, Format=? WHERE TrackID=?', [f.bitrate, f.format, track['TrackID']])
|
||||
|
||||
logger.debug('Wrote mbid to track: %s' % match[0])
|
||||
|
||||
except:
|
||||
logger.error('Error embedding track id into: %s' % match[0])
|
||||
continue
|
||||
|
||||
logger.info('Done checking empty filepaths')
|
||||
logger.info('Done syncing library with directory: %s' % dir)
|
||||
logger.info('Completed scanning directory: %s' % dir)
|
||||
|
||||
# Clean up the new artist list
|
||||
unique_artists = {}.fromkeys(new_artists).keys()
|
||||
|
||||
Reference in New Issue
Block a user