From 80ba94a9c533e410341708fb0b2eca9d96ed7921 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jason=20=5B=EC=A0=9C=EC=9D=B4=EC=8A=A8=20=EC=A0=9C?= =?UTF-8?q?=EB=A1=AC=5D?= <20238115+DuckBoss@users.noreply.github.com> Date: Wed, 10 Jun 2020 12:48:35 -0400 Subject: [PATCH 1/3] Implemented experimental !sbskip command to sound_board plugin --- .../extensions/sound_board/metadata.ini | 1 + .../extensions/sound_board/privileges.csv | 1 + .../extensions/sound_board/sound_board.py | 24 ++++++++++++++++++- .../sound_board/utility/settings.py | 2 ++ .../utility/sound_board_utility.py | 16 ++++++++++--- 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/JJMumbleBot/plugins/extensions/sound_board/metadata.ini b/JJMumbleBot/plugins/extensions/sound_board/metadata.ini index f5985768..f26e98cf 100644 --- a/JJMumbleBot/plugins/extensions/sound_board/metadata.ini +++ b/JJMumbleBot/plugins/extensions/sound_board/metadata.ini @@ -6,6 +6,7 @@ PluginLanguage = EN PluginCommands: [ "sb", "sbloop", + "sbskip", "sbvolume", "sblist", "sblist_echo", diff --git a/JJMumbleBot/plugins/extensions/sound_board/privileges.csv b/JJMumbleBot/plugins/extensions/sound_board/privileges.csv index fc3765e6..f152dcb5 100644 --- a/JJMumbleBot/plugins/extensions/sound_board/privileges.csv +++ b/JJMumbleBot/plugins/extensions/sound_board/privileges.csv @@ -3,6 +3,7 @@ sb,2 sbvolume,3 sbrandom,3 sbloop,3 +sbskip,3 sblist,2 sblist_echo,3 sbplaying,2 diff --git a/JJMumbleBot/plugins/extensions/sound_board/sound_board.py b/JJMumbleBot/plugins/extensions/sound_board/sound_board.py index eea91380..b44e177f 100644 --- a/JJMumbleBot/plugins/extensions/sound_board/sound_board.py +++ b/JJMumbleBot/plugins/extensions/sound_board/sound_board.py @@ -197,6 +197,7 @@ def process(self, text): box_align='left') return False sbu_settings.current_track = random_sfx + sbu_settings.loop_clip = False sbu.play_audio() elif command == "sb": @@ -224,6 +225,7 @@ def process(self, text): box_align='left') return False sbu_settings.current_track = parameter + sbu_settings.loop_clip = False sbu.play_audio() elif command == "sbloop": @@ -251,4 +253,24 @@ def process(self, text): box_align='left') return False sbu_settings.current_track = parameter - sbu.play_audio(loop=True) \ No newline at end of file + sbu_settings.loop_clip = True + sbu.play_audio() + + elif command == "sbskip": + if not privileges.plugin_privilege_checker(text, command, self.plugin_name): + return + if len(message_parse) < 2: + return + if GS.audio_dni[1] == self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME] and GS.audio_dni[0] is True: + if not sbu_settings.loop_clip: + try: + seconds_to_skip = int(message_parse[1]) + sbu_settings.skip_to = seconds_to_skip + sbu.play_audio() + except ValueError: + return + else: + GS.gui_service.quick_gui( + "The skip feature is currently unavailable when looping clips.", + text_type='header', + box_align='left') diff --git a/JJMumbleBot/plugins/extensions/sound_board/utility/settings.py b/JJMumbleBot/plugins/extensions/sound_board/utility/settings.py index c856d234..67208ecc 100644 --- a/JJMumbleBot/plugins/extensions/sound_board/utility/settings.py +++ b/JJMumbleBot/plugins/extensions/sound_board/utility/settings.py @@ -1,6 +1,8 @@ exit_flag = False current_track = None is_playing = False +loop_clip = False +skip_to = 0 sound_board_metadata = None # default volume volume = 0.5 diff --git a/JJMumbleBot/plugins/extensions/sound_board/utility/sound_board_utility.py b/JJMumbleBot/plugins/extensions/sound_board/utility/sound_board_utility.py index 912e4857..77989330 100644 --- a/JJMumbleBot/plugins/extensions/sound_board/utility/sound_board_utility.py +++ b/JJMumbleBot/plugins/extensions/sound_board/utility/sound_board_utility.py @@ -33,6 +33,8 @@ def stop_audio(): global_settings.audio_inst.kill() global_settings.audio_inst = None settings.current_track = None + settings.loop_clip = False + settings.skip_to = 0 global_settings.audio_dni = (False, None) return True return False @@ -93,7 +95,7 @@ def clear_audio_thread(): return False -def play_audio(loop=False): +def play_audio(): global_settings.audio_dni = (True, settings.sound_board_metadata[C_PLUGIN_INFO][P_PLUGIN_NAME]) global_settings.mumble_inst.sound_output.clear_buffer() @@ -110,18 +112,26 @@ def play_audio(loop=False): use_stereo = global_settings.cfg.getboolean(C_MAIN_SETTINGS, P_AUD_STEREO) if use_stereo: global_settings.audio_inst = sp.Popen( - [command, uri] + ['-I', 'dummy', f'{"--quiet" if settings.sound_board_metadata.getboolean(C_PLUGIN_SETTINGS, P_VLC_QUIET, fallback=True) else ""}', '--one-instance', f'{"--no-repeat" if loop is False else "--repeat"}', '--sout', + [command, uri] + ['-I', 'dummy', f'{"--quiet" if settings.sound_board_metadata.getboolean(C_PLUGIN_SETTINGS, P_VLC_QUIET, fallback=True) else ""}', + '--one-instance', f'{"--no-repeat" if settings.loop_clip is False else "--repeat"}', + f'--start-time={settings.skip_to if settings.loop_clip is False else 0}', + '--sout', '#transcode{acodec=s16le, channels=2, samplerate=48000, ' 'ab=128, threads=8}:std{access=file, mux=wav, dst=-}', 'vlc://quit'], stdout=sp.PIPE, bufsize=1024) + settings.skip_to = 0 else: global_settings.audio_inst = sp.Popen( - [command, uri] + ['-I', 'dummy', f'{"--quiet" if settings.sound_board_metadata.getboolean(C_PLUGIN_SETTINGS, P_VLC_QUIET, fallback=True) else ""}', '--one-instance', f'{"--no-repeat" if loop is False else "--repeat"}', '--sout', + [command, uri] + ['-I', 'dummy', f'{"--quiet" if settings.sound_board_metadata.getboolean(C_PLUGIN_SETTINGS, P_VLC_QUIET, fallback=True) else ""}', + '--one-instance', f'{"--no-repeat" if settings.loop_clip is False else "--repeat"}', + f'--start-time={settings.skip_to if settings.loop_clip is False else 0}', + '--sout', '#transcode{acodec=s16le, channels=2, samplerate=24000, ' 'ab=128, threads=8}:std{access=file, mux=wav, dst=-}', 'vlc://quit'], stdout=sp.PIPE, bufsize=1024) + settings.skip_to = 0 runtime_utils.unmute() while not settings.exit_flag and global_settings.audio_inst and settings.is_playing: From 0e8cd97f3fc4ba4d75267ee07b35ffb78112a4ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jason=20=5B=EC=A0=9C=EC=9D=B4=EC=8A=A8=20=EC=A0=9C?= =?UTF-8?q?=EB=A1=AC=5D?= <20238115+DuckBoss@users.noreply.github.com> Date: Wed, 10 Jun 2020 13:13:52 -0400 Subject: [PATCH 2/3] Added !sbskip command to help html file --- JJMumbleBot/plugins/extensions/sound_board/help.html | 1 + 1 file changed, 1 insertion(+) diff --git a/JJMumbleBot/plugins/extensions/sound_board/help.html b/JJMumbleBot/plugins/extensions/sound_board/help.html index a2ea7af6..25f180aa 100644 --- a/JJMumbleBot/plugins/extensions/sound_board/help.html +++ b/JJMumbleBot/plugins/extensions/sound_board/help.html @@ -1,6 +1,7 @@ All commands can be run by typing it in the channel or privately messaging JJMumbleBot.
!sb 'file_name': Plays a locally saved wav file.
!sbloop 'file_name': Plays a locally saved wav file, but endlessly loops until it is stopped.
+!sbskip 'seconds': Skips the current track by the given amount of seconds.
!sbrandom: Plays a random sound clip from the list of available clips.
!sbvolume '0..1': Sets the sound board audio volume.
!sblist/!sbl: Displays all the available sound board tracks in private messages.
From 1c4e197f6d8f83ef707297d68257cd0e6e8e894d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jason=20=5B=EC=A0=9C=EC=9D=B4=EC=8A=A8=20=EC=A0=9C?= =?UTF-8?q?=EB=A1=AC=5D?= <20238115+DuckBoss@users.noreply.github.com> Date: Wed, 10 Jun 2020 14:37:39 -0400 Subject: [PATCH 3/3] Fixed youtube plugin! --- .../youtube/utility/youtube_helper.py | 32 ++++++++++++------- .../plugins/extensions/youtube/youtube.py | 23 ++++--------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/JJMumbleBot/plugins/extensions/youtube/utility/youtube_helper.py b/JJMumbleBot/plugins/extensions/youtube/utility/youtube_helper.py index 40ba6cb9..4d3018cf 100644 --- a/JJMumbleBot/plugins/extensions/youtube/utility/youtube_helper.py +++ b/JJMumbleBot/plugins/extensions/youtube/utility/youtube_helper.py @@ -160,7 +160,7 @@ def download_next(): else: return if os.path.isfile(f"{dir_utils.get_temp_med_dir()}/youtube/{queue_list[-1]['img_id']}.jpg"): - # print("Thumbnail exists...skipping") + dprint(f"Thumbnail exists for {queue_list[-1]['img_id']}.jpg...skipping") return try: with youtube_dl.YoutubeDL(YoutubeHelper.ydl_opts) as ydl: @@ -168,14 +168,14 @@ def download_next(): # if video['duration'] >= YoutubeHelper.max_track_duration or video['duration'] <= 0.1: # debug_print("Video length exceeds limit...skipping.") # YoutubeHelper.queue_instance.pop() - except youtube_dl.utils.DownloadError: + except youtube_dl.utils.DownloadError as e: + dprint(e) return return def download_specific(index): queue_list = list(YoutubeHelper.queue_instance.queue_storage) - youtube_url = None if len(queue_list) > 0: youtube_url = queue_list[index]['main_url'] else: @@ -278,6 +278,7 @@ def stop_current(): YoutubeHelper.current_song_info = None YoutubeHelper.current_song = None YoutubeHelper.is_playing = False + YoutubeHelper.loop_song = False def stop_audio(): @@ -289,6 +290,7 @@ def stop_audio(): YoutubeHelper.current_song_info = None YoutubeHelper.current_song = None YoutubeHelper.is_playing = False + YoutubeHelper.loop_song = False GS.audio_dni = (False, None) @@ -352,10 +354,11 @@ def play_audio(): if GS.audio_inst is None: use_stereo = GS.cfg.getboolean(C_MAIN_SETTINGS, P_AUD_STEREO) - print(f"USE STEREO: {use_stereo}") + dprint(f"USE STEREO: {use_stereo}") if use_stereo: GS.audio_inst = sp.Popen( - [command, uri] + ['-I', 'dummy', f'{"--quiet" if YoutubeHelper.yt_metadata.getboolean(C_PLUGIN_SETTINGS, P_YT_VLC_QUIET, fallback=True) else ""}', '--one-instance', f'{"--no-repeat" if YoutubeHelper.loop_song is False else "--repeat"}', '--sout', + [command, uri] + ['-I', 'dummy', f'{"--quiet" if YoutubeHelper.yt_metadata.getboolean(C_PLUGIN_SETTINGS, P_YT_VLC_QUIET, fallback=True) else ""}', + '--one-instance', f'{"--no-repeat" if YoutubeHelper.loop_song is False else "--repeat"}', '--sout', '#transcode{acodec=s16le, channels=2, ' 'samplerate=48000, ab=192, threads=8}:std{access=file, ' 'mux=wav, dst=-}', @@ -363,7 +366,8 @@ def play_audio(): stdout=sp.PIPE, bufsize=1024) else: GS.audio_inst = sp.Popen( - [command, uri] + ['-I', 'dummy', f'{"--quiet" if YoutubeHelper.yt_metadata.getboolean(C_PLUGIN_SETTINGS, P_YT_VLC_QUIET, fallback=True) else ""}', '--one-instance', f'{"--no-repeat" if YoutubeHelper.loop_song is False else "--repeat"}', '--sout', + [command, uri] + ['-I', 'dummy', f'{"--quiet" if YoutubeHelper.yt_metadata.getboolean(C_PLUGIN_SETTINGS, P_YT_VLC_QUIET, fallback=True) else ""}', + '--one-instance', f'{"--no-repeat" if YoutubeHelper.loop_song is False else "--repeat"}', '--sout', '#transcode{acodec=s16le, channels=2, ' 'samplerate=24000, ab=192, threads=8}:std{access=file, ' 'mux=wav, dst=-}', @@ -372,12 +376,16 @@ def play_audio(): # YoutubeHelper.music_thread.wait() YoutubeHelper.is_playing = True runtime_utils.unmute() - - GS.gui_service.quick_gui_img(f"{dir_utils.get_temp_med_dir()}/youtube", - f"{YoutubeHelper.current_song_info['img_id']}", - caption=f"Now playing: {YoutubeHelper.current_song_info['main_title']}", - format_img=True, - img_size=32768) + try: + GS.gui_service.quick_gui_img(f"{dir_utils.get_temp_med_dir()}/youtube", + f"{YoutubeHelper.current_song_info['img_id']}", + caption=f"Now playing: {YoutubeHelper.current_song_info['main_title']}", + format_img=True, + img_size=32768) + except FileNotFoundError: + GS.gui_service.quick_gui(f"Thumbnail Image Unavailable
Now playing: {YoutubeHelper.current_song_info['img_id']}", + text_type='header', + box_align='left') while not YoutubeHelper.exit_flag and GS.mumble_inst.isAlive(): while GS.mumble_inst.sound_output.get_buffer_size() > 0.5 and not YoutubeHelper.exit_flag: diff --git a/JJMumbleBot/plugins/extensions/youtube/youtube.py b/JJMumbleBot/plugins/extensions/youtube/youtube.py index 3bb67369..0c978f2b 100644 --- a/JJMumbleBot/plugins/extensions/youtube/youtube.py +++ b/JJMumbleBot/plugins/extensions/youtube/youtube.py @@ -345,7 +345,7 @@ def process(self, text): text_type='header', box_align='left') return - song_data['main_url'] = stripped_url + # song_data['main_url'] = stripped_url # self.sound_board_plugin.clear_audio_thread() if not GS.audio_dni[0]: @@ -406,7 +406,7 @@ def process(self, text): text_type='header', box_align='left') return - song_data['main_url'] = stripped_url + # song_data['main_url'] = stripped_url # self.sound_board_plugin.clear_audio_thread() if not GS.audio_dni[0]: @@ -441,18 +441,11 @@ def process(self, text): return YH.loop_song = not YH.loop_song rprint( - f'{"Enabled" if YH.loop_song is True else "Disabled"} {self.plugin_name} loop mode.') + f'{"Enabled" if YH.loop_song is True else "Disabled"} {self.plugin_name} loop mode. {"The next track in the queue will start looping." if YH.loop_song else ""}') GS.gui_service.quick_gui( - f'{"Enabled" if YH.loop_song is True else "Disabled"} {self.plugin_name} loop mode.', + f'{"Enabled" if YH.loop_song is True else "Disabled"} {self.plugin_name} loop mode. {"The next track in the queue will start looping." if YH.loop_song else ""}', text_type='header', box_align='left') - if GS.audio_dni[1] == self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME] and GS.audio_dni[0] is True: - if GS.audio_inst is not None: - if YH.current_song is not None and YH.current_song_info is not None: - YH.queue_instance.insert_priority(YH.current_song_info) - YM.stop_audio() - YM.download_next() - YM.play_audio() elif command == "play": if not privileges.plugin_privilege_checker(text, command, self.plugin_name): @@ -487,7 +480,7 @@ def process(self, text): text_type='header', box_align='left') return - song_data['main_url'] = "https://www.youtube.com" + YH.all_searches[0]['href'] + # song_data['main_url'] = "https://www.youtube.com" + YH.all_searches[0]['href'] GS.gui_service.quick_gui( f"Automatically chosen: {YH.all_searches[0]['title']}", text_type='header', @@ -507,8 +500,7 @@ def process(self, text): text_type='header', box_align='left') return - song_data['main_url'] = "https://www.youtube.com" + YH.all_searches[int(all_messages[1])][ - 'href'] + # song_data['main_url'] = "https://www.youtube.com" + YH.all_searches[int(all_messages[1])]['href'] GS.gui_service.quick_gui( f"You've chosen: {YH.all_searches[int(all_messages[1])]['title']}", text_type='header', @@ -535,8 +527,7 @@ def process(self, text): text_type='header', box_align='left') return - song_data['main_url'] = "https://www.youtube.com" + YH.all_searches[int(all_messages[1])][ - 'href'] + #song_data['main_url'] = "https://www.youtube.com" + YH.all_searches[int(all_messages[1])]['href'] GS.gui_service.quick_gui( f"You've chosen: {YH.all_searches[int(all_messages[1])]['title']}", text_type='header',