Update streamlit_app.py
Browse files- streamlit_app.py +18 -7
streamlit_app.py
CHANGED
|
@@ -3,6 +3,7 @@ from io import BytesIO
|
|
| 3 |
from PIL import Image, ImageDraw, ImageFont
|
| 4 |
import streamlit as st
|
| 5 |
|
|
|
|
| 6 |
FONT_PATH = "/tmp/Palestine.ttf"
|
| 7 |
FONT_URL = "https://github.com/mokhtarbsaid/rare-arabic-fonts/raw/main/palestine/palestine-regular.ttf"
|
| 8 |
COMMENTS_URL = "https://reoo88-signserver.hf.space/comments"
|
|
@@ -61,9 +62,12 @@ def start_stream(yt_key, username):
|
|
| 61 |
threading.Thread(target=comments_updater, daemon=True).start()
|
| 62 |
time.sleep(3)
|
| 63 |
|
| 64 |
-
|
|
|
|
|
|
|
| 65 |
ff_cmd = [
|
| 66 |
-
"ffmpeg",
|
|
|
|
| 67 |
"-i", "pipe:0",
|
| 68 |
"-f", "image2pipe", "-r", "2", "-i", "pipe:1",
|
| 69 |
"-filter_complex", "[0:v]scale=720:1280[vid];[vid][1:v]overlay=0:0",
|
|
@@ -75,22 +79,29 @@ def start_stream(yt_key, username):
|
|
| 75 |
]
|
| 76 |
|
| 77 |
try:
|
| 78 |
-
sl_process = subprocess.Popen(sl_cmd,
|
| 79 |
-
|
|
|
|
| 80 |
|
|
|
|
| 81 |
def feed_overlay():
|
| 82 |
while ffmpeg_process.poll() is None:
|
| 83 |
try:
|
| 84 |
img_data = create_comment_overlay()
|
| 85 |
ffmpeg_process.stdin.write(img_data)
|
| 86 |
ffmpeg_process.stdin.flush()
|
| 87 |
-
except:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
break
|
| 89 |
time.sleep(0.5)
|
| 90 |
-
|
| 91 |
|
| 92 |
threading.Thread(target=feed_overlay, daemon=True).start()
|
| 93 |
|
|
|
|
| 94 |
while ffmpeg_process.poll() is None:
|
| 95 |
data = sl_process.stdout.read(8192)
|
| 96 |
if not data:
|
|
@@ -103,7 +114,7 @@ def start_stream(yt_key, username):
|
|
| 103 |
except Exception as e:
|
| 104 |
print(f"[ERROR] {e}")
|
| 105 |
|
| 106 |
-
st.title("بث تيك توك مع تعليقات
|
| 107 |
with st.form("f"):
|
| 108 |
user = st.text_input("معرف تيك توك", "majd.alban")
|
| 109 |
key = st.text_input("مفتاح يوتيوب", type="password")
|
|
|
|
| 3 |
from PIL import Image, ImageDraw, ImageFont
|
| 4 |
import streamlit as st
|
| 5 |
|
| 6 |
+
# ---------- إعدادات ----------
|
| 7 |
FONT_PATH = "/tmp/Palestine.ttf"
|
| 8 |
FONT_URL = "https://github.com/mokhtarbsaid/rare-arabic-fonts/raw/main/palestine/palestine-regular.ttf"
|
| 9 |
COMMENTS_URL = "https://reoo88-signserver.hf.space/comments"
|
|
|
|
| 62 |
threading.Thread(target=comments_updater, daemon=True).start()
|
| 63 |
time.sleep(3)
|
| 64 |
|
| 65 |
+
# إصلاح 1: استخدام shell=False
|
| 66 |
+
sl_cmd = ["streamlink", f"https://www.tiktok.com/@{username}/live", "best", "--hls-live-edge", "3", "--stdout"]
|
| 67 |
+
|
| 68 |
ff_cmd = [
|
| 69 |
+
"ffmpeg",
|
| 70 |
+
"-thread_queue_size", "8192",
|
| 71 |
"-i", "pipe:0",
|
| 72 |
"-f", "image2pipe", "-r", "2", "-i", "pipe:1",
|
| 73 |
"-filter_complex", "[0:v]scale=720:1280[vid];[vid][1:v]overlay=0:0",
|
|
|
|
| 79 |
]
|
| 80 |
|
| 81 |
try:
|
| 82 |
+
sl_process = subprocess.Popen(sl_cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
|
| 83 |
+
# إصلاح 2: تعيين bufsize كبير
|
| 84 |
+
ffmpeg_process = subprocess.Popen(ff_cmd, stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, bufsize=10**8)
|
| 85 |
|
| 86 |
+
# خيط لتغذية ffmpeg بصورة التعليقات
|
| 87 |
def feed_overlay():
|
| 88 |
while ffmpeg_process.poll() is None:
|
| 89 |
try:
|
| 90 |
img_data = create_comment_overlay()
|
| 91 |
ffmpeg_process.stdin.write(img_data)
|
| 92 |
ffmpeg_process.stdin.flush()
|
| 93 |
+
except BrokenPipeError:
|
| 94 |
+
print("[INFO] توقف ffmpeg عن استقبال الصور (Broken pipe - طبيعي عند انتهاء البث)")
|
| 95 |
+
break
|
| 96 |
+
except Exception as e:
|
| 97 |
+
print(f"[ERROR] خطأ في تغذية الصور: {e}")
|
| 98 |
break
|
| 99 |
time.sleep(0.5)
|
| 100 |
+
# لا نغلق stdin هنا، نترك العملية الرئيسية تتعامل معه
|
| 101 |
|
| 102 |
threading.Thread(target=feed_overlay, daemon=True).start()
|
| 103 |
|
| 104 |
+
# تغذية الفيديو من streamlink
|
| 105 |
while ffmpeg_process.poll() is None:
|
| 106 |
data = sl_process.stdout.read(8192)
|
| 107 |
if not data:
|
|
|
|
| 114 |
except Exception as e:
|
| 115 |
print(f"[ERROR] {e}")
|
| 116 |
|
| 117 |
+
st.title("بث تيك توك مع تعليقات - حل نهائي")
|
| 118 |
with st.form("f"):
|
| 119 |
user = st.text_input("معرف تيك توك", "majd.alban")
|
| 120 |
key = st.text_input("مفتاح يوتيوب", type="password")
|