mrwabnalas40 commited on
Commit
93b36e7
·
verified ·
1 Parent(s): e23680a

Upload bottafreegh.py

Browse files
Files changed (1) hide show
  1. bottafreegh.py +90 -14
bottafreegh.py CHANGED
@@ -12,6 +12,9 @@ import time
12
  from pathlib import Path
13
  from datetime import datetime
14
 
 
 
 
15
  # إعدادات التخزين المؤقت للهواتف
16
  TEMP_DIR = "/data/data/com.termux/files/usr/tmp/tafreegh_bot" # مسار Termux
17
  try:
@@ -52,17 +55,60 @@ def check_dependencies():
52
  missing_libs.append("tafreeghbot")
53
  VIDEO_PROCESSOR_AVAILABLE = False
54
 
55
- # ffmpeg
56
  FFMPEG_AVAILABLE = False
57
  try:
58
  import subprocess
59
- result = subprocess.run(['ffmpeg', '-version'], capture_output=True, text=True)
60
- if result.returncode == 0:
61
- FFMPEG_AVAILABLE = True
62
- else:
63
- missing_libs.append("FFmpeg (تأكد من تثبيته على Termux)")
64
- except FileNotFoundError:
65
- missing_libs.append("FFmpeg (غير مثبت على النظام)")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
  return missing_libs, VIDEO_PROCESSOR_AVAILABLE, FFMPEG_AVAILABLE
68
 
@@ -70,17 +116,40 @@ def check_dependencies():
70
  missing, vid_proc_available, ffmpeg_available = check_dependencies()
71
 
72
  if missing:
 
73
  print("❌ المكتبات المفقودة:")
74
  for lib in missing:
75
  print(f" - {lib}")
76
 
77
- print("\n📦 لتثبيت المكتبات:")
78
- print("pip install pyTelegramBotAPI")
79
- print("\n📦 لتثبيت FFmpeg على Termux:")
80
- print("pkg install ffmpeg")
 
 
 
 
 
81
 
82
- if "tafreeghbot" in missing:
83
- print("\n⚠️ تأكد من وجود ملف tafreeghbot.py في نفس المجلد")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  sys.exit(1)
86
 
@@ -599,6 +668,13 @@ if __name__ == "__main__":
599
  print(f"📁 المجلد المؤقت: {TEMP_DIR}")
600
  print(f"🔑 التوكن: {TELEGRAM_TOKEN[:15]}...")
601
 
 
 
 
 
 
 
 
602
  # بدء مهمة التنظيف
603
  cleanup_thread = threading.Thread(target=cleanup_task, daemon=True)
604
  cleanup_thread.start()
 
12
  from pathlib import Path
13
  from datetime import datetime
14
 
15
+ # إضافة مسار Termux إلى PATH
16
+ os.environ['PATH'] = '/data/data/com.termux/files/usr/bin:' + os.environ['PATH']
17
+
18
  # إعدادات التخزين المؤقت للهواتف
19
  TEMP_DIR = "/data/data/com.termux/files/usr/tmp/tafreegh_bot" # مسار Termux
20
  try:
 
55
  missing_libs.append("tafreeghbot")
56
  VIDEO_PROCESSOR_AVAILABLE = False
57
 
58
+ # ffmpeg - إصلاح للمسار على Termux
59
  FFMPEG_AVAILABLE = False
60
  try:
61
  import subprocess
