70 lines
No EOL
2.1 KiB
Python
70 lines
No EOL
2.1 KiB
Python
|
|
from Env import client_id, client_secret, local_library_path
|
|
from Env import work_dir
|
|
|
|
from src.LibrarySerializer import LibrarySaver, LibraryLoader
|
|
|
|
from src.spotify.SpotifyWebAPI import fetch_all
|
|
from src.spotify.ParseSpotify import Parser
|
|
|
|
from src.local.LocalLibraryIndexer import update_local_library
|
|
from src.local.ParseLocal import LocalParser
|
|
|
|
from src.mappers.RemoteLibraryResolver import resolve_remote_tracks
|
|
from src.StatGenerator import log_stats
|
|
|
|
|
|
class Flow:
|
|
spotify_library = None
|
|
local_library = None
|
|
|
|
@staticmethod
|
|
def fetch_spotify(self):
|
|
fetch_all(client_id, client_secret, work_dir)
|
|
|
|
@staticmethod
|
|
def fetch_local():
|
|
update_local_library(local_library_path, work_dir)
|
|
|
|
@staticmethod
|
|
def parse_spotify_library():
|
|
parser = Parser()
|
|
|
|
library_parsed = parser.parse(
|
|
work_dir / "spotify" / "playlistTracks.json",
|
|
work_dir / "spotify" / "tracks.json",
|
|
work_dir / "spotify" / "top_tracks.json",
|
|
work_dir / "spotify" / "top_artists.json",
|
|
)
|
|
|
|
LibrarySaver(library_parsed).save(work_dir / "spotify_library.json")
|
|
|
|
@staticmethod
|
|
def parse_local_library():
|
|
parser = LocalParser()
|
|
library_parsed = parser.parse(work_dir / "local" / "local_library.json")
|
|
LibrarySaver(library_parsed).save(work_dir / "local_library.json")
|
|
|
|
def load_libraries(self):
|
|
self.spotify_library = LibraryLoader().load(work_dir / "spotify_library.json")
|
|
self.local_library = LibraryLoader().load(work_dir / "local_library.json")
|
|
|
|
def map_local_to_spotify(self):
|
|
resolve_remote_tracks(client_id, client_secret, self.local_library, self.spotify_library, work_dir)
|
|
|
|
def log_stats(self):
|
|
log_stats(work_dir / "remote_to_local_map.json", work_dir / "stats", self.local_library, self.spotify_library)
|
|
|
|
|
|
def run(self, arg):
|
|
self.fetch_local()
|
|
# self.do_fetch_spotify()
|
|
|
|
self.parse_local_library()
|
|
self.parse_spotify_library()
|
|
|
|
self.load_libraries()
|
|
|
|
# self.map_local_to_spotify()
|
|
|
|
return True |