Created
November 12, 2023 14:34
-
-
Save kompowiec/d2858c2486a8f88a9bd899dcb80fb65c to your computer and use it in GitHub Desktop.
mirror script from /r/HLWIT https://redd.it/17sy4kn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tqdm | |
import asyncio | |
from shazamio import Shazam, Serialize | |
import os | |
from multiprocessing import Pool, freeze_support, set_start_method | |
from datetime import datetime | |
async def recognize(song): | |
shazam = Shazam() | |
try: | |
out = await shazam.recognize_song(song) | |
if (out['matches']!=[]): | |
if (int(out['track']['key']) == 679351247): | |
s = 'FOUND!!!: ' + song | |
return s | |
except: | |
pass | |
def process_file(file_path): | |
return asyncio.run(recognize(file_path)) | |
def get_files(startpath): | |
with Pool() as pool: | |
for result in pool.imap_unordered(process_file, file_paths): | |
pbar.update(1) | |
if result != None: | |
pbar.write(result) | |
with open("result.txt", "a", encoding="utf-8") as f: | |
f.write(result + '\n') | |
if __name__ == '__main__': | |
freeze_support() | |
set_start_method('spawn') | |
while True: | |
path = os.path.normpath(input('Folder path: ')) | |
if os.path.exists(path): break | |
print("Folder dosn't exist!") | |
try: | |
print('Scanning...') | |
with open("result.txt", "a", encoding="utf-8") as f: | |
f.write('\n\n----' + str(datetime.now()) + '----\n') | |
file_paths = [] | |
for root, dirs, files in os.walk(path): | |
file_paths.extend([os.path.normpath(os.path.join(root, file)) for file in files]) | |
pbar = tqdm.tqdm(total=len(file_paths)) | |
get_files(path) | |
pbar.write('Done!') | |
with open("result.txt", "a", encoding="utf-8") as f: | |
f.write('Done!\n') | |
f.write('----' + str(datetime.now()) + '----\n') | |
pbar.disable = True | |
input('\n Press Enter to exit') | |
except Exception: | |
print("Exception in user code:") | |
print("-"*60) | |
traceback.print_exc(file=sys.stdout) | |
print("-"*60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment