Skip to content

Commit

Permalink
Merge pull request #214 from DuckBoss/experimental-sbskip-command-sou…
Browse files Browse the repository at this point in the history
…nd_board_plugin

Experimental !sbskip command sound board plugin
  • Loading branch information
Jason [제이슨 제롬] authored Jun 10, 2020
2 parents 2406a31 + 1c4e197 commit 78681f3
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 32 deletions.
1 change: 1 addition & 0 deletions JJMumbleBot/plugins/extensions/sound_board/help.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
All commands can be run by typing it in the channel or privately messaging JJMumbleBot.<br>
<b>!sb 'file_name'</b>: Plays a locally saved wav file.<br>
<b>!sbloop 'file_name'</b>: Plays a locally saved wav file, but endlessly loops until it is stopped.<br>
<b>!sbskip 'seconds'</b>: Skips the current track by the given amount of seconds.<br>
<b>!sbrandom</b>: Plays a random sound clip from the list of available clips.<br>
<b>!sbvolume '0..1'</b>: Sets the sound board audio volume.<br>
<b>!sblist/!sbl</b>: Displays all the available sound board tracks in private messages.<br>
Expand Down
1 change: 1 addition & 0 deletions JJMumbleBot/plugins/extensions/sound_board/metadata.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PluginLanguage = EN
PluginCommands: [
"sb",
"sbloop",
"sbskip",
"sbvolume",
"sblist",
"sblist_echo",
Expand Down
1 change: 1 addition & 0 deletions JJMumbleBot/plugins/extensions/sound_board/privileges.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ sb,2
sbvolume,3
sbrandom,3
sbloop,3
sbskip,3
sblist,2
sblist_echo,3
sbplaying,2
Expand Down
24 changes: 23 additions & 1 deletion JJMumbleBot/plugins/extensions/sound_board/sound_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -251,4 +253,24 @@ def process(self, text):
box_align='left')
return False
sbu_settings.current_track = parameter
sbu.play_audio(loop=True)
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')
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand All @@ -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:
Expand Down
32 changes: 20 additions & 12 deletions JJMumbleBot/plugins/extensions/youtube/utility/youtube_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,22 @@ 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:
ydl.extract_info(youtube_url, download=True)
# 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:
Expand Down Expand Up @@ -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():
Expand All @@ -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)


Expand Down Expand Up @@ -352,18 +354,20 @@ 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=-}',
'vlc://quit'],
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=-}',
Expand All @@ -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<br>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:
Expand Down
23 changes: 7 additions & 16 deletions JJMumbleBot/plugins/extensions/youtube/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit 78681f3

Please sign in to comment.