File size: 5,872 Bytes
69b885f
4cb4020
83a2f7b
4cb4020
 
6f15580
 
09d1e4c
 
0d3ebe0
 
 
c748144
 
10f6ba8
0d3ebe0
10f6ba8
0d3ebe0
 
 
10f6ba8
0d3ebe0
 
 
10f6ba8
6f15580
0d3ebe0
10f6ba8
 
04f3007
10f6ba8
0d3ebe0
04f3007
 
0d3ebe0
04f3007
 
 
 
 
 
 
 
 
0d3ebe0
04f3007
10f6ba8
0d3ebe0
 
69b885f
0d3ebe0
 
04f3007
10f6ba8
0d3ebe0
04f3007
10f6ba8
 
0d3ebe0
 
 
 
 
 
 
 
 
 
 
 
10f6ba8
0d3ebe0
 
 
10f6ba8
0d3ebe0
69b885f
0d3ebe0
10f6ba8
0d3ebe0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
04f3007
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import streamlit as st
import asyncio
import os
import time
import subprocess
import threading
from datetime import datetime
from TikTokLive import TikTokLiveClient

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
#  โš™๏ธ  ุงู„ุฅุนุฏุงุฏุงุช ุงู„ุซุงุจุชุฉ (ุชุนุฏู„ ู…ุฑุฉ ูˆุงุญุฏุฉ ูู‚ุท)
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
TIKTOK_USERNAME    = "@osei_iraq"           # ุงู„ุญุณุงุจ ุงู„ู…ุฑุงุฏ ุฑุตุฏู‡
YOUTUBE_STREAM_KEY = "p0ep-37wz-q3yg-7twf-3acb"  # ู…ูุชุงุญ ุจุซ ูŠูˆุชูŠูˆุจ
POLL_INTERVAL      = 60                  # ูุญุต ูƒู„ ุฏู‚ูŠู‚ุฉ
YT_RTMP_URL        = f"rtmp://a.rtmp.youtube.com/live2/{YOUTUBE_STREAM_KEY}"

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# ๐Ÿš€ ู…ุญุฑูƒ ุงู„ุนู…ู„ ููŠ ุงู„ุฎู„ููŠุฉ (Background Engine)
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

def run_monitor():
    """ู‡ุฐู‡ ุงู„ุฏุงู„ุฉ ู‡ูŠ ุงู„ุชูŠ ุชุธู„ ุชุนู…ู„ ุญุชู‰ ู„ูˆ ุฃุบู„ู‚ุช ุงู„ุตูุญุฉ"""
    print("โœ… ุจุฏุฃ ู…ุญุฑูƒ ุงู„ู…ุฑุงู‚ุจุฉ ุงู„ุชู„ู‚ุงุฆูŠ 24/7...")
    while True:
        try:
            # ูุญุต ุญุงู„ุฉ ุงู„ุจุซ
            client = TikTokLiveClient(unique_id=TIKTOK_USERNAME)
            is_live = asyncio.run(client.is_live())

            if is_live:
                print(f"[{datetime.now().strftime('%H:%M')}] ๐Ÿ”ด ุงู„ุจุซ ุจุฏุฃ! ุฌุงุฑูŠ ุงู„ู†ู‚ู„ ุฅู„ู‰ ูŠูˆุชูŠูˆุจ...")

                # ุฃู…ุฑ ุงู„ู†ู‚ู„ ุงู„ู…ุจุงุดุฑ - ู…ุญุณู‘ู† ู„ู„ุตูˆุช
                cmd = (
                    f"streamlink https://www.tiktok.com/{TIKTOK_USERNAME}/live best --hls-live-edge 3 --stdout | "
                    f"ffmpeg -thread_queue_size 8192 -i pipe:0 "
                    f"-c:v copy "
                    f"-c:a aac -ar 48000 -b:a 192k -ac 2 "
                    f"-af 'highpass=f=200,lowpass=f=3000,aresample=async=1' "
                    f"-buffer_size 1024k "
                    f"-fflags +genpts+igndts "
                    f"-max_interleave_delta 0 "
                    f"-f flv {YT_RTMP_URL}"
                )

                process = subprocess.Popen(cmd, shell=True)
                process.wait() # ุณูŠู†ุชุธุฑ ู‡ู†ุง ุญุชู‰ ูŠู†ุชู‡ูŠ ุงู„ุจุซ ูุนู„ูŠุงู‹
                print("โน๏ธ ุงู†ุชู‡ู‰ ุงู„ุจุซุŒ ุงู„ุนูˆุฏุฉ ู„ูˆุถุน ุงู„ู…ุฑุงู‚ุจุฉ...")
            else:
                #print(f"๐Ÿ” ูุญุต: {TIKTOK_USERNAME} ุบูŠุฑ ู…ุชุตู„ ุญุงู„ูŠุงู‹.")
                pass

        except Exception as e:
            print(f"โš ๏ธ ุชู†ุจูŠู‡: {e}")

        time.sleep(POLL_INTERVAL)

