Skip to content

Commit

Permalink
Update play_song.py and play_video.py
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiiRepair committed Aug 6, 2023
1 parent 29ea845 commit 5297c90
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
32 changes: 18 additions & 14 deletions tlg_bot/plugins/play_song.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import uuid
from asyncio import sleep

# from tlg_bot.helpers.thumbnail import gen_thumb
from telethon import Button, events
from tlg_bot.dicts.dicts import QUEUE, VOICE_CHATS
Expand Down Expand Up @@ -71,6 +72,19 @@ async def play_song(event):
file=config.CMD_IMG,
buttons=[[Button.inline("cʟᴏꜱᴇ", data="cls")]],
)
if VOICE_CHATS.get(chat.id) is None:
try:
await msg.edit("__Joining the voice chat...__")
await ins.join(chat.id)
VOICE_CHATS[chat.id] = ins
await sleep(3)
except Exception as e:
await msg.edit(
f"__Oops master, something wrong has happened. \n\nError:__ `{e}`",
)
await VOICE_CHATS[chat.id].stop()
VOICE_CHATS.pop(chat.id)
return await sleep(3)
elif replied and not replied.audio and not replied.voice or not replied:
query = event.text.split(maxsplit=1)[1]
search = ytsearch(query)
Expand All @@ -96,19 +110,7 @@ async def play_song(event):
# file=thumb,
buttons=[[Button.inline("cʟᴏꜱᴇ", data="cls")]],
)
elif VOICE_CHATS.get(chat.id) is None:
try:
await msg.edit("__Joining the voice chat...__")
await ins.join(chat.id)
VOICE_CHATS[chat.id] = ins
await sleep(3)
except Exception as e:
await msg.edit(
f"__Oops master, something wrong has happened. \n\nError:__ `{e}`",
)
await VOICE_CHATS[chat.id].stop()
VOICE_CHATS.pop(chat.id)
return await sleep(3)

try:
await ins.start_audio(url, repeat=False)
add_to_queue(chat, name, url, ref, "audio")
Expand Down Expand Up @@ -139,7 +141,9 @@ async def play_song(event):

else:
await msg.edit("➕ __Downloading...__")
dl = await replied.download_media(file=f"{downloads_dir} {str(uuid.uuid4())}")
dl = await replied.download_media(
file=f"{downloads_dir} {str(uuid.uuid4())}"
)
link = f"https://t.me/c/{chat.id}/{event.reply_to_msg_id}"
if replied.audio:
name = "Audio File"
Expand Down
4 changes: 3 additions & 1 deletion tlg_bot/plugins/play_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ async def play_video(event):

elif media.video or media.file:
await msg.edit("🔄 __Downloading...__")
video = await client.download_media(media, file=f"{downloads_dir} {str(uuid.uuid4())}")
video = await client.download_media(
media, file=f"{downloads_dir} {str(uuid.uuid4())}"
)

try:
await sleep(2)
Expand Down

0 comments on commit 5297c90

Please sign in to comment.