def fingerprint_file(self, filepath, song_name=None): songname = path_to_songname(filepath) song_name = song_name or songname if db.has(song_name): print("%s already fingerprinted" % (song_name)) return None, None song_name, hashes = _fingerprint_worker(filepath, self.limit, song_name=song_name) sid = db.insert_song(song_name) db.insert_hashes(sid, hashes)
def fingerprint_file(self, filepath, song_name=None): songname = path_to_songname(filepath) song_name = song_name or songname if db.has(song_name): print("%s already fingerprinted" %(song_name)) return None,None song_name, hashes = _fingerprint_worker( filepath, self.limit, song_name=song_name ) sid = db.insert_song(song_name) db.insert_hashes(sid, hashes)
def fingerprint_directory(self, path, extensions, nprocesses=None): # Try to use the maximum amount of processes if not given. try: nprocesses = nprocesses or multiprocessing.cpu_count() except NotImplementedError: nprocesses = 1 else: nprocesses = 1 if nprocesses <= 0 else nprocesses pool = multiprocessing.Pool(nprocesses) filenames_to_fingerprint = [] for filename,_ in find_files(path, extensions): filenames_to_fingerprint.append(filename) # Prepare _fingerprint_worker input worker_input = zip(filenames_to_fingerprint, [self.limit] * len(filenames_to_fingerprint)) # Send off our tasks iterator = pool.imap_unordered(_fingerprint_worker, worker_input) # Loop till we have all of them while True: try: song_name, hashes = iterator.next() except multiprocessing.TimeoutError: continue except StopIteration: break except: print("Failed fingerprinting") # Print traceback because we can't reraise it here traceback.print_exc(file=sys.stdout) else: if song_name and hashes: sid = db.insert_song(song_name) db.insert_hashes(sid, hashes) pool.close() pool.join()
def fingerprint_directory(self, path, extensions, nprocesses=None): # Try to use the maximum amount of processes if not given. try: nprocesses = nprocesses or multiprocessing.cpu_count() except NotImplementedError: nprocesses = 1 else: nprocesses = 1 if nprocesses <= 0 else nprocesses pool = multiprocessing.Pool(nprocesses) filenames_to_fingerprint = [] for filename, _ in find_files(path, extensions): filenames_to_fingerprint.append(filename) # Prepare _fingerprint_worker input worker_input = zip(filenames_to_fingerprint, [self.limit] * len(filenames_to_fingerprint)) # Send off our tasks iterator = pool.imap_unordered(_fingerprint_worker, worker_input) # Loop till we have all of them while True: try: song_name, hashes = iterator.next() except multiprocessing.TimeoutError: continue except StopIteration: break except: print("Failed fingerprinting") # Print traceback because we can't reraise it here traceback.print_exc(file=sys.stdout) else: if song_name and hashes: sid = db.insert_song(song_name) db.insert_hashes(sid, hashes) pool.close() pool.join()