Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,39 @@
|
|
| 1 |
import telebot
|
| 2 |
-
import
|
|
|
|
| 3 |
|
| 4 |
TOKEN = '8468827766:AAHnYY1BXQ2YFA0Lj86oTGG-GcXy3mOjXWo'
|
| 5 |
bot = telebot.TeleBot(TOKEN)
|
| 6 |
|
| 7 |
@bot.message_handler(commands=['start'])
|
| 8 |
def start(message):
|
| 9 |
-
bot.reply_to(message, "
|
| 10 |
|
| 11 |
@bot.message_handler(func=lambda m: True)
|
| 12 |
-
def
|
| 13 |
url = message.text
|
| 14 |
-
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
try:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
res = requests.get(api_url).json()
|
| 20 |
-
video = res.get('video', {}).get('noWatermark') or res.get('url')
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
api_url_2 = f"https://api.lorescripts.org/api/download?url={url}"
|
| 25 |
-
res_2 = requests.get(api_url_2).json()
|
| 26 |
-
video = res_2.get('data', {}).get('url')
|
| 27 |
-
|
| 28 |
-
if video:
|
| 29 |
bot.send_video(message.chat.id, video)
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
bot.infinity_polling()
|
|
|
|
| 1 |
import telebot
|
| 2 |
+
import yt_dlp
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
TOKEN = '8468827766:AAHnYY1BXQ2YFA0Lj86oTGG-GcXy3mOjXWo'
|
| 6 |
bot = telebot.TeleBot(TOKEN)
|
| 7 |
|
| 8 |
@bot.message_handler(commands=['start'])
|
| 9 |
def start(message):
|
| 10 |
+
bot.reply_to(message, "أهلاً يا محمد! ابعت أي رابط فيديو وهحملهولك فوراً.")
|
| 11 |
|
| 12 |
@bot.message_handler(func=lambda m: True)
|
| 13 |
+
def download_video(message):
|
| 14 |
url = message.text
|
| 15 |
+
msg = bot.reply_to(message, "⏳ جاري التحميل الفعلي للفيديو، انتظر لحظة...")
|
| 16 |
|
| 17 |
+
# إعدادات التحميل
|
| 18 |
+
ydl_opts = {
|
| 19 |
+
'format': 'best',
|
| 20 |
+
'outtmpl': 'video.mp4',
|
| 21 |
+
'quiet': True,
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
try:
|
| 25 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 26 |
+
ydl.download([url])
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
# إرسال الفيديو بعد التحميل
|
| 29 |
+
with open('video.mp4', 'rb') as video:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
bot.send_video(message.chat.id, video)
|
| 31 |
+
|
| 32 |
+
# مسح الملف بعد الإرسال لتوفير المساحة
|
| 33 |
+
os.remove('video.mp4')
|
| 34 |
+
bot.delete_message(message.chat.id, msg.message_id)
|
| 35 |
+
|
| 36 |
+
except Exception as e:
|
| 37 |
+
bot.edit_message_text(f"❌ فشل التحميل. تأكد من الرابط أو جرب لاحقاً.", message.chat.id, msg.message_id)
|
| 38 |
|
| 39 |
bot.infinity_polling()
|