示例#1
0
def on_next_track():
    if gs.aud_interface.status.get_track().track_type == TrackType.STREAM:
        # If the track is looping, there is no need to download the next track image.
        if gs.aud_interface.status.is_looping():
            # Get new set of metadata for the current track if it is looping
            # because the link may expire and cause an issue.
            cur_track = gs.aud_interface.get_track()
            song_data = get_video_info(cur_track.alt_uri)
            if song_data is None:
                return
            track_obj = TrackInfo(
                uri=song_data['main_url'],
                name=cur_track.name,
                sender=cur_track.sender,
                duration=str(timedelta(seconds=int(song_data['duration'])))
                if int(song_data['duration']) > 0 else -1,
                track_type=TrackType.STREAM,
                track_id=cur_track.track_id,
                alt_uri=cur_track.alt_uri,
                image_uri=cur_track.image_uri,
                quiet=False)
            gs.aud_interface.status.set_track(track_obj)
            return
        # If the queue is empty, there is no track image to download.
        if gs.aud_interface.status.get_queue_length() == 0:
            return

        download_thumbnail(gs.aud_interface.status.get_queue()[0])
        # Get the video metadata and fill in the information if the current track is missing metadata information.
        if gs.aud_interface.status.get_queue()[0].uri == '':
            if gs.aud_interface.status.get_queue()[0].alt_uri == '':
                return
            song_data = get_video_info(
                gs.aud_interface.status.get_queue()[0].alt_uri)
            if song_data is None:
                return
            track_obj = TrackInfo(
                uri=song_data['main_url'],
                name=gs.aud_interface.status.get_queue()[0].name,
                sender=gs.aud_interface.status.get_queue()[0].sender,
                duration=str(timedelta(seconds=int(song_data['duration'])))
                if int(song_data['duration']) > 0 else -1,
                track_type=TrackType.STREAM,
                track_id=gs.aud_interface.status.get_queue()[0].track_id,
                alt_uri=gs.aud_interface.status.get_queue()[0].alt_uri,
                image_uri=gs.aud_interface.status.get_queue()[0].image_uri,
                quiet=False)
            gs.aud_interface.status.set_track(track_obj)
            cur_track_hashed_img_uri = hex(
                crc32(str.encode(track_obj.track_id)) & 0xffffffff)
            gs.aud_interface.status[
                "img_uri_hashed"] = cur_track_hashed_img_uri
示例#2
0
 def cmd_ttsplayquiet(self, data):
     if gs.aud_interface.check_dni(self.plugin_name):
         gs.aud_interface.set_dni(
             self.plugin_name, self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME])
     else:
         return
     all_data = data.message.strip().split(' ', 1)
     to_play = all_data[1].strip()
     if not os.path.isfile(
             f"{dir_utils.get_perm_med_dir()}/{self.plugin_name}/{to_play}.oga"
     ):
         gs.gui_service.quick_gui(
             f"The text-to-speech clip '{to_play}.oga' does not exist.",
             text_type='header',
             box_align='left')
         if gs.aud_interface.get_track().name == '':
             gs.aud_interface.clear_dni()
         return
     track_obj = TrackInfo(
         uri=
         f'{dir_utils.get_perm_med_dir()}/{self.plugin_name}/{to_play}.oga',
         name=to_play,
         sender=gs.mumble_inst.users[data.actor]['name'],
         duration=None,
         track_type=TrackType.FILE,
         quiet=True)
     gs.aud_interface.enqueue_track(track_obj=track_obj,
                                    to_front=False,
                                    quiet=True)
     gs.aud_interface.play(audio_lib=AudioLibrary.FFMPEG, override=True)
