stable - generate local playlists & add default options
This commit is contained in:
parent
11e3b06824
commit
892568d668
4 changed files with 132 additions and 26 deletions
|
|
@ -3,7 +3,7 @@ from SpotifyWebAPI import find_song, update_access_token
|
|||
|
||||
from rapidfuzz import fuzz
|
||||
from tqdm import tqdm
|
||||
|
||||
import requests
|
||||
|
||||
def spotify_pattern_generator():
|
||||
update_access_token()
|
||||
|
|
@ -11,15 +11,29 @@ def spotify_pattern_generator():
|
|||
local_library = get_data("local_library")
|
||||
spotify_library = get_data("tracks")
|
||||
|
||||
|
||||
def find_local_songs_on_spotify(local_lib):
|
||||
search_log = []
|
||||
|
||||
total = len(local_library)
|
||||
found_tracks_map = {}
|
||||
with tqdm(total=total, desc='Searching local songs on spotify') as pbar:
|
||||
for track_id, track in local_lib.items():
|
||||
search_pattern = f"{track['name']} {track['artist']} {track['album']}"
|
||||
found_tracks = find_song(search_pattern)
|
||||
found_tracks_map[track_id] = found_tracks[0:1]
|
||||
parts = [track["name"], track["artist"], track.get("album")]
|
||||
search_pattern = " ".join(p for p in parts if p)
|
||||
|
||||
if search_pattern == "":
|
||||
print(f"cannot generate search pattern for the track - {track["path"]}")
|
||||
pbar.update(1)
|
||||
continue
|
||||
|
||||
found_tracks = find_song(search_pattern)[0:1]
|
||||
found_tracks_map[track_id] = found_tracks
|
||||
search_log.append({"path" : track["path"], "search_pattern": search_pattern, "result" : found_tracks_map[track_id]})
|
||||
pbar.update(1)
|
||||
|
||||
save_data(search_log, "spotify_search_log")
|
||||
|
||||
return found_tracks_map
|
||||
|
||||
spotify_found_tracks = find_local_songs_on_spotify(local_library)
|
||||
|
|
@ -127,10 +141,8 @@ def fuzzy_tag_pattern_generator():
|
|||
save_data(mappings, "link_pattern_tags")
|
||||
|
||||
|
||||
def run_pattern_generators():
|
||||
#fuzzy_pattern_generator()
|
||||
#spotify_pattern_generator()
|
||||
fuzzy_tag_pattern_generator()
|
||||
def run_pattern_generators(type_id = 0):
|
||||
spotify_pattern_generator()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue