need run main fetch command then run indexer then LinkerPatternGenerator then link_pattern command in the main
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
import json
|
|
import os
|
|
|
|
data_dir = 'prefetched'
|
|
|
|
|
|
class SongTags:
|
|
def __init__(self, title='', artist='', album=''):
|
|
self.artist = artist
|
|
self.title = title
|
|
self.album = album
|
|
|
|
|
|
def get_data(name):
|
|
file_path = os.path.join(data_dir, f"{name}.json")
|
|
try:
|
|
with open(file_path, 'r') as file:
|
|
data = json.load(file)
|
|
return data
|
|
except FileNotFoundError:
|
|
print(f"File {name}.json not found.")
|
|
return {}
|
|
except json.JSONDecodeError:
|
|
print(f"Error decoding JSON from {name}.json.")
|
|
return {}
|
|
|
|
def save_data(data, name):
|
|
def remove_available_markets(obj):
|
|
if isinstance(obj, dict):
|
|
return {key: remove_available_markets(value) for key, value in obj.items() if key != 'available_markets'}
|
|
elif isinstance(obj, list):
|
|
return [remove_available_markets(item) for item in obj]
|
|
else:
|
|
return obj
|
|
|
|
data = remove_available_markets(data)
|
|
|
|
os.makedirs(data_dir, exist_ok=True)
|
|
|
|
file_path = os.path.join(data_dir, f"{name}.json")
|
|
with open(file_path, 'w') as file:
|
|
json.dump(data, file, indent=4)
|
|
return f"Data saved to {name}.json."
|
|
|
|
|
|
def get_artists_str(artists_pack):
|
|
track_artists = [artist['name'] for artist in artists_pack]
|
|
artists = " ".join(track_artists)
|
|
return artists
|