Spaces:
Paused

Reoo88 commited on
Commit
e4b26dc
·
verified ·
1 Parent(s): dfc5626

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +9 -55
streamlit_app.py CHANGED
@@ -1,69 +1,23 @@
1
- import os, time, asyncio, threading, urllib.request, subprocess
 
2
  import streamlit as st
3
- from TikTokLive import TikTokLiveClient
4
- from TikTokLive.events import CommentEvent, ConnectEvent
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_FILE = "/tmp/comments.txt"
10
-
11
- if not os.path.exists(FONT_PATH):
12
- urllib.request.urlretrieve(FONT_URL, FONT_PATH)
13
-
14
- comments_list, lock = [], threading.Lock()
15
-
16
- def update_file():
17
- with lock:
18
- text = "\n".join(comments_list[-10:])
19
- with open(COMMENTS_FILE, "w", encoding="utf-8") as f:
20
- f.write(text)
21
-
22
- async def fetch_comments(username, proxy_url):
23
- client = TikTokLiveClient(
24
- unique_id=f"@{username}",
25
- web_proxy=proxy_url
26
- )
27
- @client.on(ConnectEvent)
28
- async def on_connect(_):
29
- print("✅ متصل بالتعليقات عبر الوكيل")
30
- @client.on(CommentEvent)
31
- async def on_comment(e):
32
- user = e.user.nickname or e.user.unique_id
33
- with lock:
34
- comments_list.append(f"{user}: {e.comment}")
35
- update_file()
36
- await client.start()
37
-
38
- def run_comments(username, proxy_url):
39
- loop = asyncio.new_event_loop()
40
- asyncio.set_event_loop(loop)
41
- loop.run_until_complete(fetch_comments(username, proxy_url))
42
-
43
- def start_stream(yt_key, username, proxy_url):
44
- with open(COMMENTS_FILE, "w", encoding="utf-8") as f:
45
- f.write("")
46
- threading.Thread(target=run_comments, args=(username, proxy_url), daemon=True).start()
47
- time.sleep(5)
48
  sl_cmd = f"streamlink https://www.tiktok.com/@{username}/live best --hls-live-edge 3 --stdout"
49
  ff_cmd = (
50
  f"ffmpeg -thread_queue_size 8192 -i pipe:0 "
51
- f"-filter_complex \"[0:v]scale=720:1280,"
52
- f"drawtext=textfile='{COMMENTS_FILE}':reload=1:fontfile={FONT_PATH}:fontsize=26:fontcolor=white:"
53
- f"x=10:y='h - mod(t*40, (h+200))':shadowx=2:shadowy=2:shadowcolor=black@0.6:bordercolor=black@0.3:borderw=1[outv]\" "
54
- f"-map \"[outv]\" -map 0:a? "
55
- f"-c:v libx264 -preset ultrafast -tune zerolatency -b:v 1500k -maxrate 2000k -bufsize 3000k -g 30 "
56
  f"-c:a aac -ar 48000 -b:a 192k -ac 2 "
57
  f"-f flv rtmp://a.rtmp.youtube.com/live2/{yt_key}"
58
  )
59
- subprocess.Popen(f"{sl_cmd} | {ff_cmd}", shell=True).wait()
 
60
 
61
- st.title("بث تيك توك مع تعليقات (Proxy)")
62
  with st.form("f"):
63
  user = st.text_input("معرف تيك توك", "s.og94")
64
  key = st.text_input("مفتاح يوتيوب", type="password")
65
- proxy = st.text_input("وكيل HTTP", "http://157.15.63.83:8080")
66
  if st.form_submit_button("ابدأ"):
67
  if user and key:
68
- threading.Thread(target=start_stream, args=(key, user, proxy)).start()
69
- st.success("تم البث! انتظر ظهور التعليقات...")
 
1
+ import subprocess
2
+ import threading
3
  import streamlit as st
 
 
4
 
5
+ def start_stream(yt_key, username):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  sl_cmd = f"streamlink https://www.tiktok.com/@{username}/live best --hls-live-edge 3 --stdout"
7
  ff_cmd = (
8
  f"ffmpeg -thread_queue_size 8192 -i pipe:0 "
9
+ f"-c:v copy "
 
 
 
 
10
  f"-c:a aac -ar 48000 -b:a 192k -ac 2 "
11
  f"-f flv rtmp://a.rtmp.youtube.com/live2/{yt_key}"
12
  )
13
+ full_cmd = f"{sl_cmd} | {ff_cmd}"
14
+ subprocess.Popen(full_cmd, shell=True).wait()
15
 
16
+ st.title("بث تيك توك إلى يوتيوب")
17
  with st.form("f"):
18
  user = st.text_input("معرف تيك توك", "s.og94")
19
  key = st.text_input("مفتاح يوتيوب", type="password")
 
20
  if st.form_submit_button("ابدأ"):
21
  if user and key:
22
+ threading.Thread(target=start_stream, args=(key, user)).start()
23
+ st.success("تم البث!")