示例#3
0
def on_play():
    if gs.aud_interface.status.get_track().track_type == TrackType.STREAM:
        cur_track = gs.aud_interface.get_track()
        download_thumbnail(cur_track)

        # Get the video metadata and fill in the information if the current track is missing metadata information.
        if cur_track.uri == '':
            if cur_track.alt_uri == '':
                return
            song_data = get_video_info(cur_track.alt_uri)
            if song_data is None:
                return
            track_obj = TrackInfo(
                uri=song_data['main_url'],
                name=cur_track.name,
                sender=cur_track.sender,
                duration=int(song_data['duration']),
                track_type=TrackType.STREAM,
                track_id=cur_track.track_id,
                alt_uri=cur_track.alt_uri,
                image_uri=cur_track.image_uri,
                quiet=False
            )
            gs.aud_interface.status.set_track(track_obj)
            cur_track_hashed_img_uri = hex(crc32(str.encode(track_obj.track_id)) & 0xffffffff)
            gs.aud_interface.status["img_uri_hashed"] = cur_track_hashed_img_uri
示例#4
0
    def cmd_sbnow(self, data):
        all_data = data.message.strip().split()
        if len(all_data) < 2:
            return

        if gs.aud_interface.check_dni(self.plugin_name):
            gs.aud_interface.set_dni(
                self.plugin_name, self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME])
        else:
            return

        sender = gs.mumble_inst.users[data.actor]['name']
        to_play = all_data[1].strip()
        audio_clip = sbu.find_file(to_play)
        if not audio_clip:
            gs.gui_service.quick_gui(
                f"The sound clip '{to_play}' does not exist.",
                text_type='header',
                box_align='left')
            gs.aud_interface.clear_dni()
            return
        track_obj = TrackInfo(
            uri=
            f'{dir_utils.get_perm_med_dir()}/{self.plugin_name}/{audio_clip}',
            alt_uri=
            f'{dir_utils.get_perm_med_dir()}/{self.plugin_name}/{audio_clip}',
            name=to_play,
            sender=sender,
            duration=None,
            track_type=TrackType.FILE,
            quiet=False)
        gs.aud_interface.enqueue_track(track_obj=track_obj,
                                       to_front=False,
                                       quiet=True)
        gs.aud_interface.play(audio_lib=AudioLibrary.FFMPEG, override=True)
示例#5
0
 def cmd_sbrandomquiet(self, data):
     if gs.aud_interface.check_dni(self.plugin_name):
         gs.aud_interface.set_dni(
             self.plugin_name, self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME])
     else:
         return
     sender = gs.mumble_inst.users[data.actor]['name']
     gather_list = sbu.prepare_sb_list(include_file_extensions=True)
     random.seed()
     random_sfx = random.choice(gather_list)
     track_obj = TrackInfo(
         uri=
         f'{dir_utils.get_perm_med_dir()}/{self.plugin_name}/{random_sfx}',
         name=random_sfx,
         sender=sender,
         duration=None,
         track_type=TrackType.FILE,
         quiet=True)
     gs.aud_interface.enqueue_track(track_obj=track_obj,
                                    to_front=False,
                                    quiet=True)
     gs.aud_interface.play(
         audio_lib=AudioLibrary.FFMPEG,
         override=not self.metadata.getboolean(
             C_PLUGIN_SETTINGS, P_ENABLE_QUEUE, fallback=False))
