Alide21 commited on
Commit
4cd7492
·
verified ·
1 Parent(s): 203d8d0

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +87 -50
main.py CHANGED
@@ -4,80 +4,117 @@ import subprocess
4
  from datetime import datetime
5
  from flask import Flask
6
  import threading
7
- import sys
8
 
9
  # ==========================================
10
- # إعدادات التحكم
11
  # ==========================================
12
- SHOW_IN_APP = True # اجعله True لعرض العداد في صفحة الـ App البيضاء
13
- SHOW_IN_LOGS = False # اجعله True لعرض العداد في شاشة الـ Logs السوداء
14
- RAMADAN_DATE = datetime(2026, 3, 20, 0, 0, 0)
15
  STREAM_KEY = os.environ.get("STREAM_KEY")
16
  STREAM_URL = "rtmp://a.rtmp.youtube.com/live2/"
17
  # ==========================================
18
 
19
  app = Flask(__name__)
20
 
21
- # دالة لحساب الوقت المتبقي وتنسيقه
22
- def get_time_left():
23
- remaining = RAMADAN_DATE - datetime.now()
24
- if remaining.total_seconds() > 0:
25
- days = remaining.days
26
- hours, rem = divmod(remaining.seconds, 3600)
27
- minutes, seconds = divmod(rem, 60)
28
- return f"{days} يوم و {hours:02}:{minutes:02}:{seconds:02}"
29
- return "بدأ شهر رمضان! مبارك عليكم"
30
-
31
  @app.route('/')
32
  def home():
