Tk.test / streamlit_app.py
Reoo88's picture
Update streamlit_app.py
278b050 verified
Raw History Blame Contribute Delete
1.8 kB
import os
import time
import subprocess
import yt_dlp
import streamlit as st
# الإعدادات
YOUTUBE_STREAM_URL = "rtmp://a.rtmp.youtube.com/live2/skqf-rd92-dfa7-74cx-bxr2"
TARGET_USERNAME = "ah_md107"
TIKTOK_LIVE_URL = f"https://www.tiktok.com/@{TARGET_USERNAME}/live"
def get_tiktok_stream_url():
# اختيار 'best' ضروري هنا لأننا سنقوم بنسخ التدفق (Copy)
# لا تقم بـ scale أو re-encode في FFmpeg
ydl_opts = {
'format': 'best',
'quiet': True,
'cookiefile': 'cookies.txt',
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
try:
info = ydl.extract_info(TIKTOK_LIVE_URL, download=False)
# استخراج رابط الـ HLS المباشر
return info.get('url')
except:
return None
def run_restreamer():
current_process = None
print(f"[System] Stream Copy Mode Active for {TARGET_USERNAME}...")
while True:
tiktok_url = get_tiktok_stream_url()
if tiktok_url:
if current_process is None or current_process.poll() is not None:
# الكود السري: -c copy يعني انسخ الفيديو والصوت بدون أي معالجة
# هذا يقلل استهلاك المعالج بنسبة 95%
ffmpeg_cmd = [
'ffmpeg', '-re', '-i', tiktok_url,
'-c', 'copy',
'-f', 'flv', YOUTUBE_STREAM_URL
]
current_process = subprocess.Popen(ffmpeg_cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
else:
if current_process and current_process.poll() is None:
current_process.terminate()
time.sleep(20)