示例#6
0
    def clbk_user_connected(self, user):
        # Return if playing audio clips on user join is disabled.
        if not self.metadata.getboolean(
                C_PLUGIN_SET, P_PLAY_AUDIO_CLIP_ON_USER_JOIN, fallback=False):
            return

        if gs.aud_interface.check_dni(self.plugin_name, quiet=True):
            gs.aud_interface.set_dni(
                self.plugin_name, self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME])
        else:
            return

        to_play = None
        # If playing the same clip on user join is enabled, load the generic clip name.
        # Otherwise, load the clip name set to the user.
        if self.metadata.getboolean(C_PLUGIN_SET,
                                    P_PLAY_SAME_CLIP_ON_USER_JOIN,
                                    fallback=True):
            to_play = self.metadata[C_PLUGIN_SET][
                P_GENERIC_CLIP_TO_PLAY_ON_USER_JOIN]
        else:
            to_play = st_settings.user_connections.get(user[0]['name'])

        # If to_play doesn't exist, that means the user is not on the user_connections.csv file.
        # use the generic clip when the user isn't on the list.
        if not to_play:
            to_play = self.metadata[C_PLUGIN_SET][
                P_GENERIC_CLIP_TO_PLAY_ON_USER_JOIN]

        # If the clip is only allowed to play when other users are in the channel
        # and no users are present, clear DNI and return.
        if self.metadata.getboolean(C_PLUGIN_SET,
                                    P_PLAY_CLIP_ONLY_IF_USERS_IN_CHANNEL,
                                    fallback=True):
            if len(get_users_in_my_channel()) <= 1:
                gs.aud_interface.clear_dni()
                return

        # Find and load the clip, then play it.
        audio_clip = find_file(to_play)
        if not path.exists(
                f"{dir_utils.get_perm_med_dir()}/{sb_plugin_name}/{audio_clip}"
        ):
            gs.aud_interface.clear_dni()
            gs.gui_service.quick_gui(
                f"The audio clip: {to_play} could not be found.",
                text_type='header',
                box_align='left')
            return
        track_obj = TrackInfo(
            uri=f'{dir_utils.get_perm_med_dir()}/{sb_plugin_name}/{audio_clip}',
            name=to_play,
            sender=get_bot_name(),
            duration=None,
            track_type=TrackType.FILE,
            quiet=True)
        gs.aud_interface.enqueue_track(track_obj=track_obj,
                                       to_front=False,
                                       quiet=True)
        gs.aud_interface.play(audio_lib=AudioLibrary.FFMPEG, override=True)
示例#7
0
    def cmd_linkfront(self, data):
        if gs.aud_interface.check_dni(self.plugin_name):
            gs.aud_interface.set_dni(
                self.plugin_name, self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME])
        else:
            return

        all_data = data.message.strip().split(' ', 1)
        if len(all_data) != 2:
            gs.gui_service.quick_gui(
                f"Invalid formatting! Format: {get_command_token()}link 'link_url'",
                text_type='header',
                box_align='left')
            gs.aud_interface.clear_dni()
            return
        sender = gs.mumble_inst.users[data.actor]['name']
        stripped_url = BeautifulSoup(all_data[1],
                                     features='html.parser').get_text()
        if "youtube.com" in stripped_url or "youtu.be" in stripped_url or 'soundcloud' in stripped_url:
            if ("youtube.com" in stripped_url and "list" in stripped_url) or (
                    "soundcloud" in stripped_url and "sets" in stripped_url):
                gs.gui_service.quick_gui(
                    "The given link was identified as a playlist link!<br>Please use the playlist "
                    "command to add playlists to the queue!",
                    text_type='header',
                    box_align='left')
                gs.aud_interface.clear_dni()
                return

            song_data = md_utility.get_video_info(stripped_url)
            if song_data is None:
                gs.gui_service.quick_gui(
                    "The media track information could not be retrieved.",
                    text_type='header',
                    box_align='left')
                gs.aud_interface.clear_dni()
                return
            if int(song_data['duration']) > int(
                    self.metadata[C_PLUGIN_SETTINGS][P_YT_MAX_VID_LEN]):
                gs.gui_service.quick_gui(
                    f"The media track provided is longer than the maximum allowed video duration: [{str(timedelta(seconds=int(self.metadata[C_PLUGIN_SETTINGS][P_YT_MAX_VID_LEN])))}]",
                    text_type='header',
                    box_align='left')
                gs.aud_interface.clear_dni()
                return
            track_obj = TrackInfo(
                uri=song_data['main_url'],
                name=song_data['main_title'],
                sender=sender,
                duration=str(timedelta(seconds=int(song_data['duration'])))
                if int(song_data['duration']) > 0 else -1,
                track_type=TrackType.STREAM,
                track_id=song_data['main_id'],
                alt_uri=stripped_url,
                image_uri=
                f"{dir_utils.get_temp_med_dir()}/{self.plugin_name}/{song_data['main_id']}",
                quiet=False)
            gs.aud_interface.enqueue_track(track_obj=track_obj, to_front=True)
            gs.aud_interface.play(audio_lib=AudioLibrary.VLC)
