من این کد رو دارم

from pyrogram import Client # pip install pyrogram
from pyrogram import filters # pip install tgcrypto
from pyrogram.types import Message

from pytgcalls import filters as fl # pip install py-tgcalls -U
from pytgcalls import idle
from pytgcalls import PyTgCalls
from pytgcalls.types import ChatUpdate
from pytgcalls.types import GroupCallParticipant
from pytgcalls.types import MediaStream
from pytgcalls.types import Update

import os
import re
import subprocess
import random
import string

api_id = 13315602
api_hash = "21dc35844ae3c0e31faacc8f0ade17db"

proxy = {
"scheme": "socks5", # "socks4", "socks5" and "http" are supported
"hostname": "127.0.0.1",
"port": 2080,
"username": "username",
"password": "password"
}

phone_num = '+989115050944'

app = Client(
"app_sesion",
api_id=api_id,
api_hash=api_hash,
phone_number=phone_num,
# proxy=proxy
)

call_py = PyTgCalls(app)

def generate_random_string(length=10):
# ترکیب حروف کوچک، بزرگ و اعداد
characters = string.ascii_letters + string.digits
# ایجاد یک رشته رندوم از ترکیب حروف و اعداد
random_string = ''.join(random.choice(characters) for _ in range(length))
return random_string

async def progress_callback(current, total, msg, file_name):
if total > 0:
percent = (current / total) * 100
await msg.edit(f"Downloading {file_name}: {percent:.2f}% completed.")

def download_video(url: str) -> str:
output_file = f'video_{generate_random_string()}.mp4' # نام فایل خروجی با زمان منحصر به فرد
try:
subprocess.run(['yt-dlp', '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]', '-o', output_file, url], check=True)
return output_file
except subprocess.CalledProcessError:
return None

@app.on_message(filters.text)
async def handle_link(client: Client, update: Message):
url = update.text
#if 'youtube.com' in url or 'youtu.be' in url:
# process = text.split(" ")[0]
# url = text.split(" ")[1]
await update.reply_text("Download Started. Please Waite...")
video_file = download_video(url) # یا استفاده از yt-dlp
if video_file and os.path.exists(video_file):
await client.send_video(update.chat.id,video_file)
os.remove(video_file) # حذف فایل بعد از ارسال
else:
await update.reply_text('خطا در دانلود ویدیو.')
#else:
# await update.reply_text('لطفاً یک لینک معتبر یوتیوب ارسال کنید.')

@app.on_message(filters.private & filters.document)
async def play_handler(_, message: Message):
if message.chat.id == 7618452400:
file_name = message.document.file_name
index_format = file_name.rfind('.')
progress_msg = await message.reply("Download Started. Please Waite...")
if re.search(r"mp3", file_name):
await app.download_media(message, f"{file_name[:index_format]}.mp3", progress=progress_callback, progress_args=(progress_msg, file_name))
elif re.search(r"mp4|mkv", file_name):
await app.download_media(message, f"{file_name[:index_format]}.mkv", progress=progress_callback, progress_args=(progress_msg, file_name))

@app.on_message(filters.private & filters.audio)
async def play_handler(_, message: Message):
if message.chat.id == 7618452400:
file_name = message.audio.file_name
index_format = file_name.rfind('.')
progress_msg = await message.reply("Download Started. Please Waite...")
await app.download_media(message, f"{file_name[:index_format]}.mp3", progress=progress_callback, progress_args=(progress_msg, file_name))

@app.on_message(filters.private & filters.video)
async def play_handler(_, message: Message):
if message.chat.id == 7618452400:
file_name = message.video.file_name
index_format = file_name.rfind('.')
progress_msg = await message.reply("Download Started. Please Waite...")
await app.download_media(message, f"{file_name[:index_format]}.mkv", progress=progress_callback, progress_args=(progress_msg, file_name))

@app.on_message(filters.regex('/help'))
async def play_handler(_: Client, message: Message):
files = os.listdir("./downloads")
song_name = "لیست اهنگ ها به شرح زیر است\n"
film_name = "لیست فیلم ها به شرح زیر است\n"
for name in files:
if re.search(r"mp3",name):
song_name += name.replace(".mp3","") + "\n"
if re.search(r"mkv",name):
film_name += name.replace(".mkv","") + "\n"
text = """شما با فعال کردن تماس گروه میتونین از دستور زیر استفاده کرده تا اهنگ مد نظر رو اجرا یا کنترل کنین همچنین در انتهای لیست نام اهنگ های فعلی موجود ذکر شده
/play برای اجرای اهنگ مد نظر
به طور مثال
/play Qrargah
/stop برای متوقف کردن
/pause برای استپ کردن
/resume اجرای ادامه
/change_volume برای تغییر ولوم
به طور مثال
/change_volume 50
""" + song_name + film_name
await app.send_message(message.chat.id, text)

@app.on_message(filters.regex('/del'))
async def play_handler(_: Client, message: Message):
text = message.text


if re.search(r"film",text):
    file_name = text.replace("/del film ","")+".mkv"
elif re.search(r"music",text):
    file_name = text.replace("/del music ","")+".mp4"

os.remove(f"./downloads/{file_name}")

await app.send_message(message.chat.id, f"remove successfull {file_name}")
@app.on_message(filters.regex('/play'))
async def play_handler(_: Client, message: Message):
text = message.text
if re.search(r"music",text):
song_name = text.replace("/play music ","")
test_stream = f'./downloads/{song_name}.mp3'
if re.search(r"film",text):
film_name = text.replace("/play film ","")
test_stream = f'./downloads/{film_name}.mkv'
await call_py.play(
message.chat.id,
MediaStream(
test_stream,
),
)
await app.send_message(message.chat.id, f"Bot Play {song_name}")

@app.on_message(filters.regex('/cache'))
async def cache_handler(_: Client, _m: Message):
await app.send_message(_m.chat.id, call_py.cache_peer)

@app.on_message(filters.regex('/ping'))
async def ping_handler(_: Client, _m: Message):
await app.send_message(_m.chat.id, call_py.ping)

@app.on_message(filters.regex('/pause'))
async def pause_handler(_: Client, message: Message):
await call_py.pause_stream(
message.chat.id,
)
await app.send_message(message.chat.id, "Bot Pause/")

@app.on_message(filters.regex('/resume'))
async def resume_handler(_: Client, message: Message):
await call_py.resume_stream(
message.chat.id,
)
await app.send_message(message.chat.id, "Bot Resume/")

@app.on_message(filters.regex('/stop'))
async def stop_handler(_: Client, message: Message):
await call_py.leave_call(
message.chat.id,
)
await app.send_message(message.chat.id, "Bot Stop/")

@app.on_message(filters.regex('/change_volume'))
async def change_volume_handler(_: Client, message: Message):
volume = int(message.text.replace("/change_volume ",""))
await call_py.change_volume_call(
message.chat.id,
volume,
)

@app.on_message(filters.regex('/status'))
async def get_play_status(client: Client, message: Message):
await client.send_message(
message.chat.id,
f'Current seconds {await call_py.played_time(message.chat.id)}',
)

@call_py.on_update(
fl.chat_update(
ChatUpdate.Status.KICKED | ChatUpdate.Status.LEFT_GROUP,
),
)
async def kicked_handler(_: PyTgCalls, update: Update):
print(f'Kicked from {update.chat_id} or left')

@call_py.on_update(fl.stream_end)
async def stream_end_handler(_: PyTgCalls, update: Update):
print(f'Stream ended in {update.chat_id}', update)

@call_py.on_update(
fl.call_participant(GroupCallParticipant.Action.JOINED),
)
async def participant_handler(_: PyTgCalls, update: Update):
print(f'Participant joined in {update.chat_id}', update)

@call_py.on_update()
async def all_updates(_: PyTgCalls, update: Update):
print(update)

call_py.start()
idle()

کد درست و کامل کار میکنه
ولی میخوام هنگام دانلود از یوتیوب و اینستا توسط تابع handle_link هم بیاد و درصد دانلود رو به کاربر نشون بده تو پیام