62
+
63
+ # تجربة عدة طرق للعثور على ffmpeg
64
+ ffmpeg_paths = [
65
+ '/data/data/com.termux/files/usr/bin/ffmpeg',
66
+ '/usr/bin/ffmpeg',
67
+ '/bin/ffmpeg',
68
+ 'ffmpeg'
69
+ ]
70
+
71
+ for ffmpeg_path in ffmpeg_paths:
72
+ try:
73
+ # استخدام shell=False مع المسار الكامل
74
+ result = subprocess.run([ffmpeg_path, '-version'],
75
+ capture_output=True,
76
+ text=True,
77
+ timeout=3)
78
+ if result.returncode == 0:
79
+ FFMPEG_AVAILABLE = True
80
+ print(f"✅ تم العثور على ffmpeg في: {ffmpeg_path}")
81
+ break
82
+ except (FileNotFoundError, OSError, subprocess.TimeoutExpired) as e:
83
+ continue
84
+
85
+ if not FFMPEG_AVAILABLE:
86
+ # الطريقة البديلة باستخدام `which`
87
+ try:
88
+ result = subprocess.run(['which', 'ffmpeg'],
89
+ capture_output=True,
90
+ text=True)
91
+ if result.returncode == 0:
92
+ FFMPEG_AVAILABLE = True
93
+ print(f"✅ تم العثور على ffmpeg عبر which: {result.stdout.strip()}")
94
+ except:
95
+ pass
96
+
97
+ # التحقق من مكتبة ffmpeg-python كبديل
98
+ if not FFMPEG_AVAILABLE:
99
+ try:
100
+ import ffmpeg
101
+ FFMPEG_AVAILABLE = True
102
+ print("✅ تم العثور على ffmpeg-python")
103
+ except ImportError:
104
+ pass
105
+
106
+ if not FFMPEG_AVAILABLE:
107
+ missing_libs.append("FFmpeg (تأكد من تثبيته على Termux: pkg install ffmpeg)")
108
+
109
+ except Exception as e:
110
+ print(f"⚠️ خطأ في التحقق من ffmpeg: {e}")
111
+ missing_libs.append("FFmpeg (خطأ في التحقق)")
112
 
113
  return missing_libs, VIDEO_PROCESSOR_AVAILABLE, FFMPEG_AVAILABLE
114
 
 
116
  missing, vid_proc_available, ffmpeg_available = check_dependencies()
117
 
118
  if missing:
119
+ print("=" * 70)
120
  print("❌ المكتبات المفقودة:")
121
  for lib in missing:
122
  print(f" - {lib}")
123
 
124
+ print("\n📦 للحل:")
125
+ print("1. تثبيت pyTelegramBotAPI:")
126
+ print(" pip install pyTelegramBotAPI")
127
+ print("\n2. تثبيت ffmpeg على Termux:")
128
+ print(" pkg update && pkg upgrade")
129
+ print(" pkg install ffmpeg")
130
+ print("\n3. تأكد من وجود ملف tafreeghbot.py في نفس المجلد")
131
+ print("\n4. إعادة تشغيل البوت بعد التثبيت")
132
+ print("=" * 70)
133
 
134
+ # سؤال المستخدم عما إذا كان يريد التثبيت تلقائياً
135
+ try:
136
+ install_choice = input("\n📥 هل تريد تثبيت المكتبات المفقودة تلقائياً؟ (y/n): ").lower()
137
+ if install_choice == 'y':
138
+ print("📦 جاري التثبيت...")
139
+
140
+ # تثبيت pyTelegramBotAPI
141
+ if "pyTelegramBotAPI" in missing:
142
+ os.system("pip install pyTelegramBotAPI")
143
+
144
+ # تثبيت ffmpeg على Termux
145
+ if "FFmpeg" in str(missing):
146
+ os.system("pkg install ffmpeg -y")
147
+ print("✅ تم تثبيت ffmpeg، قد تحتاج لإعادة تشغيل Termux")
148
+
149
+ print("\n🔄 أعد تشغيل البوت الآن:")
150
+ print("python3 bottafreegh.py")
151
+ except:
152
+ pass
153
 
154
  sys.exit(1)
155
 
 
668
  print(f"📁 المجلد المؤقت: {TEMP_DIR}")
669
  print(f"🔑 التوكن: {TELEGRAM_TOKEN[:15]}...")
670
 
671
+ # نصائح لمستخدمي Termux
672
+ print("\n💡 نصائح للأندرويد/Termux:")
673
+ print("1. تأكد من تشغيل البوت مع Termux مفتوح في الخلفية")
674
+ print("2. استخدم فيديوهات صغيرة لنتائج أسرع")
675
+ print("3. تأكد من اتصال الإنترنت الجيد")
676
+ print("4. أغلق التطبيقات غير الضرورية لتحسين الأداء")
677
+
678
  # بدء مهمة التنظيف
679
  cleanup_thread = threading.Thread(target=cleanup_task, daemon=True)
680
  cleanup_thread.start()