Exemplo n.º 1
0
    def run(self):
        print(self.config.username)
        if not self.config.is_valid():
            app = QApplication([])
            app.setQuitOnLastWindowClosed(True)
            auth = AuthUI()
            # ADD TUTORIAL WEBSITE webbrowser.open("https://alfred-spotify-mini-player.com/setup/", 2)
            while not self.config.is_valid():
                auth.show()
                app.exec_()
                if auth.isCanceled:
                    sys.exit()

        try:
            print("Starting auth process")
            self.oauth = self.config.get_oauth()
            self.token_info = self.oauth.get_access_token(as_dict=True)
            self.spotify = Spotify(auth=self.token_info["access_token"])

            self.init_tray()

            self.listener_thread.start()
            self.song_queue = SongQueue()
            self.image_queue = ImageQueue()
            self.cache_manager = CacheManager(self.spotify, self.song_queue,
                                              self.image_queue)

            self.spotlight = SpotlightUI(self.spotify, self.song_queue)

            self.show_spotlight()
            while True:
                self.app.exec_()

        except Exception as ex:
            print(ex)
Exemplo n.º 2
0
    def run(self):
        # Pre checks in event of no config.json
        # Validation dependencies

        if not self.config.is_valid():
            app = QApplication([])
            app.setQuitOnLastWindowClosed(True)
            auth = AuthUI()

            while not self.config.is_valid():
                auth.show()
                app.exec_()
                if auth.isCanceled:
                    sys.exit()
        while True:
            self.ui_invoke()
Exemplo n.º 3
0
 def __init__(self, sp: Spotify, queue: Queue):
     self.sp = sp
     self.auth_ui = AuthUI()
     self.command_list = [
         SongCommand(),
         QueueCommand(),
         PlaylistCommand(),
         AlbumCommand(),
         ArtistCommand(),
         PlayingCommand(sp),
         ShuffleCommand(sp),
         LikeCommand(sp),
         Command("Authentication", "Enter Spotify API details", "cog",
                 lambda: None, "", "authentication", "exe"),
         OnlineCommand(sp, type="song"),
         OnlineCommand(sp, type="queue"),
         OnlineCommand(sp, type="artist"),
         OnlineCommand(sp, type="playlist"),
         OnlineCommand(sp, type="album"),
         ParameterCommand(
             "Go to", "Seeks a position in the current song, i.e. 1:40",
             "forward", PlaybackManager.goto, "", "go to "),
         ParameterCommand(
             "Volume",
             "Sets the volume of your Spotify Player in range 1-10",
             "volume", PlaybackManager.set_volume, "", "volume "),
         DeviceCommand(sp),
         Command("Pause", "Pauses playback", "pause", PlaybackManager.pause,
                 "", "pause", "exe"),
         Command("Resume", "Resumes playback", "play",
                 PlaybackManager.resume, "", "resume", "exe"),
         RepeatCommand(),
         Command("Skip", "Skips to the next song", "forward",
                 PlaybackManager.skip, "", "skip", "exe"),
         Command("Previous", "Plays the previous song", "backward",
                 PlaybackManager.previous, "", "previous", "exe"),
         Command("Saved", "Plays liked music", "heart",
                 PlaybackManager.play_liked, "", "saved", "exe"),
         Command("Exit", "Exit the application", "exit",
                 PlaybackManager.exit_app, "", "exit", "exe"),
         Command("Share", "Copy song URL to clipboard", "share",
                 PlaybackManager.copy_url_to_clipboard, "", "share", "exe")
     ]
     self.manager = PlaybackManager(sp, queue)
     self.manager.set_device("")  # Sets default device
     CacheHolder.reload_holder("all")
Exemplo n.º 4
0
    def run(self):
        print(self.config.username)
        if not self.config.is_valid():
            app = QApplication([])
            app.setQuitOnLastWindowClosed(True)
            auth = AuthUI()
            # ADD TUTORIAL WEBSITE webbrowser.open("https://alfred-spotify-mini-player.com/setup/", 2)
            while not self.config.is_valid():
                auth.show()
                app.exec_()
                if auth.isCanceled:
                    sys.exit()

        try:
            print("Starting auth process")

            # sets up a Spotify username env var which is referenced elsewhere
            environ["SPOTIFY_USERNAME"] = self.config.username  # TODO Change this to something permanent

            self.oauth = self.config.get_oauth()
            self.token_info = self.oauth.get_access_token(as_dict=True)
            SpotifySingleton(self.token_info["access_token"])  # Instantiate Singleton Object
            self.spotify = SpotifySingleton.get_instance()

            self.init_tray()

            self.listener_thread.start()
            self.song_queue = SongQueue()
            self.image_queue = ImageQueue()
            self.cache_manager = CacheManager(self.spotify, self.song_queue, self.image_queue)

            self.spotlight = SpotlightUI(self.spotify, self.song_queue, self.spotifyclient)

            self.show_spotlight()
            while True:
                self.app.exec_()

        except Exception as ex:
            print(ex)
Exemplo n.º 5
0
    def __init__(self, sp: Spotify, queue: Queue):
        self.sp = sp
        self.auth_ui = AuthUI()
        # store commands in a list
        # sp needed for some commands for some API functions i.e. check the state of song shuffle
        self.command_list = [
            SearchCacheCommand("song"),
            SearchCacheCommand("queue"),
            SearchCacheCommand("artist"),
            SearchCacheCommand("album"),
            SearchCacheCommand("playlist"),
            SearchOnlineCommand("song", sp),
            SearchOnlineCommand("queue", sp),
            SearchOnlineCommand("artist", sp),
            SearchOnlineCommand("album", sp),
            SearchOnlineCommand("playlist", sp),
            ResumeCommand(),
            LikeCommand(sp),
            RepeatCommand(),
            ShuffleCommand(sp),
            PlayingCommand(sp),
            PreviousCommand(),
            NextCommand(),
            PauseCommand(),
            VolumeCommand(),
            GoToCommand(),
            DeviceCommand(sp),
            SavedCommand(),
            ShareCommand(),
            AuthenticationCommand(),
            ExitCommand()
        ]

        self.manager = PlaybackManager(sp, queue)
        # TODO create a settings json to store things like default device
        self.manager.set_device("")  # sets device to first available
        CacheHolder.reload_holder(
            "all")  # Initially loads the cache into memory
Exemplo n.º 6
0
class CommandHandler:
    """
    Handles commands and output suggestions for the Spotlight UI
    """
    def __init__(self, sp: Spotify, queue: Queue):
        self.sp = sp
        self.auth_ui = AuthUI()
        # store commands in a list
        # sp needed for some commands for some API functions i.e. check the state of song shuffle
        self.command_list = [
            SearchCacheCommand("song"),
            SearchCacheCommand("queue"),
            SearchCacheCommand("artist"),
            SearchCacheCommand("album"),
            SearchCacheCommand("playlist"),
            SearchOnlineCommand("song", sp),
            SearchOnlineCommand("queue", sp),
            SearchOnlineCommand("artist", sp),
            SearchOnlineCommand("album", sp),
            SearchOnlineCommand("playlist", sp),
            ResumeCommand(),
            LikeCommand(sp),
            RepeatCommand(),
            ShuffleCommand(sp),
            PlayingCommand(sp),
            PreviousCommand(),
            NextCommand(),
            PauseCommand(),
            VolumeCommand(),
            GoToCommand(),
            DeviceCommand(sp),
            SavedCommand(),
            ShareCommand(),
            AuthenticationCommand(),
            ExitCommand()
        ]

        self.manager = PlaybackManager(sp, queue)
        # TODO create a settings json to store things like default device
        CacheHolder.reload_holder(
            "all")  # Initially loads the cache into memory

    def get_command_suggestions(self, text: str) -> list:
        """
        Used to return a list of Suggestion objects to be displayed
        :param text: Text from textbox widget on Spotlight UI
        :return: list of Suggestion objects corresponding to the text parameter
        """
        CacheHolder.check_reload(
            "all"
        )  # Reloads cached suggestions if time since last reload has surpassed 5 minutes
        suggestions = []
        if text == "":
            return suggestions
        for command in self.command_list:
            prefix = command.prefix
            if prefix.startswith(text) or text.startswith(prefix):
                if text > prefix:
                    parameter = text[len(prefix):]
                else:
                    parameter = ""
                suggestions.extend(
                    command.get_suggestions(parameter=parameter))
        if not suggestions:  # gets song suggestions if no other matches are found
            suggestions = self.command_list[0].get_suggestions(parameter=text)
        return suggestions

    def execute_function(self, suggestion: Suggestion):
        """
        Executes a command
        :param suggestion: Suggestion Object
        """
        try:
            if suggestion.title == "Authentication":  # opens Auth UI, needs changed at some point
                self.auth_ui.show()
            elif suggestion.parameter == "":  # executes Suggestion's function
                suggestion.function(self.manager)
            else:  # executes Suggestion's function with a string parameter
                suggestion.function(self.manager, suggestion.parameter)
        except:
            print("[Error] Command failed to execute")
Exemplo n.º 7
0
class CommandHandler:
    def __init__(self, sp: Spotify, queue: Queue):
        self.sp = sp
        self.auth_ui = AuthUI()
        self.command_list = [
            SongCommand(),
            QueueCommand(),
            PlaylistCommand(),
            AlbumCommand(),
            ArtistCommand(),
            PlayingCommand(sp),
            ShuffleCommand(sp),
            LikeCommand(sp),
            Command("Authentication", "Enter Spotify API details", "cog",
                    lambda: None, "", "authentication", "exe"),
            OnlineCommand(sp, type="song"),
            OnlineCommand(sp, type="queue"),
            OnlineCommand(sp, type="artist"),
            OnlineCommand(sp, type="playlist"),
            OnlineCommand(sp, type="album"),
            ParameterCommand(
                "Go to", "Seeks a position in the current song, i.e. 1:40",
                "forward", PlaybackManager.goto, "", "go to "),
            ParameterCommand(
                "Volume",
                "Sets the volume of your Spotify Player in range 1-10",
                "volume", PlaybackManager.set_volume, "", "volume "),
            DeviceCommand(sp),
            Command("Pause", "Pauses playback", "pause", PlaybackManager.pause,
                    "", "pause", "exe"),
            Command("Resume", "Resumes playback", "play",
                    PlaybackManager.resume, "", "resume", "exe"),
            RepeatCommand(),
            Command("Skip", "Skips to the next song", "forward",
                    PlaybackManager.skip, "", "skip", "exe"),
            Command("Previous", "Plays the previous song", "backward",
                    PlaybackManager.previous, "", "previous", "exe"),
            Command("Saved", "Plays liked music", "heart",
                    PlaybackManager.play_liked, "", "saved", "exe"),
            Command("Exit", "Exit the application", "exit",
                    PlaybackManager.exit_app, "", "exit", "exe"),
            Command("Share", "Copy song URL to clipboard", "share",
                    PlaybackManager.copy_url_to_clipboard, "", "share", "exe")
        ]
        self.manager = PlaybackManager(sp, queue)
        self.manager.set_device("")  # Sets default device
        CacheHolder.reload_holder("all")

    def get_command_suggestions(self, text: str) -> list:
        """
        Used to return a list of Suggestion objects to be displayed
        :param text: Text from textbox widget on GUI
        :return: list of Suggestion objects corresponding to the text parameter
        """
        CacheHolder.check_reload(
            "all"
        )  # Reloads cached items if time since last reload has surpassed 5 minutes
        suggestions = []
        for command in self.command_list:
            prefix = command.prefix
            if prefix.startswith(text) or text.startswith(prefix):
                if issubclass(command.__class__, Menu):
                    if len(prefix) >= len(text):
                        suggestions.extend(
                            command.get_items(True if command.prefix ==
                                              text else False))
                else:
                    if text > prefix:
                        command.parameter = text[len(prefix):]
                    else:
                        command.parameter = ""
                    suggestions.extend(command.get_items())
        if not suggestions:  # gets song suggestions if no other matches are found
            self.command_list[0].parameter = text
            suggestions = self.command_list[0].get_items()
        return suggestions

    def perform_command(self, command: Suggestion):
        """
        Executes a command
        :param command: Suggestion object
        :return:
        """
        try:
            if command.title == "Authentication":
                self.auth_ui.show()
            elif command.parameter == "":
                command.function(self.manager)
            else:
                command.function(self.manager, command.parameter)
        except:
            print("[Error] Command failed to execute")