from pyrogram import Client
from pytube import YouTube
import os
import asyncio
app = Client("qaserd_ll", api_id=..., api_hash= ... , bot_token= ... )
@app.on_message()
async def send_video(client, message):
URL = message.text
yt = YouTube(URL)
ys = yt.streams.get_highest_resolution()
video_path = video.mp4
try:
ys.download(filename= video.mp4 ) # Download the video using the specified filename
print("Video downloaded successfully")
except Exception as e:
print(f"An error occurred while downloading the video: {e}")
return
attempts = 0
while not os.path.exists( video.mp4 ) and attempts < 10: # Wait for the video to be downloaded
await asyncio.sleep(1)
attempts += 1
if attempts == 10:
print("Video download timed out")
return
duration = yt.length
print(duration)
try:
await client.send_video(message.chat.id, video_path, duration=duration)
print("Video sent successfully")
except Exception as e:
print(f"An error occurred while sending the video: {e}")
app.run()
录像被下载,时间也正确显示,但守则的最后一条行不通。 The bot token, api_id, api_hash is written disabilities