Пример #1
0
    def music_setting(self, stat):
        response = ""
        try:
            import sys
            sys.path.append(self.UTILS_DIR)
            from musicplayer import MusicPlayer
            mp = MusicPlayer()

            player_setting = mp.get_player_setting()["status"].strip().lower()

            if player_setting != "close":
                if "pause" in stat:
                    stat = "pause"
                    response = "Music is Paused..."
                elif "skip" in stat or "next" in stat:
                    stat = "skip"
                    response = "Skipping..."
                elif "play" in stat and "stop" not in stat:
                    stat = "Playing"
                    response = "Now Playing..."
                elif "close" in stat or "stop" in stat:
                    stat = "close"
                    response = "Closing Music Player..."
                else:
                    stat = ""

                if stat:
                    mp.player_status(stat)
                    return f'{choice(self._get_commands("acknowledge response"))} {response}'

        except Exception:
            self.Log("Music Setting Error.")
        return response
Пример #2
0
    def play_music(self, voice_data):
        songWasFound = False
        option = '"play all"'
        shuffle = "True"
        mode = "compact"
        title = "none"
        artist = "none"
        genre = "none"
        response = ""

        try:
            import sys
            sys.path.append(self.UTILS_DIR)
            from musicplayer import MusicPlayer
            mp = MusicPlayer()

            # change the directory to location of batch file to execute
            os.chdir(self.UTILS_DIR)

            music_word_found = True if is_match(
                voice_data, ["music", "songs"]) else False
            meta_data = voice_data.lower().replace("&", "and").replace(
                "music", "").replace("songs", "").strip()

            if meta_data == "":
                # mode = "compact"
                alternate_responses = self._get_commands("acknowledge response")
                response = f"{choice(alternate_responses)} Playing all songs{', shuffled' if shuffle == 'True' else '...'}"
                songWasFound = True

            elif meta_data and "by" in meta_data.split(" ") and meta_data.find("by") > 0 and len(meta_data.split()) >= 3:
                option = '"play by"'

                by_idx = meta_data.find("by")
                title = meta_data[:(by_idx - 1)].strip().capitalize()
                artist = meta_data[(by_idx + 3):].strip().capitalize()

                if mp.search_song_by(title, artist, title):
                    songWasFound = True
                    artist = f'"{artist}"'
                    genre = title

                    alternate_responses = self._get_commands("acknowledge response")
                    response = f"{choice(alternate_responses)} Playing \"{title}\" by {artist}..."
                else:
                    response = f"I couldn't find \"{title}\" in your music."

            elif meta_data:
                option = '"play by"'
                title = f'"{meta_data}"'
                artist = f'"{meta_data}"'
                genre = f'"{meta_data}"'

                mp.title = meta_data
                mp.artist = meta_data
                mp.genre = meta_data

                if mp.search_song_by(meta_data, meta_data, meta_data):
                    songWasFound = True
                    alternate_responses = self._get_commands("acknowledge response")
                    response = f"{choice(alternate_responses)} Now playing \"{meta_data.capitalize()}\" {'music...' if music_word_found else '...'}"
                else:
                    response = f"I couldn't find \"{meta_data.capitalize()}\" in your music."

            if songWasFound:
                mp.player_status("close")
                # batch file to play some music in new window
                os.system(
                    f'start cmd /k "play_some_music.bat {option} {shuffle} {mode} {title} {artist} {genre}"')

            # get back to virtual assistant directory
            os.chdir(self.ASSISTANT_DIR)

            return response

        except Exception:
            self.Log("Play Music Skill Error.")