refactor 2
This commit is contained in:
parent
a620e7a4f5
commit
5f4bbbaa59
7 changed files with 426 additions and 503 deletions
86
main.py
86
main.py
|
|
@ -1,77 +1,17 @@
|
|||
|
||||
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
|
||||
|
||||
import Flow
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
Interpreter().do_run("")
|
||||
# Interpreter().cmdloop()
|
||||
flow = Flow.Flow()
|
||||
|
||||
except KeyboardInterrupt as kb:
|
||||
print("process terminated")
|
||||
# flow.fetch_spotify()
|
||||
flow.fetch_local()
|
||||
|
||||
flow.parse_spotify_library()
|
||||
flow.parse_local_library()
|
||||
|
||||
flow.load_libraries()
|
||||
|
||||
flow.map_local_to_spotify()
|
||||
|
||||
print("asd")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue