File size: 1,795 Bytes
a239a42
 
f13ad6a
9a83eee
69ecaf8
b1c2294
278b050
419bbaa
356d5dd
 
b1c2294
69ecaf8
278b050
 
9a83eee
278b050
9a83eee
69ecaf8
9a83eee
 
 
 
278b050
9a83eee
356d5dd
9a83eee
1c024b6
9a83eee
69ecaf8
278b050
9a83eee
 
69ecaf8
9a83eee
 
69ecaf8
278b050
 
69ecaf8
 
278b050
69ecaf8
 
 
9a83eee
69ecaf8
 
 
278b050
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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)