<commit_before>

PreloadNextN = 5

import sys

def needUpdate(song):
	if getattr(song, "bmpThumbnail", None) is None: return True
	if getattr(song, "fingerprint_AcoustID", None) is None: return True
	if getattr(song, "gain", None) is None: return True
	return False

def update(song):
	def doCalc(queue):
		try:
			import ffmpeg

			if getattr(song, "gain", None) is None:
				song.close()
				song.openFile() # this is another process, so safe
				duration, gain = ffmpeg.calcReplayGain(song)
				queue.put(("duration", duration))
				queue.put(("gain", gain))
				song.gain = gain # useful for bmpThumbnail
				
			if getattr(song, "bmpThumbnail", None) is None:
				song.close()
				song.openFile() # this is another process, so safe
				# We have song.gain which mostly lowers the volume. So increase here for nicer display.
				duration, bmpData = ffmpeg.calcBitmapThumbnail(song, 600, 81, volume = 1.5)
				queue.put(("duration", duration))
				queue.put(("bmpThumbnail", bmpData))

			if getattr(song, "fingerprint_AcoustID", None) is None:
				song.close()
				song.openFile()
				song.gain = 0 # just use original
				duration, fingerprint = ffmpeg.calcAcoustIdFingerprint(song)
				from base64 import b64decode
				fingerprint = b64decode(fingerprint)
				queue.put(("duration", duration))
				queue.put(("fingerprint_AcoustID", fingerprint))

		except (KeyboardInterrupt,SystemExit):
			pass
		except:
			sys.excepthook(*sys.exc_info())
		
		queue.put((None,None))
		
	from multiprocessing import Process, Queue
	queue = Queue()
	Process(target=doCalc, args=(queue,)).start()
	
	while True:
		attr, value = queue.get()
		if attr is None: break
		setattr(song, attr, value)

def checkUpdate():
	from queue import queue
	from State import state
	
	songs = [state.curSong]
	songs += queue.peekNextN(PreloadNextN)
	
	import threading
	curThread = threading.currentThread()
	
	for song in songs:<commit_msg>save raw acoustid fingerprint<commit_after>

PreloadNextN = 5

import sys

def needUpdate(song):
	if getattr(song, "bmpThumbnail", None) is None: return True
	if getattr(song, "fingerprint_AcoustID", None) is None: return True
	if getattr(song, "gain", None) is None: return True
	return False

def update(song):
	def doCalc(queue):
		try:
			import ffmpeg

			if getattr(song, "gain", None) is None:
				song.close()
				song.openFile() # this is another process, so safe
				duration, gain = ffmpeg.calcReplayGain(song)
				queue.put(("duration", duration))
				queue.put(("gain", gain))
				song.gain = gain # useful for bmpThumbnail
				
			if getattr(song, "bmpThumbnail", None) is None:
				song.close()
				song.openFile() # this is another process, so safe
				# We have song.gain which mostly lowers the volume. So increase here for nicer display.
				duration, bmpData = ffmpeg.calcBitmapThumbnail(song, 600, 81, volume = 1.5)
				queue.put(("duration", duration))
				queue.put(("bmpThumbnail", bmpData))

			if getattr(song, "fingerprint_AcoustID", None) is None:
				song.close()
				song.openFile()
				song.gain = 0 # just use original
				duration, fingerprint = ffmpeg.calcAcoustIdFingerprint(song)
				# fingerprint is URL-safe base64 with missing padding
				fingerprint += "==="
				import base64
				fingerprint = base64.urlsafe_b64decode(fingerprint)
				queue.put(("duration", duration))
				queue.put(("fingerprint_AcoustID", fingerprint))

		except (KeyboardInterrupt,SystemExit):
			pass
		except:
			sys.excepthook(*sys.exc_info())
		
		queue.put((None,None))
		
	from multiprocessing import Process, Queue
	queue = Queue()
	Process(target=doCalc, args=(queue,)).start()
	
	while True:
		attr, value = queue.get()
		if attr is None: break
		setattr(song, attr, value)

def checkUpdate():
	from queue import queue
	from State import state
	
	songs = [state.curSong]
	songs += queue.peekNextN(PreloadNextN)
	
	import threading
	curThread = threading.currentThread()
	
	for song in songs:
{'fraction_non_alphanumeric': 0.11464968152866242, 'fraction_numerical': 0.008152866242038216, 'mean_word_length': 3.98856416772554, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2791819', 'n_tokens_mistral': 1579, 'n_tokens_neox': 1291, 'n_words': 370}