refactor 2
This commit is contained in:
parent
a620e7a4f5
commit
5f4bbbaa59
7 changed files with 426 additions and 503 deletions
65
Flow.py
Normal file
65
Flow.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
|
||||
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 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):
|
||||
map_local_to_spotify(client_id, client_secret, self.local_library, self.spotify_library, work_dir)
|
||||
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue