This commit is contained in:
Шурупов Илья Викторович 2026-01-03 19:54:44 +03:00
parent e68e29fa4a
commit 589271ae20
5 changed files with 31 additions and 16 deletions

View file

@ -18,10 +18,11 @@ def get_data(name):
data = json.load(file)
return data
except FileNotFoundError:
return f"File {name}.json not found."
print(f"File {name}.json not found.")
return {}
except json.JSONDecodeError:
return f"Error decoding JSON from {name}.json."
print(f"Error decoding JSON from {name}.json.")
return {}
def save_data(data, name):
def remove_available_markets(obj):

View file

@ -1,7 +1,7 @@
from DataBase import *
from SpotifyWebAPI import find_song, update_access_token
from fuzzywuzzy import fuzz
from rapidfuzz import fuzz
from tqdm import tqdm
@ -99,7 +99,7 @@ def fuzzy_tag_pattern_generator():
album_ratio = fuzz.token_set_ratio(first.album, second.album) / 100
return title_ratio, artist_ratio, album_ratio
with tqdm(total=len(local_library), desc='Searching local songs on spotify') as pbar:
with tqdm(total=len(local_library), desc='fuzzy_tag_pattern_generator') as pbar:
for local_track_id, local_track in local_library.items():
mapping = mappings.get(local_track_id, {"score": 1.0, "items": []})
ratios = []

View file

@ -46,9 +46,15 @@ def update_local_library(root_dir):
abs_path = os.path.join(root_dir, track['path'])
match track['type']:
case ".mp3":
tag = eyed3.load(abs_path).tag
mp3track = eyed3.load(abs_path)
if not mp3track:
print(f"Failed to load mp3 {abs_path} using just name of the file as track name")
track['name'] = track['path']
else:
tag = mp3track.tag
if not tag:
print(f"Invalid mp3 header {abs_path}")
print(f"Invalid mp3 header {abs_path} using just name of the file as track name")
track['name'] = track['path']
else:
track['artist'] = tag.artist
track['name'] = tag.title
@ -64,10 +70,11 @@ def update_local_library(root_dir):
if 'album' in metadata:
track['album'] = " ".join(metadata['album'])
except mutagen.MutagenError:
print(f"Invalid flac header {abs_path}")
print(f"Invalid flac header {abs_path} using just name of the file as track name")
track['name'] = track['path']
save_data(new_library, "local_library")
if __name__ == "__main__":
update_local_library("/mnt/main/data/music/raw")
update_local_library("/home/auser/Music/")

View file

@ -34,7 +34,7 @@ def retrieve_web_api_token(authorization_code):
"client_secret": client_secret,
"client_id": client_id,
"code": authorization_code,
'redirect_uri': 'http://localhost:8888',
'redirect_uri': 'http://127.0.0.1:8888',
}
print("\nAuthenticating WEB API\n")
@ -95,7 +95,7 @@ def open_authenticate_page():
params = {
'client_id': client_id,
'response_type': 'code',
'redirect_uri': 'http://localhost:8888',
'redirect_uri': 'http://127.0.0.1:8888',
"scope": "user-top-read playlist-read-collaborative user-read-email user-library-read user-read-private playlist-read-private",
}

View file

@ -129,6 +129,10 @@ class Interpreter(cmd.Cmd):
print(f"2 - fuzzy")
def do_link_pattern(self, arg):
if not len(arg.split()):
print("expected name of the pattern")
return
"""prints available linking patterns"""
pattern_id = int(arg.split()[0])
print_link_stats(link_patterns[pattern_id])
@ -187,4 +191,7 @@ class Interpreter(cmd.Cmd):
if __name__ == '__main__':
try:
Interpreter().cmdloop()
except KeyboardInterrupt as kb:
print("process terminated")