示例#8
0
    def cmd_stream(self, data):
        if gs.aud_interface.check_dni(self.plugin_name):
            gs.aud_interface.set_dni(self.plugin_name, self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME])
        else:
            return

        all_data = data.message.strip().split(' ', 1)
        sender = gs.mumble_inst.users[data.actor]['name']
        stripped_url = BeautifulSoup(all_data[1], features='html.parser').get_text()

        if "youtube.com" in stripped_url or "youtu.be" in stripped_url:
            stream_data = self.get_stream_info(stripped_url, "bestaudio/best")
        elif "twitch.tv" in stripped_url:
            stream_data = self.get_stream_info(stripped_url, "audio_only")
        else:
            gs.gui_service.quick_gui(
                "Only twitch and youtube are supported at this time.",
                text_type='header',
                box_align='left')
            gs.aud_interface.clear_dni()
            return

        track_obj = TrackInfo(
            uri=stream_data['main_url'],
            name=stream_data['main_title'],
            sender=sender,
            track_type=TrackType.STREAM,
            quiet=False
        )

        gs.aud_interface.enqueue_track(
            track_obj=track_obj,
            to_front=True
        )

        if "twitch.tv" in stripped_url:
            gs.aud_interface.play(audio_lib=AudioLibrary.FFMPEG)
        else:
            gs.aud_interface.play(audio_lib=AudioLibrary.VLC)
示例#9
0
def song_integrity_check():
    # Get the video metadata and fill in the information if the current track is missing metadata information.
    cur_track = gs.aud_interface.status.get_track()
    if cur_track.uri == '':
        if cur_track.alt_uri == '':
            return
        song_data = get_video_info(cur_track.alt_uri)
        if song_data is None:
            return
        track_obj = TrackInfo(
            uri=song_data['main_url'],
            name=cur_track.name,
            sender=cur_track.sender,
            duration=str(timedelta(seconds=int(song_data['duration'])))
            if int(song_data['duration']) > 0 else -1,
            track_type=TrackType.STREAM,
            track_id=cur_track.track_id,
            alt_uri=cur_track.alt_uri,
            image_uri=cur_track.image_uri,
            quiet=False)
        gs.aud_interface.status.set_track(track_obj)
        cur_track_hashed_img_uri = hex(
            crc32(str.encode(track_obj.track_id)) & 0xffffffff)
        gs.aud_interface.status["img_uri_hashed"] = cur_track_hashed_img_uri
示例#10
0
    def cmd_tts(self, data):
        if gs.aud_interface.check_dni(self.plugin_name):
            gs.aud_interface.set_dni(
                self.plugin_name, self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME])
        else:
            return
        data_actor = gs.mumble_inst.users[data.actor]
        all_data = data.message.strip().split(' ', 2)

        if all_data[1].strip() in tts_settings.voice_list:
            all_data = data.message.strip().split(' ', 2)
        else:
            all_data = data.message.strip().split(' ', 1)

        if len(all_data) == 2:
            if len(all_data[1]) > int(
                    self.metadata[C_PLUGIN_SETTINGS][P_TTS_MSG_CHR_LIM]):
                gs.gui_service.quick_gui(
                    f"The text-to-speech message exceeded the character limit:"
                    f" [{self.metadata[C_PLUGIN_SETTINGS][P_TTS_MSG_CHR_LIM]}].",
                    text_type='header',
                    box_align='left',
                    user=data_actor['name'])
                return
            if ttsu.download_clip(
                    "_temp",
                    self.metadata[C_PLUGIN_SETTINGS][P_TTS_DEF_VOICE],
                    all_data[1].strip(),
                    directory=f'{dir_utils.get_temp_med_dir()}'):
                track_obj = TrackInfo(
                    uri=
                    f'{dir_utils.get_temp_med_dir()}/{self.plugin_name}/_temp.oga',
                    name='text-to-speech clip',
                    sender=gs.mumble_inst.users[data.actor]['name'],
                    duration=None,
                    track_type=TrackType.FILE,
                    quiet=True)
                gs.aud_interface.enqueue_track(track_obj=track_obj,
                                               to_front=False,
                                               quiet=True)
                gs.aud_interface.play(audio_lib=AudioLibrary.VLC,
                                      override=True)
        elif len(all_data) == 3:
            if len(all_data[1]) > int(
                    self.metadata[C_PLUGIN_SETTINGS][P_TTS_MSG_CHR_LIM]):
                gs.gui_service.quick_gui(
                    f"The text to speech message exceeded the character limit:"
                    f" [{self.metadata[C_PLUGIN_SETTINGS][P_TTS_MSG_CHR_LIM]}].",
                    text_type='header',
                    box_align='left',
                    user=data_actor['name'])
                return
            if ttsu.download_clip("_temp",
                                  all_data[1].strip(),
                                  all_data[2].strip(),
                                  directory=f'{dir_utils.get_temp_med_dir()}'):
                track_obj = TrackInfo(
                    uri=
                    f'{dir_utils.get_temp_med_dir()}/{self.plugin_name}/_temp.oga',
                    name='text-to-speech clip',
                    sender=gs.mumble_inst.users[data.actor]['name'],
                    duration=None,
                    track_type=TrackType.FILE,
                    quiet=True)
                gs.aud_interface.enqueue_track(track_obj=track_obj,
                                               to_front=False,
                                               quiet=True)
                gs.aud_interface.play(audio_lib=AudioLibrary.VLC,
                                      override=True)
        else:
            gs.gui_service.quick_gui(
                f"Incorrect Format:<br>{get_command_token()}tts 'voice_name' 'message'<br>OR<br>{get_command_token()}tts 'message'",
                text_type='header',
                box_align='left',
                user=data_actor['name'])
