def main(args=None): # suppress messages to prevent GUI corruption logging.disable(sys.maxsize) os.environ["SPOTIPY_CLIENT_ID"] = "711661c6916a4a9981244380aa852adc" # set correct path for application sys.path.insert(0, str(pathlib.Path(__file__).parents[1])) print(sys.path[0]) from spotidex.models.spotifyAuth import SpotifyAuth from spotidex.views.login_screen import LoginScreen from spotidex.views.main_menu import MainMenu from spotidex.views.terminal_wrapper import TerminalWrapper auth = SpotifyAuth.get_instance() if auth.current_user: starting_screen = MainMenu() else: starting_screen = LoginScreen() try: TerminalWrapper.start_application(starting_screen) except KeyboardInterrupt: TerminalWrapper.clean_resources()
def __init__(self): self.__callback: Callable[ [], SpotifyTrack] = SpotifyAuth.get_instance().currently_playing self.__current_song_data: Optional[SpotifyTrack] = None self.__previous_song_data: Optional[SpotifyTrack] = None self.__refresh_lock: Lock = Lock() self.__auto_lock: Lock = Lock() self.__automatic_refresh: bool = True self.__refresh_killed: bool = False self.__session = Session.get_instance()
def test_simulate_invalid_login(self): copyfile(self.cache_path, self.cache_backup_path) SpotifyAuth._SpotifyAuth__cache_path = self.cache_path auth = SpotifyAuth.get_instance() auth._SpotifyAuth__endpoint = FailingEndpoint( auth._SpotifyAuth__endpoint) self.assertFalse(auth.establish_connection(), "user should not be connected") self.assertFalse(os.path.exists("test/resources/invalid_cache"), "invalid cache should be removed.")
def test_manual_attempt(self): auth = SpotifyAuth.get_instance() connected = auth.establish_connection() if connected: self.assertTrue( auth.current_user, "Current user should be available on successful connection.") self.assertTrue( self.user_still_logged_in(), "User should still be logged in on subsequent program launch.") else: self.assertFalse( auth.current_user, "Current user should equal None when connection unsuccessful.")
def test_simulate_correct_login(self): cache_path = self.simulated_cache_path SpotifyAuth._SpotifyAuth__cache_path = cache_path with open(cache_path, "w+") as cache_file: cache_file.write("{}") auth = SpotifyAuth.get_instance() self.assertFalse(auth.current_user, "no cache should mean that there is no current user") auth._SpotifyAuth__endpoint = PassingEndpoint() self.assertTrue(auth.establish_connection(), "Connection should be established with mock endpoint") self.assertEqual( "sample_user", auth.current_user, "User should match with one provided by mock endpoint ")
def __init__(self): self.__auth = SpotifyAuth.get_instance() message = f"Welcome, {self.__auth.current_user}!" # Menu contexts not yet implemented. Saving for future versions choices = [ Choice( "Begin Session", self.begin, """ Start your Spotify session now! """), Choice( "Log out", self.logout, """ Log out of Spotidex, note you will need to re-authenticate to re-use. """), Choice( "Exit Spotidex", TerminalWrapper.exit, ) ] menu = Menu() menu.add_choice_block(choices, description=message) self.__widget = menu.build()
import json from spotidex.models.spotifyAuth import SpotifyAuth auth = SpotifyAuth() auth.establish_connection() refresh = auth.currently_playing song_info = refresh().information for item, value in song_info.items(): print(item) print("----------") for attr in song_info[item].items(): print(attr)
def __init__(self): self.__auth = SpotifyAuth.get_instance() self.success = False self.lock = Lock()
def user_still_logged_in(self): self.setUp() auth = SpotifyAuth.get_instance() return auth.current_user
def test_user_exists_valid_cache(self): SpotifyAuth._SpotifyAuth__cache_path = "test/resources/valid_cache" auth = SpotifyAuth.get_instance() self.assertEqual("redbrickhut", auth.current_user, "user redbrickhut should be logged in")