def id_in_tag(tag): if 'acoustid_fingerprint' in tag: fp = to_string(tag['acoustid_fingerprint']) else: return if '__length' in tag: duration = audioinfo.lnglength(tag['__length']) else: return return (duration, fp)
def calculate_discid(album): #from quodlibet's cddb plugin by Michael Urman album = sorted(album, key=sort_func('__filename', u'')) album = sorted(album, key=sort_func('track', u'1')) lengths = [audioinfo.lnglength(to_string(song['__length'])) for song in album] total_time = 0 offsets = [] for length in lengths: offsets.append(total_time) total_time += length checksum = sum(map(sumdigits, offsets)) discid = ((checksum % 0xff) << 24) | (total_time << 8) | len(album) return [discid, len(album)] + [75 * o for o in offsets] + [total_time]
def calculate_discid(album): #from quodlibet's cddb plugin by Michael Urman album = sorted(album, key=sort_func('__filename', u'')) album = sorted(album, key=sort_func('track', u'1')) lengths = [ audioinfo.lnglength(to_string(song['__length'])) for song in album ] total_time = 0 offsets = [] for length in lengths: offsets.append(total_time) total_time += length checksum = sum(map(sumdigits, offsets)) discid = ((checksum % 0xff) << 24) | (total_time << 8) | len(album) return [discid, len(album)] + [75 * o for o in offsets] + [total_time]
u'title': u'title', u'genre': u'genre', u'artist': u'artist', u'album': u'album', u'track-number': u'track', u'duration': getLength, u'file-size': u'__size', u'location': getFilename, u'first-seen': getCreated, u'mtime': getModified, u'last-seen': '__last_seen', u'bitrate': getBitRate, u'disc-number': u'discnumber' } setLength = lambda length: {'duration': unicode(audioinfo.lnglength(length))} setCreated = lambda created: { 'first-seen': unicode(audioinfo.lngtime(created)) } setBitrate = lambda bitrate: { 'bitrate': unicode(audioinfo.lngfrequency(bitrate) / 1000) } setModified = lambda modified: { 'last-seen': unicode(audioinfo.lngtime(modified)) } setFilename = lambda filename: { u'location': u'file://' + unicode(QUrl.toPercentEncoding(filename, '/()"\'')).encode( 'utf8') }
CONVERSION = {u'title': u'title', u'genre': u'genre', u'artist': u'artist', u'album': u'album', u'track-number': u'track', u'duration': getLength, u'file-size': u'__size', u'location': getFilename, u'first-seen': getCreated, u'mtime': getModified, u'last-seen': '__last_seen', u'bitrate': getBitRate, u'disc-number': u'discnumber'} setLength = lambda length: {'duration': unicode(audioinfo.lnglength(length))} setCreated = lambda created: {'first-seen': unicode(audioinfo.lngtime(created))} setBitrate = lambda bitrate: {'bitrate': unicode(audioinfo.lngfrequency(bitrate) / 1000)} setModified = lambda modified: {'last-seen': unicode(audioinfo.lngtime(modified))} setFilename = lambda filename: {u'location': u'file://' + unicode(QUrl.toPercentEncoding(filename, '/()"\'')).encode('utf8')} RECONVERSION = { 'title': 'title', 'artist': 'artist', 'album': 'album', 'track': 'track-number', 'discnumber': 'disc-number', 'genre': 'genre', '__length': setLength, '__created': setCreated, '__bitrate': setBitrate,