示例#11
0
    def cmd_ytplaylist(self, data):
        if gs.aud_interface.check_dni(self.plugin_name):
            gs.aud_interface.set_dni(
                self.plugin_name, self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME])
        else:
            return

        all_data = data.message.strip().split(' ', 1)
        if len(all_data) != 2:
            gs.gui_service.quick_gui(
                f"Invalid formatting! Format: {get_command_token()}ytplaylist 'youtube_playlist_link'",
                text_type='header',
                box_align='left')
            gs.aud_interface.clear_dni()
            return
        sender = gs.mumble_inst.users[data.actor]['name']
        stripped_url = BeautifulSoup(all_data[1],
                                     features='html.parser').get_text()

        check_url_request = requests.get(
            f'https://www.youtube.com/oembed?format=json&url={stripped_url}')
        if check_url_request.status_code == 200 and check_url_request.content != "Not Found":
            if "list" in check_url_request.json()['html']:
                all_song_data = md_utility.get_playlist_info(stripped_url)
                if all_song_data is None:
                    gs.gui_service.quick_gui(
                        "The youtube playlist information could not be retrieved.",
                        text_type='header',
                        box_align='left')
                    gs.aud_interface.clear_dni()
                    return

                for i, song_data in enumerate(all_song_data):
                    track_obj = TrackInfo(
                        uri=song_data['main_url'],
                        name=song_data['main_title'],
                        sender=sender,
                        duration=-1,
                        track_type=TrackType.STREAM,
                        track_id=song_data['main_id'],
                        alt_uri=song_data['std_url'],
                        image_uri=
                        f"{dir_utils.get_temp_med_dir()}/{self.plugin_name}/{song_data['main_id']}",
                        quiet=False)
                    gs.aud_interface.enqueue_track(track_obj=track_obj,
                                                   to_front=False,
                                                   quiet=True)
                gs.gui_service.quick_gui(
                    "The playlist was generated and added to the audio queue.",
                    text_type='header',
                    box_align='left')
                gs.aud_interface.play(audio_lib=AudioLibrary.VLC)
            else:
                gs.aud_interface.clear_dni()
                gs.gui_service.quick_gui(
                    "The given link was not a playlist.<br>Only use the !ytplaylist command for playlist links.",
                    text_type='header',
                    box_align='left')
        else:
            gs.aud_interface.clear_dni()
            gs.gui_service.quick_gui(
                "The given link was not identified as a Youtube playlist link!<br>SoundCloud playlists are not supported.",
                text_type='header',
                box_align='left')