33
- if SHOW_IN_APP:
34
- time_left = get_time_left()
35
- # كود HTML بسيط لتحديث الصفحة كل ثانية وعرض العداد بشكل جميل
36
- return f"""
37
- <html>
38
- <head>
39
- <meta http-equiv="refresh" content="1">
40
- <style>
41
- body {{ font-family: sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; background: #1a1a1a; color: white; }}
42
- .container {{ text-align: center; border: 2px solid yellow; padding: 40px; border-radius: 20px; }}
43
- h1 {{ color: yellow; font-size: 3em; }}
44
- p {{ font-size: 1.5em; }}
45
- </style>
46
- </head>
47
- <body>
48
- <div class="container">
49
- <h1>عداد رمضان 2026</h1>
50
- <p>الوقت المتبقي للبث المباشر:</p>
51
- <div style="font-size: 2.5em; font-weight: bold;">{time_left}</div>
52
- </div>
53
- </body>
54
- </html>
55
- """
56
- else:
57
- return "Stream is Running! (Dashboard Disabled)", 200
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
- def print_console_countdown():
60
- while SHOW_IN_LOGS:
61
- sys.stdout.write(f"\r[Monitor] {get_time_left()}")
62
- sys.stdout.flush()
63
- time.sleep(1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  def start_stream():
66
  if not STREAM_KEY:
 
67
  return
 
 
68
  ffmpeg_cmd = [
69
  'ffmpeg', '-re', '-f', 'lavfi', '-i', 'color=c=black:s=1280x720:r=30',
70
- '-vf', f"drawtext=text='Ramadan 2026 Countdown':x=(w-text_w)/2:y=(h-text_h)/2-60:fontsize=70:fontcolor=white, "
71
- f"drawtext=text='%{{pts\\:localtime\\:{RAMADAN_DATE.timestamp()}\\:%d Days %H\\:%M\\:%S}}':x=(w-text_w)/2:y=(h-text_h)/2+60:fontsize=90:fontcolor=yellow",
72
- '-vcodec', 'libx264', '-preset', 'veryfast', '-b:v', '1500k', '-f', 'flv', f"{STREAM_URL}{STREAM_KEY}"
73
  ]
74
  subprocess.run(ffmpeg_cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
75
 
76
  if __name__ == "__main__":
 
77
  threading.Thread(target=lambda: app.run(host='0.0.0.0', port=7860), daemon=True).start()
78
- if SHOW_IN_LOGS:
79
- threading.Thread(target=print_console_countdown, daemon=True).start()
80
 
 
81
  while True:
82
  try:
83
  start_stream()
 
4
  from datetime import datetime
5
  from flask import Flask
6
  import threading
 
7
 
8
  # ==========================================
9
+ # الإعدادات الأساسية
10
  # ==========================================
11
+ TARGET_DATE = datetime(2026, 2, 19, 0, 0, 0) # التاريخ الجديد
 
 
12
  STREAM_KEY = os.environ.get("STREAM_KEY")
13
  STREAM_URL = "rtmp://a.rtmp.youtube.com/live2/"
14
  # ==========================================
15
 
16
  app = Flask(__name__)
17
 
 
 
 
 
 
 
 
 
 
 
18
  @app.route('/')
19
  def home():
20
+ # كود HTML احترافي بتصميم Flip Clock عصري
21
+ return f"""
22
+ <!DOCTYPE html>
23
+ <html lang="ar" dir="rtl">
24
+ <head>
25
+ <meta charset="UTF-8">
26
+ <meta http-equiv="refresh" content="1">
27
+ <title>عداد رمضان 2026</title>
28
+ <style>
29
+ body {{
30
+ background-color: #f4f4f4;
31
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
32
+ display: flex;
33
+ flex-direction: column;
34
+ justify-content: center;
35
+ align-items: center;
36
+ height: 100vh;
37
+ margin: 0;
38
+ }}
39
+ .title {{ font-size: 2.5rem; color: #333; margin-bottom: 30px; font-weight: bold; }}
40
+ .countdown-container {{ display: flex; gap: 20px; }}
41
+ .time-box {{ text-align: center; }}
42
+ .label {{ font-size: 1.2rem; color: #555; margin-bottom: 10px; font-weight: bold; }}
43
+ .flip-card {{
44
+ background: #4CAF50;
45
+ color: white;
46
+ font-size: 4rem;
47
+ padding: 15px 25px;
48
+ border-radius: 10px;
49
+ box-shadow: 0 8px 15px rgba(0,0,0,0.2);
50
+ min-width: 100px;
51
+ display: inline-block;
52
+ position: relative;
53
+ }}
54
+ /* خط فاصل في منتصف البطاقة ليشبه الـ Flip */
55
+ .flip-card::after {{
56
+ content: '';
57
+ position: absolute;
58
+ left: 0; top: 50%;
59
+ width: 100%; height: 2px;
60
+ background: rgba(0,0,0,0.1);
61
+ }}
62
+ </style>
63
+ </head>
64
+ <body>
65
+ <div class="title">كم باقي على رمضان 2026</div>
66
+ <div class="countdown-container">
67
+ {generate_timer_html()}
68
+ </div>
69
+ </body>
70
+ </html>
71
+ """
72
 
73
+ def generate_timer_html():
74
+ diff = TARGET_DATE - datetime.now()
75
+ if diff.total_seconds() <= 0:
76
+ return "<h1>مبارك عليكم الشهر!</h1>"
77
+
78
+ days = diff.days
79
+ hours, rem = divmod(diff.seconds, 3600)
80
+ minutes, seconds = divmod(rem, 60)
81
+
82
+ units = [
83
+ (days, "أيام"),
84
+ (hours, "ساعات"),
85
+ (minutes, "دقائق"),
86
+ (seconds, "ثواني")
87
+ ]
88
+
89
+ html = ""
90
+ for val, label in units:
91
+ html += f"""
92
+ <div class="time-box">
93
+ <div class="label">{label}</div>
94
+ <div class="flip-card">{val:02}</div>
95
+ </div>
96
+ """
97
+ return html
98
 
99
  def start_stream():
100
  if not STREAM_KEY:
101
+ print("Waiting for Stream Key in Secrets...")
102
  return
103
+
104
+ # فلتر FFmpeg للبث المباشر مع التاريخ الجديد
105
  ffmpeg_cmd = [
106
  'ffmpeg', '-re', '-f', 'lavfi', '-i', 'color=c=black:s=1280x720:r=30',
107
+ '-vf', f"drawtext=text='Ramadan 2026':x=(w-text_w)/2:y=(h-text_h)/2-60:fontsize=80:fontcolor=white, "
108
+ f"drawtext=text='%{{pts\\:localtime\\:{TARGET_DATE.timestamp()}\\:%d Days %H\\:%M\\:%S}}':x=(w-text_w)/2:y=(h-text_h)/2+60:fontsize=100:fontcolor=green",
109
+ '-vcodec', 'libx264', '-preset', 'veryfast', '-b:v', '2000k', '-f', 'flv', f"{STREAM_URL}{STREAM_KEY}"
110
  ]
111
  subprocess.run(ffmpeg_cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
112
 
113
  if __name__ == "__main__":
114
+ # تشغيل الواجهة الجميلة
115
  threading.Thread(target=lambda: app.run(host='0.0.0.0', port=7860), daemon=True).start()
 
 
116
 
117
+ print("System Running... Check the 'App' tab for the new design!")
118
  while True:
119
  try:
120
  start_stream()