77 lines
2.1 KiB
Python
77 lines
2.1 KiB
Python
|
|
import cmd
|
|
|
|
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.MapLocalToSpotify import map_local_to_spotify
|
|
|
|
|
|
class Interpreter(cmd.Cmd):
|
|
intro = "Welcome to the interactive command loop. Type help or ? to list commands.\n"
|
|
prompt = "(kuw) "
|
|
|
|
spotify_library = None
|
|
local_library = None
|
|
|
|
@staticmethod
|
|
def do_fetch_spotify(self):
|
|
fetch_all(client_id, client_secret, work_dir)
|
|
|
|
|
|
@staticmethod
|
|
def do_fetch_local():
|
|
update_local_library(local_library_path, work_dir)
|
|
|
|
|
|
def do_parse_spotify_library(self):
|
|
parser = Parser()
|
|
library_parsed = parser.parse(work_dir / "spotify" / "playlistTracks.json", work_dir / "spotify" / "tracks.json")
|
|
LibrarySaver(library_parsed).save(work_dir / "spotify_library.json")
|
|
|
|
def do_parse_local_library(self):
|
|
parser = LocalParser()
|
|
library_parsed = parser.parse(work_dir / "local" / "local_library.json")
|
|
LibrarySaver(library_parsed).save(work_dir / "local_library.json")
|
|
|
|
def do_load_libraries(self):
|
|
self.spotify_library = LibraryLoader().load(work_dir / "spotify_library.json")
|
|
self.local_library = LibraryLoader().load(work_dir / "local_library.json")
|
|
|
|
def do_map_local_to_spotify(self):
|
|
map_local_to_spotify(client_id, client_secret, self.local_library, self.spotify_library, work_dir)
|
|
|
|
|
|
def do_run(self, arg):
|
|
# self.do_fetch_local()
|
|
# self.do_fetch_spotify()
|
|
|
|
# self.do_parse_local_library()
|
|
# self.do_parse_spotify_library()
|
|
|
|
self.do_load_libraries()
|
|
|
|
self.do_map_local_to_spotify()
|
|
|
|
return True
|
|
|
|
@staticmethod
|
|
def do_exit(self, arg):
|
|
return True
|
|
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
Interpreter().do_run("")
|
|
# Interpreter().cmdloop()
|
|
|
|
except KeyboardInterrupt as kb:
|
|
print("process terminated")
|