From cd554a9512f7b9e87a06e1f2edecc575b576af1a Mon Sep 17 00:00:00 2001 From: Kaya <95276965+kytpbs@users.noreply.github.com> Date: Thu, 18 Jul 2024 22:13:19 +0300 Subject: [PATCH] update file_path of music system Now It also gets downloaded into the "downloads/youtube" folder --- src/file_handeler.py | 3 +++ src/voice_commands.py | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/file_handeler.py b/src/file_handeler.py index 41037c8..f6a0d38 100644 --- a/src/file_handeler.py +++ b/src/file_handeler.py @@ -68,3 +68,6 @@ async def delete_saved_attachments(): onerror=logger.error, ) logger.debug("Deleted saved attachments") + +def get_file_path_of_video(video_id: str) -> str: + return os.path.join("downloads", "youtube", video_id + ".mp3") diff --git a/src/voice_commands.py b/src/voice_commands.py index 8161c8a..052a0e7 100644 --- a/src/voice_commands.py +++ b/src/voice_commands.py @@ -8,6 +8,7 @@ import yt_dlp from Constants import CYAN, KYTPBS_TAG +from src.file_handeler import get_file_path_of_video from src import views from src import Youtube from src.voice_helpers import play_path_queue_guild @@ -220,12 +221,13 @@ async def play(interaction: discord.Interaction, search: str): voice_view = views.voice_play_view(timeout=info["duration"] + 5) - video_path = f"cache/{video_id}.mp3" + video_path = get_file_path_of_video(video_id) + last_played.set_video_data( interaction.guild_id, Youtube.video_data(info["title"], info["thumbnail"]) ) send_next_message = interaction.followup.send - if not os.path.isfile(video_path): # video is cached and can be played + if not os.path.isfile(video_path): # video is not cached and can't be played embed = discord.Embed( title="Şarkı indiriliyor", description=info["title"], color=CYAN ) @@ -302,7 +304,8 @@ async def add_to_queue(interaction: discord.Interaction, search: str): info: dict = ydt["entries"][0] video_id = info["id"] url = info["webpage_url"] - video_path = f"cache/{video_id}.mp3" + video_path = get_file_path_of_video(video_id) + if not os.path.isfile(video_path): # the video has not been downloaded before extra_queue = LifoQueue()