diff --git a/headphones/librarysync.py b/headphones/librarysync.py index eca74417..37be6708 100644 --- a/headphones/librarysync.py +++ b/headphones/librarysync.py @@ -168,4 +168,4 @@ def libraryScan(): headphones.NEW_ARTISTS = artist_list if headphones.DETECT_BITRATE: - headphones.PREFERRED_BITRATE = float(sum(bitrates))/len(bitrates)/1000 \ No newline at end of file + headphones.PREFERRED_BITRATE = round(sum(bitrates))/len(bitrates)/1000 \ No newline at end of file diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index 70ae4ac3..2efb6942 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -240,6 +240,7 @@ def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list) myDB.action('UPDATE artists SET HaveTracks=? WHERE ArtistID=?', [new_track_count, release['ArtistID']]) myDB.action('UPDATE albums SET status = "Downloaded" WHERE AlbumID=?', [albumid]) myDB.action('UPDATE snatched SET status = "Processed" WHERE AlbumID=?', [albumid]) + updateHave(albumpath) logger.info('Post-processing for %s - %s complete' % (release['ArtistName'], release['AlbumTitle'])) @@ -420,6 +421,36 @@ def renameFiles(albumpath, downloaded_track_list, release): except Exception, e: logger.error('Error renaming file: %s. Error: %s' % (downloaded_track, e)) continue + +def updateHave(albumpath): + + results = [] + + for r,d,f in os.walk(albumpath): + for files in f: + if any(files.endswith('.' + x) for x in headphones.MEDIA_FORMATS): + results.append(os.path.join(r, files)) + + if results: + + myDB = db.DBConnection() + + for song in results: + try: + f = MediaFile(song) + #logger.debug('Reading: %s' % song.decode('UTF-8')) + except: + logger.warn('Could not read file: %s' % song) + continue + else: + if f.albumartist: + artist = f.albumartist + elif f.artist: + artist = f.artist + 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]) def renameUnprocessedFolder(albumpath):