fixes
This commit is contained in:
parent
5f4bbbaa59
commit
20c7b28ed6
7 changed files with 91 additions and 276 deletions
|
|
@ -1,42 +1,55 @@
|
|||
from src.Library import *
|
||||
|
||||
def print_link_stats(link_pattern):
|
||||
resolved_reversed = {}
|
||||
resolved = []
|
||||
unresolved_local = []
|
||||
unresolved_remote = []
|
||||
from pathlib import Path
|
||||
import json
|
||||
|
||||
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)
|
||||
out = {
|
||||
"local_count": 0,
|
||||
"resolved_count": 0,
|
||||
"unresolved_tracks": [],
|
||||
}
|
||||
|
||||
for track in user_tracks:
|
||||
track_id = track['track']['id']
|
||||
if track_id not in resolved_reversed:
|
||||
unresolved_remote.append(track_id)
|
||||
def get_mapping(mapping_path) -> dict[str, Any]:
|
||||
data = {}
|
||||
|
||||
print(f"Local Tracks: {len(local_library)}")
|
||||
print(f"Remote Tracks: {len(user_tracks)}")
|
||||
with Path(mapping_path).open("r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
|
||||
unresolved_remote = sort_remote_tracks_by_popularity(unresolved_remote)
|
||||
unresolved_remote = unresolved_remote[0:min(len(unresolved_remote), 100)]
|
||||
out = {}
|
||||
|
||||
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
|
||||
for local, remotes in data.items():
|
||||
if len(remotes["items"]):
|
||||
out[local] = remotes["items"][0]
|
||||
|
||||
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]
|
||||
return out
|
||||
|
||||
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
|
||||
|
||||
def find_add_local_paths(mapping_path: Path, local_lib: Library, remote_lib: Library):
|
||||
mapping = get_mapping(mapping_path)
|
||||
|
||||
out["resolved_count"] = len(mapping)
|
||||
|
||||
remote_id_map = {track.id: track for track in remote_lib.tracks}
|
||||
local_id_map = {track.id: track for track in local_lib.tracks}
|
||||
|
||||
for local, remote in mapping.items():
|
||||
remote_id_map[remote].local_path = local_id_map[local].local_path
|
||||
|
||||
|
||||
def generate_stats(local_lib: Library, remote_lib: Library, output_path : Path):
|
||||
|
||||
out["local_count"] = len(local_lib.tracks)
|
||||
|
||||
for track in remote_lib.top_tracks:
|
||||
if not track.local_path:
|
||||
out["unresolved_tracks"].append(
|
||||
f"{track.title} - {track.artists[0].title if len(track.artists) else ""} - {track.album.title}")
|
||||
|
||||
|
||||
with output_path.open("w", encoding="utf-8") as f:
|
||||
json.dump(out, f, indent=2, ensure_ascii=False)
|
||||
|
||||
|
||||
def log_stats(mapping_path : Path, output_path : Path, local_lib: Library, remote_lib: Library):
|
||||
find_add_local_paths(mapping_path, local_lib, remote_lib)
|
||||
generate_stats(local_lib, remote_lib, output_path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue