Skip to content

Commit

Permalink
Fixed youtube plugin!
Browse files Browse the repository at this point in the history
  • Loading branch information
DuckBoss committed Jun 10, 2020
1 parent 0e8cd97 commit 1c4e197
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
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 1c4e197

Please sign in to comment.