@@ -884,7 +884,9 @@ def __init__(self, options, interaction, music_queue):
884
884
async def callback (self , interaction : discord .Interaction ):
885
885
interaction .response .defer ()
886
886
selected_option = self .values [0 ]
887
- song_info = await asyncio .to_thread (YouTube .get_song_info , {"link" : selected_option })
887
+ song_info = await YouTube .get_song_info (selected_option )
888
+ if song_info is None :
889
+ return await interaction .followup .send ("❌ This is not a valid YouTube video link." )
888
890
song = (song_info ['url' ], f"📺 { song_info ['title' ]} " , song_info ['duration' ] * 1000 , song_info )
889
891
await play_song (self .interaction , * song , send_message = True , music_queue = self .music_queue , play_called = False )
890
892
@@ -920,10 +922,10 @@ async def get_raw_url(url):
920
922
return None
921
923
922
924
@staticmethod
923
- def get_song_info (entry ):
925
+ async def get_song_info (entry ):
924
926
with yt_dlp .YoutubeDL (YouTube .ydl_opts ) as ydl :
925
927
try :
926
- info_dict = ydl .extract_info (entry [ "link" ] , download = False )
928
+ info_dict = ydl .extract_info (entry , download = False )
927
929
yt_thumbnail = "https://images.freeimages.com/fic/images/icons/820/simply_google/256/google_youtube.png"
928
930
return {'title' : info_dict ['title' ], 'duration' : info_dict ['duration' ], 'thumbnail' : info_dict .get ('thumbnail' , 'yt_thumbnail' ), 'url' : info_dict ['url' ]}
929
931
except Exception as e :
@@ -968,6 +970,8 @@ async def youtube(interaction: discord.Interaction, search: str = None, video_ur
968
970
if raw_url is None :
969
971
return await interaction .followup .send ("❌ This is not a valid YouTube video link." )
970
972
song_info = await YouTube .get_song_info (video_url )
973
+ if song_info is None :
974
+ return await interaction .followup .send ("❌ This is not a valid YouTube video link." )
971
975
song = (raw_url , f"📺 { song_info ['title' ]} " , song_info ['duration' ] * 1000 , song_info )
972
976
await play_song (interaction , * song , send_message = True , music_queue = music_queue , play_called = False )
973
977
elif playlist_url :
@@ -980,6 +984,7 @@ async def youtube(interaction: discord.Interaction, search: str = None, video_ur
980
984
if playlist_entries :
981
985
# Process and add songs in the playlist in the background
982
986
bot .loop .create_task (process_playlist (interaction , playlist_entries , music_queue ))
987
+ # Add a placeholder song to the queue
983
988
placeholder_song = ("placeholder" , f"📺 Playlist: { playlist ['info' ]['title' ]} ({ total_songs } songs)" , 0 , {})
984
989
print (f"{ playlist ['info' ]['title' ]} " )
985
990
await music_queue .add_song (placeholder_song )
@@ -992,7 +997,7 @@ async def youtube(interaction: discord.Interaction, search: str = None, video_ur
992
997
993
998
async def process_playlist (interaction , playlist_entries , music_queue ):
994
999
for entry in playlist_entries :
995
- song_info = await asyncio . to_thread ( YouTube .get_song_info , entry )
1000
+ song_info = await YouTube .get_song_info ( entry [ 'link' ] )
996
1001
if song_info is None :
997
1002
await interaction .channel .send (f"❌ Error extracting audio from video { entry ['link' ]} . Skipping." )
998
1003
continue
@@ -1009,6 +1014,8 @@ async def process_playlist(interaction, playlist_entries, music_queue):
1009
1014
1010
1015
1011
1016
1017
+
1018
+
1012
1019
commands = {
1013
1020
"play" : "Play a song or playlist. Usage: /play <song/playlist name>" ,
1014
1021
"playlist" : "Toggle loop mode. Usage: /playlist" ,
@@ -1042,7 +1049,4 @@ async def help(interaction: discord.Interaction, command: str = None):
1042
1049
1043
1050
1044
1051
1045
-
1046
-
1047
-
1048
- bot .run (TOKEN )
1052
+ bot .run (TOKEN )
0 commit comments