tmp
This commit is contained in:
parent
3744bd1c56
commit
e044b7ffd4
2 changed files with 86 additions and 7 deletions
|
|
@ -94,10 +94,10 @@ def fuzzy_tag_pattern_generator():
|
||||||
mappings = {}
|
mappings = {}
|
||||||
|
|
||||||
def fuzzy_tags_ratio(first: SongTags, second: SongTags):
|
def fuzzy_tags_ratio(first: SongTags, second: SongTags):
|
||||||
title_ratio = fuzz.ratio(first.title, second.title) / 100
|
title_ratio = fuzz.token_set_ratio(first.title, second.title) / 100
|
||||||
artist_ratio = fuzz.ratio(first.artist, second.artist) / 100
|
artist_ratio = fuzz.token_set_ratio(first.artist, second.artist) / 100
|
||||||
album_ratio = fuzz.ratio(first.album, second.album) / 100
|
album_ratio = fuzz.token_set_ratio(first.album, second.album) / 100
|
||||||
return sum([title_ratio, artist_ratio, album_ratio]) / 3
|
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='Searching local songs on spotify') as pbar:
|
||||||
for local_track_id, local_track in local_library.items():
|
for local_track_id, local_track in local_library.items():
|
||||||
|
|
@ -111,9 +111,15 @@ def fuzzy_tag_pattern_generator():
|
||||||
|
|
||||||
ratios.append((fuzzy_tags_ratio(tag1, tag2), track['id']))
|
ratios.append((fuzzy_tags_ratio(tag1, tag2), track['id']))
|
||||||
|
|
||||||
ratios.sort(reverse=True, key=lambda x: x[0])
|
filtered_ratios = []
|
||||||
if ratios[0][0] > 0.8:
|
threshold = 0.8
|
||||||
mapping['items'] = [ratios[0][1]]
|
for ratio in ratios:
|
||||||
|
if all([val > threshold for val in ratio[0]]):
|
||||||
|
filtered_ratios.append((sum(i for i in ratio[0]) / len(ratio[0]), ratio[1]))
|
||||||
|
|
||||||
|
filtered_ratios.sort(reverse=True, key=lambda x: x[0])
|
||||||
|
if len(filtered_ratios):
|
||||||
|
mapping['items'] = [filtered_ratios[0][1]]
|
||||||
|
|
||||||
mappings[local_track_id] = mapping
|
mappings[local_track_id] = mapping
|
||||||
pbar.update(1)
|
pbar.update(1)
|
||||||
|
|
|
||||||
73
main.py
73
main.py
|
|
@ -6,6 +6,9 @@ playlists = get_data('playlistTracks')
|
||||||
top_artists = get_data('top_artists')
|
top_artists = get_data('top_artists')
|
||||||
top_tracks = get_data('top_tracks')
|
top_tracks = get_data('top_tracks')
|
||||||
user_tracks = get_data('tracks')
|
user_tracks = get_data('tracks')
|
||||||
|
link_patterns = [get_data('link_pattern_tags'), get_data('link_pattern_tags'), get_data('link_pattern_tags')]
|
||||||
|
local_library = get_data("local_library")
|
||||||
|
user_tracks_by_id = {track['track']['id']: track['track'] for track in user_tracks}
|
||||||
|
|
||||||
|
|
||||||
def get_playlist_names(pl):
|
def get_playlist_names(pl):
|
||||||
|
|
@ -56,10 +59,80 @@ def print_tracks():
|
||||||
track_idx += 1
|
track_idx += 1
|
||||||
|
|
||||||
|
|
||||||
|
def sort_remote_tracks_by_popularity(track_ids):
|
||||||
|
out = []
|
||||||
|
for top_track in top_tracks:
|
||||||
|
if top_track['id'] in track_ids:
|
||||||
|
out.append(top_track['id'])
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def print_link_stats(link_pattern):
|
||||||
|
resolved_reversed = {}
|
||||||
|
resolved = []
|
||||||
|
unresolved_local = []
|
||||||
|
unresolved_remote = []
|
||||||
|
|
||||||
|
for local_id, links in link_pattern.items():
|
||||||
|
if len(links['items']):
|
||||||
|
resolved.append(local_id)
|
||||||
|
resolved_reversed[links['items'][0]] = local_id
|
||||||
|
else:
|
||||||
|
unresolved_local.append(local_id)
|
||||||
|
|
||||||
|
for track in user_tracks:
|
||||||
|
track_id = track['track']['id']
|
||||||
|
if track_id not in resolved_reversed:
|
||||||
|
unresolved_remote.append(track_id)
|
||||||
|
|
||||||
|
print(f"Local Tracks: {len(local_library)}")
|
||||||
|
print(f"Remote Tracks: {len(user_tracks)}")
|
||||||
|
|
||||||
|
unresolved_remote = sort_remote_tracks_by_popularity(unresolved_remote)
|
||||||
|
unresolved_remote = unresolved_remote[0:min(len(unresolved_remote), 100)]
|
||||||
|
|
||||||
|
print(f"\nUnresolved tracks from the remote: {len(unresolved_remote)}")
|
||||||
|
index = 0
|
||||||
|
for remote_id in unresolved_remote:
|
||||||
|
remote_track = user_tracks_by_id[remote_id]
|
||||||
|
print(f" {index}: '{remote_track['name']}' by '{get_artists_str(remote_track['artists'])}'")
|
||||||
|
index += 1
|
||||||
|
|
||||||
|
print(f"\nResolved tracks: {len(resolved)}")
|
||||||
|
index = 0
|
||||||
|
for link in resolved:
|
||||||
|
remote_id = link_pattern[link]['items'][0]
|
||||||
|
local_track = local_library[link]
|
||||||
|
remote_track = user_tracks_by_id[remote_id]
|
||||||
|
|
||||||
|
print(f" {index}: '{local_track['name']}' by '{local_track['artist']}'", end=' ----> ')
|
||||||
|
print(f"'{remote_track['name']}' by '{get_artists_str(remote_track['artists'])}'")
|
||||||
|
index += 1
|
||||||
|
|
||||||
|
return
|
||||||
|
print(f"\nUnresolved tracks from the local: {len(unresolved_local)}")
|
||||||
|
index = 0
|
||||||
|
for link in unresolved_local:
|
||||||
|
local_track = local_library[link]
|
||||||
|
print(f" {index}: '{local_track['name']}' by '{local_track['artist']}'")
|
||||||
|
index += 1
|
||||||
|
|
||||||
|
|
||||||
class Interpreter(cmd.Cmd):
|
class Interpreter(cmd.Cmd):
|
||||||
intro = "Welcome to the interactive command loop. Type help or ? to list commands.\n"
|
intro = "Welcome to the interactive command loop. Type help or ? to list commands.\n"
|
||||||
prompt = "(spotify) "
|
prompt = "(spotify) "
|
||||||
|
|
||||||
|
def do_link_patterns(self, arg):
|
||||||
|
"""prints available linking patterns"""
|
||||||
|
print(f"0 - fuzzy tags")
|
||||||
|
print(f"1 - spotify")
|
||||||
|
print(f"2 - fuzzy")
|
||||||
|
|
||||||
|
def do_link_pattern(self, arg):
|
||||||
|
"""prints available linking patterns"""
|
||||||
|
pattern_id = int(arg.split()[0])
|
||||||
|
print_link_stats(link_patterns[pattern_id])
|
||||||
|
|
||||||
def do_playlists(self, arg):
|
def do_playlists(self, arg):
|
||||||
"""prints user playlists"""
|
"""prints user playlists"""
|
||||||
pl_id = 0
|
pl_id = 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue