Exemple #1
0
 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
Exemple #2
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")
Exemple #3
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
Exemple #4
0
 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