def _cash_out(self, file, track, album, artist): file[u'title'] = track.title file[u'artist'] = artist.name if not file.get('album'): file['album'] = album.title file[u'duration'] = track.duration #in milliseconds year = get_year(album) if year: file[u'date'] = year file[u'year'] = year if len(track.releases) > 0: file[u'tracknumber'] = track.releases[0].getTracksOffset()+1 else: file[u'tracknumber'] = album.tracks.index(track) + 1 file[u'totaltracks'] = len(album.tracks) # The musicbrainz ids are urls. I just keep the actual id part file[u'mbtrackid'] = track.id.rsplit('/').pop() file[u'mbalbumid'] = album.id.rsplit('/').pop() file[u'mbartistid'] = artist.id.rsplit('/').pop() file[u'asin'] = album.asin #probably a good thing to have # Album artist stuff try: file[u'mbalbumartistid'] = album.artist.id.rsplit('/').pop() file[u'albumartist'] = album.artist.name except: file[u'mbalbumartistid'] = file['mbartistid'] file[u'albumartist'] = file['artist'] log.debug('%s successfully tagged by MusicBrainz', track.title) return file
def compare_to_release(file, release): """ Compare cluster metadata to a MusicBrainz release. Weigths: * title = 12 * artist name = 6 * number of tracks = 5 * year of release = 4 * type is album = 3 * album is official = 3 * num of release events= 2 """ total = 0.0 a = file['album'] b = release.title if a and b: total += similarity2(a, b) * 17.0 / 33.0 a = file['artist'] b = release.artist.name if a and b: total += similarity2(a, b) * 6.0 / 33.0 a = file.get('date') b = get_year(release) if a and b: total += 1.0-abs(cmp(a, b)) * 4.0 / 33.0 a = totaltracks(file) b = len(release.tracks) if a > b: score = 0.0 elif a < b: score = 0.3 else: score = 1.0 total += score * 5.0 / 33.0 if release.TYPE_OFFICIAL in release.types: total += 3.0/33.0 if release.TYPE_ALBUM in release.types: total += 3.0/33.0 return total
def _find_track(self, file): mbquery = Query() filter = TrackFilter(puid = file['puid']) result = self._query_brainz(file,mbquery.getTracks, filter) if not result: return False if len(result)== 0: #Uh oh, nothing found. return file trackl = [] trackd = {} include = ReleaseIncludes(releaseEvents = True, tracks = True) for track in result: trackd[track.track.id] = track log.debug("Looking up %s with score %s", track.track.title, track.score ) release = self._query_brainz( file, mbquery.getReleaseById, track.track.releases[0].id, include = include ) trackl.append({ 'id': track.track.id, 'title': track.track.title, 'album': track.track.releases[0].title, 'artist': track.track.artist.name, 'duration': track.track.duration, 'releaseid': track.track.releases[0].id, 'tracknumber': track.track.releases[0].getTracksOffset()+1, 'totaltracks': len(release.tracks), 'date': get_year(release), 'types': release.types }) result = match_file_to_track(file, trackl) if result: return trackd[result['id']] else: return False
def match_file_to_release(file, release): """Match files on tracks on this album, based on metadata similarity.""" trackl = [] trackd = {} for track in release.tracks: trackd[track.id] = track trackl.append({ 'id': track.id, 'releaseid': release.id, 'title': track.title, 'album': release.title, 'artist': release.artist.name, 'duration': track.duration, 'tracknumber': release.tracks.index(track) + 1, 'totaltracks': len(release.tracks), 'date': get_year(release), 'types': release.types }) result = match_file_to_track(file, trackl) if result: result = trackd[result['id']] return result