Update streamlit_app.py
Browse files- streamlit_app.py +13 -8
streamlit_app.py
CHANGED
|
@@ -117,7 +117,7 @@ def create_dynamic_youtube_stream(yt):
|
|
| 117 |
timestamp_title = now_local.strftime("[%Y-%m-%d | %H:%M]")
|
| 118 |
current_date = now_local.strftime("%d-%m-%Y")
|
| 119 |
|
| 120 |
-
# 🌍
|
| 121 |
now_utc = datetime.now(dt.timezone.utc) - dt.timedelta(minutes=1)
|
| 122 |
now_iso = now_utc.strftime('%Y-%m-%dT%H:%M:%SZ')
|
| 123 |
|
|
@@ -125,11 +125,10 @@ def create_dynamic_youtube_stream(yt):
|
|
| 125 |
|
| 126 |
broadcast_body = {
|
| 127 |
"snippet": {
|
| 128 |
-
# تم تقديم صيغة الوقت والتاريخ في بداية العنوان هنا بناءً على طلبك
|
| 129 |
"title": f"{timestamp_title} بث مباشر وتغطية مستمرة | أحمد عبدالله",
|
| 130 |
"description": f"بث تلقائي آلي مؤرشف بتاريخ: {current_date}\n#بث_مباشر #أحمد_عبدالله",
|
| 131 |
"categoryId": "22",
|
| 132 |
-
"scheduledStartTime": now_iso # الوقت ال
|
| 133 |
},
|
| 134 |
"contentDetails": {
|
| 135 |
"enableMonitorStream": False # تخطي وضع اختبار الاستعراض والمراقبة لتفادي خطأ 403 وحل مشكلة المزامنة
|
|
@@ -140,9 +139,14 @@ def create_dynamic_youtube_stream(yt):
|
|
| 140 |
broadcast_res = yt.liveBroadcasts().insert(part="snippet,contentDetails,status", body=broadcast_body).execute()
|
| 141 |
broadcast_id = broadcast_res["id"]
|
| 142 |
|
|
|
|
| 143 |
stream_body = {
|
| 144 |
"snippet": {"title": f"Automated Key - {current_date}"},
|
| 145 |
-
"cdn": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
}
|
| 147 |
stream_res = yt.liveStreams().insert(part="snippet,cdn", body=stream_body).execute()
|
| 148 |
stream_key = stream_res["cdn"]["ingestionInfo"]["streamName"]
|
|
@@ -172,7 +176,7 @@ def monitor_and_switch_to_live(yt, broadcast_id):
|
|
| 172 |
return
|
| 173 |
|
| 174 |
try:
|
| 175 |
-
#
|
| 176 |
yt.liveBroadcasts().transition(broadcastStatus="live", id=broadcast_id, part="status").execute()
|
| 177 |
write_log(f"[🔥 SUCCESS] مبروك! البث المباشر انطلق وتجاوز البافر بنجاح وهو ظاهر للجميع!")
|
| 178 |
return
|
|
@@ -240,12 +244,13 @@ def run_monitor():
|
|
| 240 |
cookie_string = get_clean_tiktok_cookies()
|
| 241 |
header_option = f'--http-header "Cookie={cookie_string}"' if cookie_string else ""
|
| 242 |
|
|
|
|
| 243 |
cmd = (
|
| 244 |
f'streamlink --loglevel error {header_option} "https://www.tiktok.com/{TIKTOK_USERNAME}/live" best --hls-live-edge 5 --stdout | '
|
| 245 |
f"ffmpeg -hide_banner -loglevel info -thread_queue_size 16384 -i pipe:0 "
|
| 246 |
-
f"-c:v
|
| 247 |
-
f"-
|
| 248 |
-
f"-
|
| 249 |
f"-f flv 'rtmp://a.rtmp.youtube.com/live2/{dynamic_key}'"
|
| 250 |
)
|
| 251 |
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
| 117 |
timestamp_title = now_local.strftime("[%Y-%m-%d | %H:%M]")
|
| 118 |
current_date = now_local.strftime("%d-%m-%Y")
|
| 119 |
|
| 120 |
+
# 🌍 التعديل الزمني الذكي: توليد توقيت UTC مع طرح دقيقة واحدة كمهلة أمان لمنع وضع الجدولة المعلق
|
| 121 |
now_utc = datetime.now(dt.timezone.utc) - dt.timedelta(minutes=1)
|
| 122 |
now_iso = now_utc.strftime('%Y-%m-%dT%H:%M:%SZ')
|
| 123 |
|
|
|
|
| 125 |
|
| 126 |
broadcast_body = {
|
| 127 |
"snippet": {
|
|
|
|
| 128 |
"title": f"{timestamp_title} بث مباشر وتغطية مستمرة | أحمد عبدالله",
|
| 129 |
"description": f"بث تلقائي آلي مؤرشف بتاريخ: {current_date}\n#بث_مباشر #أحمد_عبدالله",
|
| 130 |
"categoryId": "22",
|
| 131 |
+
"scheduledStartTime": now_iso # الوقت الجاهز للإطلاق الفوري
|
| 132 |
},
|
| 133 |
"contentDetails": {
|
| 134 |
"enableMonitorStream": False # تخطي وضع اختبار الاستعراض والمراقبة لتفادي خطأ 403 وحل مشكلة المزامنة
|
|
|
|
| 139 |
broadcast_res = yt.liveBroadcasts().insert(part="snippet,contentDetails,status", body=broadcast_body).execute()
|
| 140 |
broadcast_id = broadcast_res["id"]
|
| 141 |
|
| 142 |
+
# 🛠️ تحديث الـ CDN ليكون ثابتًا (30 إطارًا بدقة 720p) ليتوافق مع معايير يوتيوب الصارمة والإشارة المصنعة
|
| 143 |
stream_body = {
|
| 144 |
"snippet": {"title": f"Automated Key - {current_date}"},
|
| 145 |
+
"cdn": {
|
| 146 |
+
"frameRate": "30fps",
|
| 147 |
+
"resolution": "720p",
|
| 148 |
+
"ingestionType": "rtmp"
|
| 149 |
+
}
|
| 150 |
}
|
| 151 |
stream_res = yt.liveStreams().insert(part="snippet,cdn", body=stream_body).execute()
|
| 152 |
stream_key = stream_res["cdn"]["ingestionInfo"]["streamName"]
|
|
|
|
| 176 |
return
|
| 177 |
|
| 178 |
try:
|
| 179 |
+
# بما أن الإشارة أصبحت قياسية والـ Monitor معطل، سينتقل البث الآن بسلاسة
|
| 180 |
yt.liveBroadcasts().transition(broadcastStatus="live", id=broadcast_id, part="status").execute()
|
| 181 |
write_log(f"[🔥 SUCCESS] مبروك! البث المباشر انطلق وتجاوز البافر بنجاح وهو ظاهر للجميع!")
|
| 182 |
return
|
|
|
|
| 244 |
cookie_string = get_clean_tiktok_cookies()
|
| 245 |
header_option = f'--http-header "Cookie={cookie_string}"' if cookie_string else ""
|
| 246 |
|
| 247 |
+
# 🛠️ أمر الـ FFmpeg المطور: يعيد بناء الإشارة برمجياً لتصبح 30fps ثابتة ومستقرة تماماً ليوتيوب
|
| 248 |
cmd = (
|
| 249 |
f'streamlink --loglevel error {header_option} "https://www.tiktok.com/{TIKTOK_USERNAME}/live" best --hls-live-edge 5 --stdout | '
|
| 250 |
f"ffmpeg -hide_banner -loglevel info -thread_queue_size 16384 -i pipe:0 "
|
| 251 |
+
f"-c:v libx264 -preset ultrafast -tune zerolatency -r 30 -g 60 -b:v 2000k -maxrate 2500k -bufsize 4000k "
|
| 252 |
+
f"-pix_fmt yuv420p -c:a aac -ar 44100 -b:a 128k -ac 2 "
|
| 253 |
+
f"-af 'aresample=async=1' "
|
| 254 |
f"-f flv 'rtmp://a.rtmp.youtube.com/live2/{dynamic_key}'"
|
| 255 |
)
|
| 256 |
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|