# ุชุดุบูŠู„ ุงู„ุฎูŠุท ุงู„ุฎู„ููŠ ููˆุฑ ุชุดุบูŠู„ ุงู„ุชุทุจูŠู‚ (ู…ุฑุฉ ูˆุงุญุฏุฉ ูู‚ุท)
if "background_started" not in st.session_state:
    # ุงู„ุจุญุซ ุนู† ุฃูŠ ุฎูŠุท ูŠุนู…ู„ ู…ุณุจู‚ุงู‹ ู„ู…ู†ุน ุงู„ุชูƒุฑุงุฑ
    for thread in threading.enumerate():
        if thread.name == "TikTokMonitorThread":
            st.session_state.background_started = True
            break
    else:
        # ุฅุฐุง ู„ู… ูŠูƒู† ู‡ู†ุงูƒ ุฎูŠุทุŒ ู†ุจุฏุฃ ูˆุงุญุฏ ุฌุฏูŠุฏ
        monitor_thread = threading.Thread(target=run_monitor, name="TikTokMonitorThread", daemon=True)
        monitor_thread.start()
        st.session_state.background_started = True

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# ๐ŸŽจ ูˆุงุฌู‡ุฉ ุงู„ู…ุณุชุฎุฏู… (ู„ู„ู…ุชุงุจุนุฉ ูู‚ุท)
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

st.set_page_config(page_title="AutoStreamer 24/7", page_icon="๐Ÿ”ด")

# ุชู†ุณูŠู‚ ุงู„ุดูƒู„
st.markdown("""
<style>
    .status-box {
        padding: 20px; border-radius: 15px; background-color: #0e1117;
        border: 1px solid #262730; text-align: center;
    }
    .live-tag { color: #ff4b4b; font-weight: bold; animation: pulse 2s infinite; }
    @keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } }
</style>
""", unsafe_allow_html=True)

st.title("๐Ÿ”ด ู†ุธุงู… ุงู„ุจุซ ุงู„ุชู„ู‚ุงุฆูŠ ุงู„ู…ุณุชู…ุฑ")

st.markdown(f"""
<div class="status-box">
    <h3>ุญุงู„ุฉ ุงู„ู†ุธุงู…: <span style="color: #00ff00;">ู…ุชุตู„ ูˆูŠุนู…ู„ โœ…</span></h3>
    <p>ูŠุชู… ู…ุฑุงู‚ุจุฉ ุงู„ุญุณุงุจ: <b>{TIKTOK_USERNAME}</b></p>
    <p class="live-tag">ุงู„ู†ุธุงู… ูŠุนู…ู„ ููŠ ุฎู„ููŠุฉ ุงู„ุณูŠุฑูุฑ ุงู„ุขู†</p>
</div>
""", unsafe_allow_html=True)

st.success("โ„น๏ธ ูŠู…ูƒู†ูƒ ุฅุบู„ุงู‚ ู‡ุฐู‡ ุงู„ุตูุญุฉ ุงู„ุขู†. ุงู„ุณูŠุฑูุฑ ุณูŠู‚ูˆู… ุจุฑุตุฏ ุงู„ุจุซ ูˆุฑูุนู‡ ุชู„ู‚ุงุฆูŠุงู‹ ููŠ ุฃูŠ ูˆู‚ุช (ุงู„ูŠูˆู…ุŒ ุบุฏุงู‹ุŒ ุฃูˆ ุฃูŠ ูˆู‚ุช).")

st.info("๐Ÿ’ก ุจู…ุฌุฑุฏ ุฃู† ูŠุจุฏุฃ ุตุงุญุจ ุงู„ุญุณุงุจ ุงู„ุจุซุŒ ุณูŠู‚ูˆู… ุงู„ู†ุธุงู… ุจูุชุญู‡ ููˆุฑุงู‹ ูˆู†ู‚ู„ู‡ ุฅู„ู‰ ู‚ู†ุงุชูƒ ุนู„ู‰ ูŠูˆุชูŠูˆุจ.")

# ุนุฑุถ ุงู„ุณุฌู„ุงุช ุงู„ุจุณูŠุทุฉ
if st.button("ุชุญุฏูŠุซ ุงู„ุญุงู„ุฉ"):
    st.rerun()

st.write(f"ุขุฎุฑ ูุญุต ุชู… ููŠ: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")