示例#12
0
 def cmd_ytplay(self, data):
     if not gs.aud_interface.check_dni_active(
     ) or gs.aud_interface.check_dni_is_mine(self.plugin_name):
         all_data = data.message.strip().split()
         sender = gs.mumble_inst.users[data.actor]['name']
         if len(all_data) == 1:
             song_data = md_utility.get_video_info(
                 md_settings.search_results[0]['webpage_url'])
             if song_data is None:
                 gs.gui_service.quick_gui(
                     f"There was an error with the chosen video.",
                     text_type='header',
                     box_align='left')
                 return
             gs.gui_service.quick_gui(
                 f"Automatically chosen: {md_settings.search_results[0]['title']}",
                 text_type='header',
                 box_align='left')
             md_settings.can_play = False
             gs.aud_interface.set_dni(
                 self.plugin_name,
                 self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME])
             track_obj = TrackInfo(
                 uri=song_data['main_url'],
                 name=song_data['main_title'],
                 sender=sender,
                 duration=int(song_data['duration']),
                 track_type=TrackType.STREAM,
                 track_id=song_data['main_id'],
                 alt_uri=md_settings.search_results[0]['webpage_url'],
                 image_uri=
                 f"{dir_utils.get_temp_med_dir()}/{self.plugin_name}/{song_data['main_id']}",
                 quiet=False)
             gs.aud_interface.enqueue_track(track_obj=track_obj,
                                            to_front=False)
             md_settings.search_results = None
             gs.aud_interface.play(audio_lib=AudioLibrary.VLC)
         elif len(all_data) == 2:
             if int(self.metadata[C_PLUGIN_SETTINGS]
                    [P_YT_MAX_SEARCH_LEN]) >= int(all_data[1]) >= 0:
                 song_data = md_utility.get_video_info(
                     md_settings.search_results[int(
                         all_data[1])]['webpage_url'])
                 if song_data is None:
                     gs.gui_service.quick_gui(
                         f"There was an error with the chosen video.",
                         text_type='header',
                         box_align='left')
                     return
                 gs.gui_service.quick_gui(
                     f"You've chosen: {md_settings.search_results[int(all_data[1])]['title']}",
                     text_type='header',
                     box_align='left')
                 md_settings.can_play = False
             else:
                 gs.gui_service.quick_gui(
                     f"Invalid choice! Valid Range [0-{int(self.metadata[C_PLUGIN_SETTINGS][P_YT_MAX_SEARCH_LEN])}]",
                     text_type='header',
                     box_align='left')
                 md_settings.can_play = False
                 return
             gs.aud_interface.set_dni(
                 self.plugin_name,
                 self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME])
             track_obj = TrackInfo(
                 uri=song_data['main_url'],
                 name=song_data['main_title'],
                 sender=sender,
                 duration=int(song_data['duration']),
                 track_type=TrackType.STREAM,
                 track_id=song_data['main_id'],
                 alt_uri=md_settings.search_results[int(
                     all_data[1])]['webpage_url'],
                 image_uri=
                 f"{dir_utils.get_temp_med_dir()}/{self.plugin_name}/{song_data['main_id']}",
                 quiet=False)
             gs.aud_interface.enqueue_track(track_obj=track_obj,
                                            to_front=False)
             md_settings.search_results = None
             gs.aud_interface.play(audio_lib=AudioLibrary.VLC)
         else:
             md_settings.can_play = False
             md_settings.search_results = None
             log(ERROR,
                 CMD_INVALID_YTPLAY,
                 origin=L_COMMAND,
                 error_type=CMD_INVALID_ERR,
                 print_mode=PrintMode.VERBOSE_PRINT.value)
             gs.gui_service.quick_gui(CMD_INVALID_YTPLAY,
                                      text_type='header',
                                      box_align='left')
