Update streamlit_app.py
Browse files- streamlit_app.py +23 -22
streamlit_app.py
CHANGED
|
@@ -4,6 +4,7 @@ import base64
|
|
| 4 |
import pickle
|
| 5 |
import subprocess
|
| 6 |
import yt_dlp
|
|
|
|
| 7 |
from googleapiclient.discovery import build
|
| 8 |
|
| 9 |
# ==========================================
|
|
@@ -13,56 +14,56 @@ YOUTUBE_STREAM_URL = "rtmp://a.rtmp.youtube.com/live2/skqf-rd92-dfa7-74cx-bxr2"
|
|
| 13 |
TIKTOK_LIVE_URL = "https://www.tiktok.com/@abdulaziz999989/live"
|
| 14 |
|
| 15 |
# ==========================================
|
| 16 |
-
# 2. تهي
|
| 17 |
# ==========================================
|
| 18 |
-
def
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# ==========================================
|
| 25 |
-
# 3. سحب رابط
|
| 26 |
# ==========================================
|
| 27 |
-
def get_tiktok_stream_url():
|
| 28 |
ydl_opts = {
|
| 29 |
'format': 'best',
|
| 30 |
'quiet': True,
|
| 31 |
-
'
|
|
|
|
| 32 |
}
|
| 33 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 34 |
try:
|
| 35 |
info = ydl.extract_info(TIKTOK_LIVE_URL, download=False)
|
| 36 |
return info.get('url')
|
| 37 |
except Exception as e:
|
| 38 |
-
print(f"[Error] TikTok
|
| 39 |
return None
|
| 40 |
|
| 41 |
# ==========================================
|
| 42 |
-
# 4.
|
| 43 |
# ==========================================
|
| 44 |
def run_restreamer():
|
| 45 |
-
|
|
|
|
| 46 |
|
| 47 |
while True:
|
| 48 |
-
tiktok_url = get_tiktok_stream_url()
|
| 49 |
|
| 50 |
if tiktok_url:
|
| 51 |
-
print("[System]
|
| 52 |
-
|
| 53 |
-
# أمر FFmpeg لسحب الرابط وإعادة توجيهه ليوتيوب
|
| 54 |
ffmpeg_cmd = [
|
| 55 |
'ffmpeg', '-re', '-i', tiktok_url,
|
| 56 |
'-c:v', 'libx264', '-preset', 'veryfast', '-b:v', '2000k',
|
| 57 |
'-c:a', 'aac', '-b:a', '128k', '-f', 'flv', YOUTUBE_STREAM_URL
|
| 58 |
]
|
| 59 |
-
|
| 60 |
-
process = subprocess.Popen(ffmpeg_cmd, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
|
| 61 |
-
process.wait() # انتظر حتى ينتهي البث
|
| 62 |
-
print("[System] Stream ended. Restarting...")
|
| 63 |
else:
|
| 64 |
-
print("[System]
|
| 65 |
time.sleep(30)
|
| 66 |
|
| 67 |
if __name__ == "__main__":
|
| 68 |
-
run_restreamer()
|
|
|
|
| 4 |
import pickle
|
| 5 |
import subprocess
|
| 6 |
import yt_dlp
|
| 7 |
+
import streamlit as st # للوصول للـ Secrets
|
| 8 |
from googleapiclient.discovery import build
|
| 9 |
|
| 10 |
# ==========================================
|
|
|
|
| 14 |
TIKTOK_LIVE_URL = "https://www.tiktok.com/@abdulaziz999989/live"
|
| 15 |
|
| 16 |
# ==========================================
|
| 17 |
+
# 2. تجهيز ملف الكوكيز مؤقتاً
|
| 18 |
# ==========================================
|
| 19 |
+
def setup_cookies():
|
| 20 |
+
# افترضنا أنك وضعت الكوكيز في الـ Secrets باسم TIKTOK_COOKIES
|
| 21 |
+
cookies_data = st.secrets.get("TIKTOK_COOKIES")
|
| 22 |
+
if cookies_data:
|
| 23 |
+
with open("cookies.txt", "w") as f:
|
| 24 |
+
f.write(cookies_data)
|
| 25 |
+
return "cookies.txt"
|
| 26 |
+
return None
|
| 27 |
|
| 28 |
# ==========================================
|
| 29 |
+
# 3. سحب الرابط مع الكوكيز
|
| 30 |
# ==========================================
|
| 31 |
+
def get_tiktok_stream_url(cookie_file):
|
| 32 |
ydl_opts = {
|
| 33 |
'format': 'best',
|
| 34 |
'quiet': True,
|
| 35 |
+
'cookiefile': cookie_file, # هنا نقوم بتمرير ملف الكوكيز
|
| 36 |
+
'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|
| 37 |
}
|
| 38 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 39 |
try:
|
| 40 |
info = ydl.extract_info(TIKTOK_LIVE_URL, download=False)
|
| 41 |
return info.get('url')
|
| 42 |
except Exception as e:
|
| 43 |
+
print(f"[Error] TikTok connection failed (Cookies might be expired): {e}")
|
| 44 |
return None
|
| 45 |
|
| 46 |
# ==========================================
|
| 47 |
+
# 4. التنفيذ
|
| 48 |
# ==========================================
|
| 49 |
def run_restreamer():
|
| 50 |
+
cookie_file = setup_cookies()
|
| 51 |
+
print(f"[System] Starting Restreaming Radar using cookies: {cookie_file}")
|
| 52 |
|
| 53 |
while True:
|
| 54 |
+
tiktok_url = get_tiktok_stream_url(cookie_file)
|
| 55 |
|
| 56 |
if tiktok_url:
|
| 57 |
+
print("[System] Stream link captured! Starting FFmpeg...")
|
|
|
|
|
|
|
| 58 |
ffmpeg_cmd = [
|
| 59 |
'ffmpeg', '-re', '-i', tiktok_url,
|
| 60 |
'-c:v', 'libx264', '-preset', 'veryfast', '-b:v', '2000k',
|
| 61 |
'-c:a', 'aac', '-b:a', '128k', '-f', 'flv', YOUTUBE_STREAM_URL
|
| 62 |
]
|
| 63 |
+
subprocess.run(ffmpeg_cmd)
|
|
|
|
|
|
|
|
|
|
| 64 |
else:
|
| 65 |
+
print("[System] Waiting for live stream...")
|
| 66 |
time.sleep(30)
|
| 67 |
|
| 68 |
if __name__ == "__main__":
|
| 69 |
+
run_restreamer()
|