Skip to content

Commit

Permalink
update file_path of music system
Browse files Browse the repository at this point in the history
Now It also gets downloaded into the "downloads/youtube" folder
  • Loading branch information
kytpbs committed Jul 18, 2024
1 parent d3ffb32 commit cd554a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/file_handeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
9 changes: 6 additions & 3 deletions src/voice_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit cd554a9

Please sign in to comment.