示例#13
0
    def clbk_user_connected(self, user):
        # Display the welcome message to the user if any.
        if self.metadata.getboolean(C_PLUGIN_SET,
                                    P_USE_WELCOME_MSG,
                                    fallback=False):
            if len(self.metadata[C_PLUGIN_SET][P_WELCOME_MSG]) > 0:
                gs.gui_service.quick_gui(
                    f"{self.metadata[C_PLUGIN_SET][P_WELCOME_MSG]}",
                    text_type='header',
                    box_align='left',
                    user=user[0]['name'])

        # Return if the user that connected is the bot (self-detection).
        if len(get_users_in_my_channel()) == 1:
            return

        # Return if playing audio clips on user join is disabled.
        if not self.metadata.getboolean(
                C_PLUGIN_SET, P_PLAY_AUDIO_CLIP_ON_USER_JOIN, fallback=False):
            return

        if gs.aud_interface.check_dni(self.plugin_name, quiet=True):
            gs.aud_interface.set_dni(
                self.plugin_name, self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME])
        else:
            return

        to_play = None
        # If playing the same clip on user join is enabled, load the generic clip name.
        # Otherwise, load the clip name set to the user.
        if self.metadata.getboolean(C_PLUGIN_SET,
                                    P_PLAY_SAME_CLIP_ON_USER_JOIN,
                                    fallback=True):
            to_play = self.metadata[C_PLUGIN_SET][
                P_GENERIC_CLIP_TO_PLAY_ON_USER_JOIN]
        else:
            to_play = st_settings.user_connections.get(user[0]['name'])

        # If to_play doesn't exist, that means the user is not on the user_connections.csv file.
        # use the built-in clip when the user isn't on the list.
        if not to_play:
            to_play = self.metadata[C_PLUGIN_SET][
                P_GENERIC_CLIP_TO_PLAY_ON_USER_JOIN]

        # If the clip is only allowed to play when other users are in the channel
        # and no users are present, clear DNI and return.
        if self.metadata.getboolean(C_PLUGIN_SET,
                                    P_PLAY_CLIP_ONLY_IF_USERS_IN_CHANNEL,
                                    fallback=True):
            if len(get_users_in_my_channel()) <= 1:
                gs.aud_interface.clear_dni()
                return

        # Find and load the clip, then play it.
        audio_clip = find_file(to_play)
        if not audio_clip:
            if not self.metadata.getboolean(
                    C_PLUGIN_SET, P_USE_BUILT_IN_CLIP, fallback=True):
                gs.aud_interface.clear_dni()
                log(ERROR,
                    f"The audio clip: {to_play} for the user connection sound could not be found.",
                    origin=L_COMMAND,
                    error_type=CMD_PROCESS_ERR,
                    print_mode=PrintMode.VERBOSE_PRINT.value)
                gs.gui_service.quick_gui(
                    f"The audio clip: {to_play} for the user connection sound could not be found.",
                    text_type='header',
                    box_align='left')
                return
            track_obj = TrackInfo(
                uri=
                f'{dir_utils.get_core_plugin_dir()}/server_tools/resources/default_user_sound.wav',
                alt_uri=
                f'{dir_utils.get_core_plugin_dir()}/server_tools/resources/default_user_sound.wav',
                name='default_user_sound.wav',
                sender=get_bot_name(),
                duration=None,
                track_type=TrackType.FILE,
                quiet=True)
        else:
            # If the plugin is set to use sound board clips, retrieve the clip from the sound board media directory.
            if self.metadata.getboolean(C_PLUGIN_SET,
                                        P_USE_SOUNDBOARD_CLIPS,
                                        fallback=True):
                track_obj = TrackInfo(
                    uri=
                    f'{dir_utils.get_perm_med_dir()}/sound_board/{audio_clip}',
                    alt_uri=
                    f'{dir_utils.get_perm_med_dir()}/sound_board/{audio_clip}',
                    name=to_play,
                    sender=get_bot_name(),
                    duration=None,
                    track_type=TrackType.FILE,
                    quiet=True)
            else:
                # Otherwise, retrieve the clip from the server tools plugin media directory.
                track_obj = TrackInfo(
                    uri=
                    f'{dir_utils.get_perm_med_dir()}/{self.plugin_name}/{audio_clip}',
                    alt_uri=
                    f'{dir_utils.get_perm_med_dir()}/{self.plugin_name}/{audio_clip}',
                    name=to_play,
                    sender=get_bot_name(),
                    duration=None,
                    track_type=TrackType.FILE,
                    quiet=True)
        gs.aud_interface.enqueue_track(track_obj=track_obj,
                                       to_front=False,
                                       quiet=True)
        gs.aud_interface.play(audio_lib=AudioLibrary.FFMPEG, override=True)
