tmp
This commit is contained in:
parent
e68e29fa4a
commit
589271ae20
5 changed files with 31 additions and 16 deletions
|
|
@ -18,10 +18,11 @@ def get_data(name):
|
||||||
data = json.load(file)
|
data = json.load(file)
|
||||||
return data
|
return data
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return f"File {name}.json not found."
|
print(f"File {name}.json not found.")
|
||||||
|
return {}
|
||||||
except json.JSONDecodeError:
|
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 save_data(data, name):
|
||||||
def remove_available_markets(obj):
|
def remove_available_markets(obj):
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from DataBase import *
|
from DataBase import *
|
||||||
from SpotifyWebAPI import find_song, update_access_token
|
from SpotifyWebAPI import find_song, update_access_token
|
||||||
|
|
||||||
from fuzzywuzzy import fuzz
|
from rapidfuzz import fuzz
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -99,7 +99,7 @@ def fuzzy_tag_pattern_generator():
|
||||||
album_ratio = fuzz.token_set_ratio(first.album, second.album) / 100
|
album_ratio = fuzz.token_set_ratio(first.album, second.album) / 100
|
||||||
return title_ratio, artist_ratio, album_ratio
|
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():
|
for local_track_id, local_track in local_library.items():
|
||||||
mapping = mappings.get(local_track_id, {"score": 1.0, "items": []})
|
mapping = mappings.get(local_track_id, {"score": 1.0, "items": []})
|
||||||
ratios = []
|
ratios = []
|
||||||
|
|
|
||||||
|
|
@ -46,13 +46,19 @@ def update_local_library(root_dir):
|
||||||
abs_path = os.path.join(root_dir, track['path'])
|
abs_path = os.path.join(root_dir, track['path'])
|
||||||
match track['type']:
|
match track['type']:
|
||||||
case ".mp3":
|
case ".mp3":
|
||||||
tag = eyed3.load(abs_path).tag
|
mp3track = eyed3.load(abs_path)
|
||||||
if not tag:
|
if not mp3track:
|
||||||
print(f"Invalid mp3 header {abs_path}")
|
print(f"Failed to load mp3 {abs_path} using just name of the file as track name")
|
||||||
|
track['name'] = track['path']
|
||||||
else:
|
else:
|
||||||
track['artist'] = tag.artist
|
tag = mp3track.tag
|
||||||
track['name'] = tag.title
|
if not tag:
|
||||||
track['album'] = tag.album
|
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
|
||||||
|
track['album'] = tag.album
|
||||||
|
|
||||||
case ".flac":
|
case ".flac":
|
||||||
try:
|
try:
|
||||||
|
|
@ -64,10 +70,11 @@ def update_local_library(root_dir):
|
||||||
if 'album' in metadata:
|
if 'album' in metadata:
|
||||||
track['album'] = " ".join(metadata['album'])
|
track['album'] = " ".join(metadata['album'])
|
||||||
except mutagen.MutagenError:
|
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")
|
save_data(new_library, "local_library")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
update_local_library("/mnt/main/data/music/raw")
|
update_local_library("/home/auser/Music/")
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ def retrieve_web_api_token(authorization_code):
|
||||||
"client_secret": client_secret,
|
"client_secret": client_secret,
|
||||||
"client_id": client_id,
|
"client_id": client_id,
|
||||||
"code": authorization_code,
|
"code": authorization_code,
|
||||||
'redirect_uri': 'http://localhost:8888',
|
'redirect_uri': 'http://127.0.0.1:8888',
|
||||||
}
|
}
|
||||||
|
|
||||||
print("\nAuthenticating WEB API\n")
|
print("\nAuthenticating WEB API\n")
|
||||||
|
|
@ -95,7 +95,7 @@ def open_authenticate_page():
|
||||||
params = {
|
params = {
|
||||||
'client_id': client_id,
|
'client_id': client_id,
|
||||||
'response_type': 'code',
|
'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",
|
"scope": "user-top-read playlist-read-collaborative user-read-email user-library-read user-read-private playlist-read-private",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
9
main.py
9
main.py
|
|
@ -129,6 +129,10 @@ class Interpreter(cmd.Cmd):
|
||||||
print(f"2 - fuzzy")
|
print(f"2 - fuzzy")
|
||||||
|
|
||||||
def do_link_pattern(self, arg):
|
def do_link_pattern(self, arg):
|
||||||
|
if not len(arg.split()):
|
||||||
|
print("expected name of the pattern")
|
||||||
|
return
|
||||||
|
|
||||||
"""prints available linking patterns"""
|
"""prints available linking patterns"""
|
||||||
pattern_id = int(arg.split()[0])
|
pattern_id = int(arg.split()[0])
|
||||||
print_link_stats(link_patterns[pattern_id])
|
print_link_stats(link_patterns[pattern_id])
|
||||||
|
|
@ -187,4 +191,7 @@ class Interpreter(cmd.Cmd):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
Interpreter().cmdloop()
|
try:
|
||||||
|
Interpreter().cmdloop()
|
||||||
|
except KeyboardInterrupt as kb:
|
||||||
|
print("process terminated")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue