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 video is downloaded, the time is also displayed correctly, but the last lines of the code are not executed. the bot token, api_id, api_hash is written correctly
sample video
What's your file size ? It took me about 20s to send a 1.5 mb video I downloaded from the link above. This was my MRE and it worked -
Use
import tracebackand puttraceback.print_exc()in theexceptblock . Update me about the result .