示例#14
0
 def cmd_ytplay(self, data):
     if not gs.aud_interface.check_dni_active(
     ) or gs.aud_interface.check_dni_is_mine(self.plugin_name):
         all_data = data.message.strip().split()
         sender = gs.mumble_inst.users[data.actor]['name']
         if len(all_data) == 1:
             song_data = md_utility.get_video_info(
                 f"https://www.youtube.com{md_settings.search_results[0]['href']}"
             )
             if song_data is None:
                 gs.gui_service.quick_gui(
                     f"There was an error with the chosen video.",
                     text_type='header',
                     box_align='left')
                 return
             gs.gui_service.quick_gui(
                 f"Automatically chosen: {md_settings.search_results[0]['title']}",
                 text_type='header',
                 box_align='left')
             md_settings.can_play = False
             gs.aud_interface.set_dni(
                 self.plugin_name,
                 self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME])
             track_obj = TrackInfo(
                 uri=song_data['main_url'],
                 name=song_data['main_title'],
                 sender=sender,
                 duration=str(timedelta(seconds=int(song_data['duration'])))
                 if int(song_data['duration']) > 0 else -1,
                 track_type=TrackType.STREAM,
                 track_id=song_data['main_id'],
                 alt_uri=
                 f"https://www.youtube.com{md_settings.search_results[0]['href']}",
                 image_uri=
                 f"{dir_utils.get_temp_med_dir()}/{self.plugin_name}/{song_data['main_id']}",
                 quiet=False)
             gs.aud_interface.enqueue_track(track_obj=track_obj,
                                            to_front=False)
             md_settings.search_results = None
             gs.aud_interface.play(audio_lib=AudioLibrary.VLC)
         elif len(all_data) == 2:
             if int(self.metadata[C_PLUGIN_SETTINGS]
                    [P_YT_MAX_SEARCH_LEN]) >= int(all_data[1]) >= 0:
                 song_data = md_utility.get_video_info(
                     f"https://www.youtube.com{md_settings.search_results[int(all_data[1])]['href']}"
                 )
                 if song_data is None:
                     gs.gui_service.quick_gui(
                         f"There was an error with the chosen video.",
                         text_type='header',
                         box_align='left')
                     return
                 gs.gui_service.quick_gui(
                     f"You've chosen: {md_settings.search_results[int(all_data[1])]['title']}",
                     text_type='header',
                     box_align='left')
                 md_settings.can_play = False
             else:
                 gs.gui_service.quick_gui(
                     f"Invalid choice! Valid Range [0-{int(self.metadata[C_PLUGIN_SETTINGS][P_YT_MAX_SEARCH_LEN])}]",
                     text_type='header',
                     box_align='left')
                 md_settings.can_play = False
                 return
             gs.aud_interface.set_dni(
                 self.plugin_name,
                 self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME])
             track_obj = TrackInfo(
                 uri=song_data['main_url'],
                 name=song_data['main_title'],
                 sender=sender,
                 duration=str(timedelta(seconds=int(song_data['duration'])))
                 if int(song_data['duration']) > 0 else -1,
                 track_type=TrackType.STREAM,
                 track_id=song_data['main_id'],
                 alt_uri=
                 f"https://www.youtube.com{md_settings.search_results[int(all_data[1])]['href']}",
                 image_uri=
                 f"{dir_utils.get_temp_med_dir()}/{self.plugin_name}/{song_data['main_id']}",
                 quiet=False)
             gs.aud_interface.enqueue_track(track_obj=track_obj,
                                            to_front=False)
             md_settings.search_results = None
             gs.aud_interface.play(audio_lib=AudioLibrary.VLC)
         else:
             md_settings.can_play = False
             md_settings.search_results = None
             gs.gui_service.quick_gui(
                 f"Invalid formatting! Format: {get_command_token()}ytplay 'track_number'",
                 text_type='header',
                 box_align='left')