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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import requests
|
| 3 |
+
import re
|
| 4 |
+
import time
|
| 5 |
+
import json
|
| 6 |
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 7 |
+
from threading import Lock
|
| 8 |
+
from datetime import datetime
|
| 9 |
+
import gradio as gr
|
| 10 |
+
|
| 11 |
+
# --- SABIT AYARLAR ---
|
| 12 |
+
TELEGRAM_TOKEN = "8782995167:AAEVSQC8z5Pc2TKOpLdAeGKSinSLfHFvT4Q"
|
| 13 |
+
TELEGRAM_CHAT_ID = "8577959776"
|
| 14 |
+
|
| 15 |
+
# --- SABIT TARAMA AYARLARI ---
|
| 16 |
+
START_USER = "ozkanturhan21"
|
| 17 |
+
MAX_DEPTH = 0 # 0 = sonsuz
|
| 18 |
+
MAX_USERS = 0 # 0 = sınırsız
|
| 19 |
+
MAX_THREADS = 3
|
| 20 |
+
|
| 21 |
+
# --- FIREBASE AYARLARI ---
|
| 22 |
+
FIREBASE_URL = "https://tiktokdata-73ad6-default-rtdb.firebaseio.com"
|
| 23 |
+
|
| 24 |
+
# --- TIKTOK COOKIE VE HEADER BİLGİLERİ ---
|
| 25 |
+
TIKTOK_CONFIG = {
|
| 26 |
+
"cookie": """tiktok_webapp_theme_source=auto; tiktok_webapp_theme=dark; delay_guest_mode_vid=5; cookie-consent={%22optional%22:false%2C%22ga%22:false%2C%22af%22:false%2C%22fbp%22:false%2C%22lip%22:false%2C%22bing%22:false%2C%22ttads%22:false%2C%22reddit%22:false%2C%22hubspot%22:false%2C%22version%22:%22v10%22}; tt_chain_token=hUHSaW841Anlho6xhguNpA==; d_ticket=3a6800342059a2ea865d696ec3860f55ca388; multi_sids=7304264194462073862%3Af9deb221250c36585cdfda3534464aa5; cmpl_token=AgQYAPOG-RfkTtK1YxsyWLadP_OgKTvwVL-FDWCgoo4; sid_guard=f9deb221250c36585cdfda3534464aa5%7C1774302411%7C15552000%7CSat%2C+19-Sep-2026+21%3A46%3A51+GMT; uid_tt=64ec4ce07df197c3dbdcf00f71aa6b38e545eb7f3c594585eec916493f5d5d73; uid_tt_ss=64ec4ce07df197c3dbdcf00f71aa6b38e545eb7f3c594585eec916493f5d5d73; sid_tt=f9deb221250c36585cdfda3534464aa5; sessionid=f9deb221250c36585cdfda3534464aa5; sessionid_ss=f9deb221250c36585cdfda3534464aa5; tt_session_tlb_tag=sttt%7C2%7C-d6yISUMNlhc39o1NEZKpf_________BAo4IenRTITJYIjINWVqDDZtS03mYV1VKa26Kf4pZQGs%3D; sid_ucp_v1=1.0.1-KDU4MTczNWM4MmZiYWQxZTEwMGQxZTQ3MGI3ZGM2YTA4MjQxMGM0ZjIKIgiGiJGE3bL9rmUQy-mGzgYYswsgDDCx6_eqBjgCQO8HSAQQAxoCbXkiIGY5ZGViMjIxMjUwYzM2NTg1Y2RmZGEzNTM0NDY0YWE1Mk4KIOxBbJTZs2KyC4hYIQ6WioypFwMLH5cEsTdIjfHt0dPREiCf-K2Q2ujaoYjHKH00aI-9YoPHWtsFZcu0Hgjvdol1BBgEIgZ0aWt0b2s; ssid_ucp_v1=1.0.1-KDU4MTczNWM4MmZiYWQxZTEwMGQxZTQ3MGI3ZGM2YTA4MjQxMGM0ZjIKIgiGiJGE3bL9rmUQy-mGzgYYswsgDDCx6_eqBjgCQO8HSAQQAxoCbXkiIGY5ZGViMjIxMjUwYzM2NTg1Y2RmZGEzNTM0NDY0YWE1Mk4KIOxBbJTZs2KyC4hYIQ6WioypFwMLH5cEsTdIjfHt0dPREiCf-K2Q2ujaoYjHKH00aI-9YoPHWtsFZcu0Hgjvdol1BBgEIgZ0aWt0b2s; store-idc=alisg; store-country-code=tr; store-country-code-src=uid; tt-target-idc=alisg; tt-target-idc-sign=MlKobDINrPpprIvmnjFtMA0ZhpedpYgPrzMmmH8ZzF61kwhLJUG8TdS_V_KYLQeBDRXlmAY2Jj8FDEVbEKwessgajRTf_hGrfuxtOHtI5jZeG-DRP7Tz6ZQzoITaiJUE0xN8ugqMfrW7EAkjhXqw4bKImBgcZ5MSOogogUdJz8szTz_mf97jgXnwOnBgmcHWBgl_IFffvqE8rr0qvWe0r6Ds1MsscsCviI3Wv-ZEMKyRFE4jn4IL4gukzb23h6IC3MSQJFjEyZkoeNwtj9fFcdO-B48bW9x118aSTkbnKHDQ5eMkogTx1VVo84VUlcHgqV4psgS08ZyuUpWHvlB65aGmGqWHH7iN1PaChxIaMhk0UFOnf5A_cEhCi0kNtnBCSDqYH_UOaycoKt7j4VQ8RCeVuSfwt3rE6jgnHdtiVAh2SnRWwDmLb8PrCbLYpRtXyk07noUaedrbr-j8jq85_3PxupJS5ShkvvGqceF-ufwZ_aXlCFE2tTg_nyUuvv4h; last_login_method=phone; tt_ticket_guard_has_set_public_key=1; ttwid=1%7C3cRywjZp1xzWhSMBFZhxJ2rbj7KtG6YwRCBAKCQpOIw%7C1774629598%7C09fb9a38dcbb0830df8775f3c21aeb49ab8b8c9f5d4412222c28f4d438673467; tt_csrf_token=uurqLaYM-TqGAy7EeqrqVWh0_qhP_BF0e4NU; _waftokenid=eyJ2Ijp7ImEiOiJCeXFNZmdnZ3pNZHhCYndkQlhoNFJHdWRRK0NRWVZHNm83a0lLK3NndXlFPSIsImIiOjE3NzQ2MzA3MzMsImMiOiJ1U3I4UVpTQXhsaHBQemtYVmVCd2dsc0pjL0J5QlNPNmVWVk5ER2ZCUXJjPSJ9LCJzIjoiZzBRSy9XNm5YSjA4dFlEem04VnJIT0N0MGo1NFFDUURPQ21aSG43T3U2WT0ifQ; passport_fe_beating_status=true; ttwid=1%7C3cRywjZp1xzWhSMBFZhxJ2rbj7KtG6YwRCBAKCQpOIw%7C1774630748%7C8022f58ef447d1f95f3d31195e86a7b500e160b8eefde9903c2d8cbaebf35cdc; store-country-sign=MEIEDEzU-4YtQLQSjKq2dwQg2S3nB90sD4YBmXIx0WT2eYmtPpCVECUiF0hNwzGmkYsEEFuWbUX9n0qvRgxnLUeZ5DQ; odin_tt=f9c7e51a151980c1e064a455a9d2392992dd091b614251f675815e864f86c63af489baa85f86ce93abf264941d7057b4ac2b0dd1eec068e908b6b6ade62db903e461a3aaf365e4b0eb458cde80a949c5; msToken=7Hpkq5PREqcXiOCni9rgc33NGQfhoLJk0uOtNoR-0WWuCp5-6ODhe9aUMs7l8J5h8uTYncvCRFlVWHdo2MMh_1pkGrrpoScBGyfVPuBmCE5OzrWkeN1jNuRCY0YIbOzPUH9tpCXldlx_JHDl0o_ILoqW_yuu2g==; msToken=H0mG9XMZX-vbjFnZ7uZKEQhMpksIDLTwLvlE8keWRDayD53UxpXxWuJW4d5EUSMJ8fTRQu6TMutsd79vxVmOCtPp_FVAQWUUmK4_t-Aq_U70RLaFXOeryJozUoo0LMIBRkqMr579jzKvGt6PeBDIolZcJ2E4r_c=; perf_feed_cache={%22expireTimestamp%22:1774800000000%2C%22itemIds%22:[%227619476359911394567%22%2C%227616849031356026133%22%2C%227621045537051020562%22]}""",
|
| 27 |
+
|
| 28 |
+
"user_agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
|
| 29 |
+
|
| 30 |
+
"ms_token": "H0mG9XMZX-vbjFnZ7uZKEQhMpksIDLTwLvlE8keWRDayD53UxpXxWuJW4d5EUSMJ8fTRQu6TMutsd79vxVmOCtPp_FVAQWUUmK4_t-Aq_U70RLaFXOeryJozUoo0LMIBRkqMr579jzKvGt6PeBDIolZcJ2E4r_c=",
|
| 31 |
+
|
| 32 |
+
"x_bogus": "DFSzsIVutxTANnUlCqsrkm6ViA-U"
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
# Global değişkenler
|
| 36 |
+
scraper = None
|
| 37 |
+
is_running = False
|
| 38 |
+
log_text = ""
|
| 39 |
+
|
| 40 |
+
def firebase_upload_user_data(username, data):
|
| 41 |
+
try:
|
| 42 |
+
user_url = f"{FIREBASE_URL}/data/{username}.json"
|
| 43 |
+
response = requests.put(user_url, json=data)
|
| 44 |
+
if response.status_code == 200:
|
| 45 |
+
print(f" ✅ @{username} Firebase'e yüklendi!")
|
| 46 |
+
return True
|
| 47 |
+
else:
|
| 48 |
+
print(f" ❌ @{username} Firebase hatası: {response.status_code}")
|
| 49 |
+
return False
|
| 50 |
+
except Exception as e:
|
| 51 |
+
print(f" ❌ @{username} Firebase bağlantı hatası: {e}")
|
| 52 |
+
return False
|
| 53 |
+
|
| 54 |
+
def firebase_get_existing_users():
|
| 55 |
+
try:
|
| 56 |
+
response = requests.get(f"{FIREBASE_URL}/data.json")
|
| 57 |
+
if response.status_code == 200:
|
| 58 |
+
data = response.json()
|
| 59 |
+
if data and isinstance(data, dict):
|
| 60 |
+
return set(data.keys())
|
| 61 |
+
return set()
|
| 62 |
+
except:
|
| 63 |
+
return set()
|
| 64 |
+
|
| 65 |
+
def send_telegram_message(message):
|
| 66 |
+
url = f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendMessage"
|
| 67 |
+
try:
|
| 68 |
+
data = {'chat_id': TELEGRAM_CHAT_ID, 'text': message, 'parse_mode': 'HTML'}
|
| 69 |
+
r = requests.post(url, data=data, timeout=15)
|
| 70 |
+
if r.status_code == 200:
|
| 71 |
+
print(f"✅ Telegram mesajı gönderildi!")
|
| 72 |
+
return True
|
| 73 |
+
else:
|
| 74 |
+
print(f"❌ Telegram gönderim hatası: {r.text}")
|
| 75 |
+
return False
|
| 76 |
+
except Exception as e:
|
| 77 |
+
print(f"❌ Mesaj gönderilemedi: {e}")
|
| 78 |
+
return False
|
| 79 |
+
|
| 80 |
+
class TikTokViralScraper:
|
| 81 |
+
def __init__(self, max_depth, max_users, max_threads, start_user):
|
| 82 |
+
self.headers = {
|
| 83 |
+
'authority': 'www.tiktok.com',
|
| 84 |
+
'accept': 'application/json',
|
| 85 |
+
'cookie': TIKTOK_CONFIG['cookie'],
|
| 86 |
+
'user-agent': TIKTOK_CONFIG['user_agent'],
|
| 87 |
+
'referer': 'https://www.tiktok.com/',
|
| 88 |
+
'accept-language': 'tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7',
|
| 89 |
+
'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="124", "Google Chrome";v="124"',
|
| 90 |
+
'sec-ch-ua-mobile': '?0',
|
| 91 |
+
'sec-ch-ua-platform': '"Chrome OS"',
|
| 92 |
+
'sec-fetch-dest': 'empty',
|
| 93 |
+
'sec-fetch-mode': 'cors',
|
| 94 |
+
'sec-fetch-site': 'same-origin'
|
| 95 |
+
}
|
| 96 |
+
self.x_bogus = TIKTOK_CONFIG['x_bogus']
|
| 97 |
+
self.ms_token = TIKTOK_CONFIG['ms_token']
|
| 98 |
+
self.processed_users = set()
|
| 99 |
+
self.processed_users_lock = Lock()
|
| 100 |
+
self.processed_videos = set()
|
| 101 |
+
self.videos_lock = Lock()
|
| 102 |
+
self.max_depth = max_depth
|
| 103 |
+
self.max_users = max_users
|
| 104 |
+
self.max_threads = max_threads
|
| 105 |
+
self.start_user = start_user
|
| 106 |
+
self.existing_users = firebase_get_existing_users()
|
| 107 |
+
self.total_uploaded = 0
|
| 108 |
+
self.total_comments = 0
|
| 109 |
+
self.total_videos = 0
|
| 110 |
+
|
| 111 |
+
def get_all_video_ids(self, username):
|
| 112 |
+
try:
|
| 113 |
+
# yt-dlp'yi subprocess ile çalıştır
|
| 114 |
+
import subprocess
|
| 115 |
+
komut = f"yt-dlp --flat-playlist --get-id https://www.tiktok.com/@{username} 2>/dev/null"
|
| 116 |
+
result = subprocess.getoutput(komut).splitlines()
|
| 117 |
+
return [vid for vid in result if vid and vid.isdigit()]
|
| 118 |
+
except:
|
| 119 |
+
return []
|
| 120 |
+
|
| 121 |
+
def get_reposted_video_ids(self, username):
|
| 122 |
+
try:
|
| 123 |
+
import subprocess
|
| 124 |
+
komut = f"yt-dlp --flat-playlist --get-id https://www.tiktok.com/@{username}?tab=repost 2>/dev/null"
|
| 125 |
+
result = subprocess.getoutput(komut).splitlines()
|
| 126 |
+
return [vid for vid in result if vid and vid.isdigit()]
|
| 127 |
+
except:
|
| 128 |
+
return []
|
| 129 |
+
|
| 130 |
+
def fetch_comments_from_video(self, video_id, username, depth):
|
| 131 |
+
cursor = 0
|
| 132 |
+
has_more = True
|
| 133 |
+
comments_data = []
|
| 134 |
+
max_retries = 3
|
| 135 |
+
retry_count = 0
|
| 136 |
+
|
| 137 |
+
while has_more and retry_count < max_retries:
|
| 138 |
+
url = "https://www.tiktok.com/api/comment/list/"
|
| 139 |
+
params = {
|
| 140 |
+
'aweme_id': video_id,
|
| 141 |
+
'count': '100',
|
| 142 |
+
'cursor': str(cursor),
|
| 143 |
+
'aid': '1988',
|
| 144 |
+
'msToken': self.ms_token,
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
if self.x_bogus:
|
| 148 |
+
params['X-Bogus'] = self.x_bogus
|
| 149 |
+
|
| 150 |
+
try:
|
| 151 |
+
r = requests.get(url, headers=self.headers, params=params, timeout=15)
|
| 152 |
+
|
| 153 |
+
if r.status_code == 429:
|
| 154 |
+
wait_time = 5
|
| 155 |
+
print(f" ⏳ Rate limit, {wait_time} saniye bekleniyor...")
|
| 156 |
+
time.sleep(wait_time)
|
| 157 |
+
retry_count += 1
|
| 158 |
+
continue
|
| 159 |
+
|
| 160 |
+
if r.status_code != 200:
|
| 161 |
+
print(f" [!] HTTP {r.status_code}: {video_id[:10]}...")
|
| 162 |
+
break
|
| 163 |
+
|
| 164 |
+
data = r.json()
|
| 165 |
+
|
| 166 |
+
comments = []
|
| 167 |
+
if 'comments' in data and isinstance(data['comments'], list):
|
| 168 |
+
comments = data['comments']
|
| 169 |
+
elif 'data' in data and 'comments' in data['data']:
|
| 170 |
+
comments = data['data']['comments']
|
| 171 |
+
|
| 172 |
+
if not comments:
|
| 173 |
+
break
|
| 174 |
+
|
| 175 |
+
for c in comments:
|
| 176 |
+
user_data = c.get('user', {})
|
| 177 |
+
commenter = user_data.get('unique_id', user_data.get('uid', 'bilinmiyor'))
|
| 178 |
+
commenter_id = user_data.get('uid', '')
|
| 179 |
+
comment_text = c.get('text', '').replace('\n', ' ').replace('\r', '')
|
| 180 |
+
digg_count = c.get('digg_count', 0)
|
| 181 |
+
create_time = c.get('create_time', 0)
|
| 182 |
+
|
| 183 |
+
reply_comments = []
|
| 184 |
+
reply_count = c.get('reply_comment_total', 0)
|
| 185 |
+
|
| 186 |
+
if reply_count > 0:
|
| 187 |
+
reply_cursor = 0
|
| 188 |
+
while reply_cursor < reply_count:
|
| 189 |
+
reply_url = "https://www.tiktok.com/api/comment/list/reply/"
|
| 190 |
+
reply_params = {
|
| 191 |
+
'aweme_id': video_id,
|
| 192 |
+
'comment_id': c.get('cid', ''),
|
| 193 |
+
'count': '50',
|
| 194 |
+
'cursor': str(reply_cursor),
|
| 195 |
+
'aid': '1988'
|
| 196 |
+
}
|
| 197 |
+
try:
|
| 198 |
+
reply_r = requests.get(reply_url, headers=self.headers, params=reply_params, timeout=10)
|
| 199 |
+
if reply_r.status_code == 200:
|
| 200 |
+
reply_data = reply_r.json()
|
| 201 |
+
replies = reply_data.get('comments', [])
|
| 202 |
+
for reply in replies:
|
| 203 |
+
reply_user = reply.get('user', {})
|
| 204 |
+
reply_comments.append({
|
| 205 |
+
'commenter': reply_user.get('unique_id', ''),
|
| 206 |
+
'commenter_id': reply_user.get('uid', ''),
|
| 207 |
+
'comment': reply.get('text', '').replace('\n', ' '),
|
| 208 |
+
'is_reply': True,
|
| 209 |
+
'digg_count': reply.get('digg_count', 0)
|
| 210 |
+
})
|
| 211 |
+
reply_cursor = reply_data.get('cursor', reply_cursor + 50)
|
| 212 |
+
time.sleep(0.1)
|
| 213 |
+
else:
|
| 214 |
+
break
|
| 215 |
+
except:
|
| 216 |
+
break
|
| 217 |
+
|
| 218 |
+
comments_data.append({
|
| 219 |
+
'video_id': video_id,
|
| 220 |
+
'commenter': commenter,
|
| 221 |
+
'commenter_id': commenter_id,
|
| 222 |
+
'comment': comment_text,
|
| 223 |
+
'depth': depth,
|
| 224 |
+
'digg_count': digg_count,
|
| 225 |
+
'create_time': create_time,
|
| 226 |
+
'reply_count': reply_count,
|
| 227 |
+
'replies': reply_comments
|
| 228 |
+
})
|
| 229 |
+
|
| 230 |
+
has_more = data.get('has_more', 0) == 1
|
| 231 |
+
cursor = data.get('cursor', cursor + 100)
|
| 232 |
+
time.sleep(0.2)
|
| 233 |
+
retry_count = 0
|
| 234 |
+
|
| 235 |
+
except json.JSONDecodeError as e:
|
| 236 |
+
print(f" [!] JSON Hatası: {e}")
|
| 237 |
+
break
|
| 238 |
+
except Exception as e:
|
| 239 |
+
print(f" [!] Hata: {str(e)[:50]}")
|
| 240 |
+
retry_count += 1
|
| 241 |
+
time.sleep(2)
|
| 242 |
+
|
| 243 |
+
return comments_data
|
| 244 |
+
|
| 245 |
+
def upload_user_to_firebase(self, username, comments, video_count, depth):
|
| 246 |
+
if not comments:
|
| 247 |
+
empty_data = {
|
| 248 |
+
'username': username,
|
| 249 |
+
'depth': depth,
|
| 250 |
+
'total_videos': video_count,
|
| 251 |
+
'total_comments': 0,
|
| 252 |
+
'last_updated': datetime.now().isoformat(),
|
| 253 |
+
'videos': {}
|
| 254 |
+
}
|
| 255 |
+
firebase_upload_user_data(username, empty_data)
|
| 256 |
+
return
|
| 257 |
+
|
| 258 |
+
user_data = {
|
| 259 |
+
'username': username,
|
| 260 |
+
'depth': depth,
|
| 261 |
+
'total_videos': video_count,
|
| 262 |
+
'total_comments': len(comments),
|
| 263 |
+
'last_updated': datetime.now().isoformat(),
|
| 264 |
+
'videos': {}
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
video_comments = {}
|
| 268 |
+
for comment in comments:
|
| 269 |
+
video_id = comment['video_id']
|
| 270 |
+
if video_id not in video_comments:
|
| 271 |
+
video_comments[video_id] = []
|
| 272 |
+
video_comments[video_id].append(comment)
|
| 273 |
+
|
| 274 |
+
for video_id, video_comment_list in video_comments.items():
|
| 275 |
+
user_data['videos'][video_id] = {
|
| 276 |
+
'comments': []
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
for comment in video_comment_list:
|
| 280 |
+
comment_entry = {
|
| 281 |
+
'commenter': comment['commenter'],
|
| 282 |
+
'commenter_id': comment['commenter_id'],
|
| 283 |
+
'comment': comment['comment'],
|
| 284 |
+
'digg_count': comment['digg_count'],
|
| 285 |
+
'reply_count': comment['reply_count']
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
if comment.get('replies'):
|
| 289 |
+
comment_entry['replies'] = []
|
| 290 |
+
for reply in comment['replies']:
|
| 291 |
+
comment_entry['replies'].append({
|
| 292 |
+
'commenter': reply['commenter'],
|
| 293 |
+
'commenter_id': reply['commenter_id'],
|
| 294 |
+
'comment': reply['comment'],
|
| 295 |
+
'digg_count': reply['digg_count']
|
| 296 |
+
})
|
| 297 |
+
|
| 298 |
+
user_data['videos'][video_id]['comments'].append(comment_entry)
|
| 299 |
+
|
| 300 |
+
success = firebase_upload_user_data(username, user_data)
|
| 301 |
+
|
| 302 |
+
if success:
|
| 303 |
+
self.total_uploaded += 1
|
| 304 |
+
self.total_comments += len(comments)
|
| 305 |
+
self.total_videos += video_count
|
| 306 |
+
|
| 307 |
+
caption = f"🦠 <b>YENİ KULLANICI TARANDI!</b>\n\n" \
|
| 308 |
+
f"👤 <b>Kullanıcı:</b> @{username}\n" \
|
| 309 |
+
f"📊 <b>Derinlik:</b> Seviye {depth}\n" \
|
| 310 |
+
f"🎬 <b>Video:</b> {video_count}\n" \
|
| 311 |
+
f"💬 <b>Yorum:</b> {len(comments)}\n" \
|
| 312 |
+
f"🕐 <b>Zaman:</b> {datetime.now().strftime('%H:%M:%S')}"
|
| 313 |
+
|
| 314 |
+
send_telegram_message(caption)
|
| 315 |
+
|
| 316 |
+
def process_user(self, username, depth=0):
|
| 317 |
+
with self.processed_users_lock:
|
| 318 |
+
if username in self.processed_users or username in self.existing_users:
|
| 319 |
+
return []
|
| 320 |
+
if self.max_users > 0 and len(self.processed_users) >= self.max_users:
|
| 321 |
+
return []
|
| 322 |
+
self.processed_users.add(username)
|
| 323 |
+
|
| 324 |
+
indent = " " * depth
|
| 325 |
+
print(f"{indent}[*] İşleniyor: @{username} (Derinlik: {depth})")
|
| 326 |
+
|
| 327 |
+
video_ids = self.get_all_video_ids(username)
|
| 328 |
+
repost_ids = self.get_reposted_video_ids(username)
|
| 329 |
+
all_videos = list(set(video_ids + repost_ids))
|
| 330 |
+
|
| 331 |
+
if not all_videos:
|
| 332 |
+
print(f"{indent} [-] Video bulunamadı veya hesap gizli/kısıtlı.")
|
| 333 |
+
self.upload_user_to_firebase(username, [], 0, depth)
|
| 334 |
+
return []
|
| 335 |
+
|
| 336 |
+
print(f"{indent} [*] {len(all_videos)} video bulundu.")
|
| 337 |
+
|
| 338 |
+
all_comments = []
|
| 339 |
+
commenters_set = set()
|
| 340 |
+
|
| 341 |
+
for i, video_id in enumerate(all_videos):
|
| 342 |
+
with self.videos_lock:
|
| 343 |
+
if video_id in self.processed_videos:
|
| 344 |
+
continue
|
| 345 |
+
self.processed_videos.add(video_id)
|
| 346 |
+
|
| 347 |
+
print(f"{indent} [{i+1}/{len(all_videos)}] Video: {video_id[:8]}... yorumlar çekiliyor", end="\r")
|
| 348 |
+
|
| 349 |
+
comments = self.fetch_comments_from_video(video_id, username, depth)
|
| 350 |
+
|
| 351 |
+
if comments:
|
| 352 |
+
all_comments.extend(comments)
|
| 353 |
+
for c in comments:
|
| 354 |
+
if c['commenter'] and c['commenter'] != 'bilinmiyor':
|
| 355 |
+
commenters_set.add(c['commenter'])
|
| 356 |
+
for reply in c.get('replies', []):
|
| 357 |
+
if reply['commenter'] and reply['commenter'] != 'bilinmiyor':
|
| 358 |
+
commenters_set.add(reply['commenter'])
|
| 359 |
+
|
| 360 |
+
time.sleep(0.3)
|
| 361 |
+
|
| 362 |
+
print(f"{indent} [*] Toplam {len(all_comments)} yorum çekildi.")
|
| 363 |
+
|
| 364 |
+
self.upload_user_to_firebase(username, all_comments, len(all_videos), depth)
|
| 365 |
+
|
| 366 |
+
with self.processed_users_lock:
|
| 367 |
+
new_commenters = [c for c in commenters_set if c not in self.processed_users and c not in self.existing_users]
|
| 368 |
+
|
| 369 |
+
print(f"{indent} [+] {len(commenters_set)} benzersiz yorumcu, {len(new_commenters)} yeni kullanıcı keşfedildi.")
|
| 370 |
+
|
| 371 |
+
return new_commenters
|
| 372 |
+
|
| 373 |
+
def process_level(self, users, depth):
|
| 374 |
+
if not users:
|
| 375 |
+
return []
|
| 376 |
+
|
| 377 |
+
print(f"\n{'='*70}")
|
| 378 |
+
print(f"🔥 SEVİYE {depth} - {len(users)} kullanıcı işleniyor ({self.max_threads} thread ile)...")
|
| 379 |
+
print(f"{'='*70}")
|
| 380 |
+
|
| 381 |
+
all_new_users = []
|
| 382 |
+
completed = 0
|
| 383 |
+
|
| 384 |
+
with ThreadPoolExecutor(max_workers=self.max_threads) as executor:
|
| 385 |
+
future_to_user = {executor.submit(self.process_user, user, depth): user for user in users}
|
| 386 |
+
|
| 387 |
+
for future in as_completed(future_to_user):
|
| 388 |
+
user = future_to_user[future]
|
| 389 |
+
completed += 1
|
| 390 |
+
try:
|
| 391 |
+
new_users = future.result()
|
| 392 |
+
if new_users:
|
| 393 |
+
all_new_users.extend(new_users)
|
| 394 |
+
print(f"[{completed}/{len(users)}] ✅ @{user} → +{len(new_users)}")
|
| 395 |
+
else:
|
| 396 |
+
print(f"[{completed}/{len(users)}] ✅ @{user} → 0 yeni")
|
| 397 |
+
except Exception as e:
|
| 398 |
+
print(f"[{completed}/{len(users)}] ❌ @{user}: {str(e)[:50]}")
|
| 399 |
+
|
| 400 |
+
all_new_users = list(set(all_new_users))
|
| 401 |
+
|
| 402 |
+
with self.processed_users_lock:
|
| 403 |
+
all_new_users = [u for u in all_new_users if u not in self.processed_users and u not in self.existing_users]
|
| 404 |
+
|
| 405 |
+
if all_new_users:
|
| 406 |
+
send_telegram_message(f"📊 SEVİYE {depth} TAMAM! +{len(all_new_users)} yeni kullanıcı (Toplam: {len(self.processed_users)})")
|
| 407 |
+
|
| 408 |
+
return all_new_users
|
| 409 |
+
|
| 410 |
+
def start_viral_scan(self):
|
| 411 |
+
print(f"\n{'█'*70}")
|
| 412 |
+
print(f"🦠 VEBA MODU AKTİF - ANLIK FIREBASE YÜKLEME!")
|
| 413 |
+
print(f"{'█'*70}")
|
| 414 |
+
print(f"📱 Başlangıç: @{self.start_user}")
|
| 415 |
+
print(f"🔁 Derinlik: {'Sonsuz' if self.max_depth == 0 else f'{self.max_depth}'}")
|
| 416 |
+
print(f"👥 Maksimum Kullanıcı: {'Sınırsız' if self.max_users == 0 else self.max_users}")
|
| 417 |
+
print(f"⚙️ Thread: {self.max_threads}")
|
| 418 |
+
print(f"🔥 Firebase: {FIREBASE_URL}/data.json")
|
| 419 |
+
print(f"{'█'*70}\n")
|
| 420 |
+
|
| 421 |
+
start_time = time.time()
|
| 422 |
+
|
| 423 |
+
print(f"🚀 SEVİYE 0 - BAŞLANGIÇ KULLANICISI İŞLENİYOR...")
|
| 424 |
+
level0_users = self.process_user(self.start_user, depth=0)
|
| 425 |
+
|
| 426 |
+
current_level_users = level0_users
|
| 427 |
+
depth = 1
|
| 428 |
+
|
| 429 |
+
while current_level_users and (depth <= self.max_depth or self.max_depth == 0):
|
| 430 |
+
print(f"\n📢 {len(current_level_users)} YENİ KULLANICI KEŞFEDİLDİ, SEVİYE {depth} BAŞLIYOR...")
|
| 431 |
+
new_users = self.process_level(current_level_users, depth)
|
| 432 |
+
current_level_users = new_users
|
| 433 |
+
|
| 434 |
+
if self.max_users > 0 and len(self.processed_users) >= self.max_users:
|
| 435 |
+
print(f"\n⚠️ Maksimum kullanıcı limitine ulaşıldı! ({self.max_users})")
|
| 436 |
+
break
|
| 437 |
+
|
| 438 |
+
depth += 1
|
| 439 |
+
|
| 440 |
+
elapsed_time = time.time() - start_time
|
| 441 |
+
minutes = int(elapsed_time // 60)
|
| 442 |
+
seconds = int(elapsed_time % 60)
|
| 443 |
+
|
| 444 |
+
final_message = f"✅ VEBA TARAMASI TAMAMLANDI!\n\n" \
|
| 445 |
+
f"👤 Başlangıç: @{self.start_user}\n" \
|
| 446 |
+
f"⏱️ Süre: {minutes}dk {seconds}sn\n" \
|
| 447 |
+
f"👥 Toplam Kullanıcı: {len(self.processed_users)}\n" \
|
| 448 |
+
f"🎬 Taranan Video: {self.total_videos}\n" \
|
| 449 |
+
f"💬 Toplam Yorum: {self.total_comments}\n" \
|
| 450 |
+
f"🔥 Firebase: {FIREBASE_URL}/data.json"
|
| 451 |
+
|
| 452 |
+
send_telegram_message(final_message)
|
| 453 |
+
print(f"\n✅ TARAMA TAMAMLANDI!")
|
| 454 |
+
print(f"📊 Toplam {len(self.processed_users)} kullanıcı, {self.total_videos} video, {self.total_comments} yorum Firebase'e yüklendi!")
|
| 455 |
+
|
| 456 |
+
# --- GRADIO ARAYÜZÜ ---
|
| 457 |
+
def start_scan():
|
| 458 |
+
global scraper, is_running, log_text
|
| 459 |
+
|
| 460 |
+
if is_running:
|
| 461 |
+
return "⚠️ Tarama zaten çalışıyor!", ""
|
| 462 |
+
|
| 463 |
+
is_running = True
|
| 464 |
+
log_text = ""
|
| 465 |
+
|
| 466 |
+
try:
|
| 467 |
+
scraper = TikTokViralScraper(MAX_DEPTH, MAX_USERS, MAX_THREADS, START_USER)
|
| 468 |
+
scraper.start_viral_scan()
|
| 469 |
+
is_running = False
|
| 470 |
+
return "✅ Tarama tamamlandı!", "Tarama başarıyla tamamlandı. Firebase verilerini kontrol edin."
|
| 471 |
+
except Exception as e:
|
| 472 |
+
is_running = False
|
| 473 |
+
return f"❌ Hata: {str(e)}", ""
|
| 474 |
+
|
| 475 |
+
def get_status():
|
| 476 |
+
global scraper, is_running
|
| 477 |
+
if scraper:
|
| 478 |
+
return f"""
|
| 479 |
+
📊 **MEVCUT DURUM**
|
| 480 |
+
- İşlenen Kullanıcı: {len(scraper.processed_users)}
|
| 481 |
+
- Taranan Video: {scraper.total_videos}
|
| 482 |
+
- Toplam Yorum: {scraper.total_comments}
|
| 483 |
+
- Firebase: {FIREBASE_URL}/data.json
|
| 484 |
+
- Çalışıyor: {'✅ Evet' if is_running else '❌ Hayır'}
|
| 485 |
+
"""
|
| 486 |
+
return "Tarama başlatılmadı."
|
| 487 |
+
|
| 488 |
+
# Gradio arayüzü
|
| 489 |
+
with gr.Blocks(title="VEBA TikTok Scanner", theme=gr.themes.Soft()) as demo:
|
| 490 |
+
gr.Markdown("""
|
| 491 |
+
# 🦠 VEBA TikTok Scanner - Firebase Entegrasyonlu
|
| 492 |
+
|
| 493 |
+
Bu araç TikTok kullanıcılarının videolarındaki yorumları tarar ve Firebase'e yükler.
|
| 494 |
+
|
| 495 |
+
**Başlangıç Kullanıcısı:** @ozkanturhan21
|
| 496 |
+
**Firebase:** https://tiktokdata-73ad6-default-rtdb.firebaseio.com/data.json
|
| 497 |
+
""")
|
| 498 |
+
|
| 499 |
+
with gr.Row():
|
| 500 |
+
with gr.Column(scale=1):
|
| 501 |
+
start_btn = gr.Button("🚀 Taramayı Başlat", variant="primary", size="lg")
|
| 502 |
+
status_btn = gr.Button("📊 Durumu Kontrol Et", variant="secondary")
|
| 503 |
+
|
| 504 |
+
status_output = gr.Markdown("Tarama başlatılmadı.")
|
| 505 |
+
|
| 506 |
+
with gr.Column(scale=2):
|
| 507 |
+
output_text = gr.Textbox(
|
| 508 |
+
label="📋 Log Çıktısı",
|
| 509 |
+
lines=20,
|
| 510 |
+
max_lines=30,
|
| 511 |
+
interactive=False,
|
| 512 |
+
placeholder="Tarama logları burada görünecek..."
|
| 513 |
+
)
|
| 514 |
+
|
| 515 |
+
start_btn.click(
|
| 516 |
+
fn=start_scan,
|
| 517 |
+
inputs=[],
|
| 518 |
+
outputs=[status_output, output_text]
|
| 519 |
+
)
|
| 520 |
+
|
| 521 |
+
status_btn.click(
|
| 522 |
+
fn=get_status,
|
| 523 |
+
inputs=[],
|
| 524 |
+
outputs=status_output
|
| 525 |
+
)
|
| 526 |
+
|
| 527 |
+
gr.Markdown("""
|
| 528 |
+
---
|
| 529 |
+
### 📌 Bilgi
|
| 530 |
+
|
| 531 |
+
- Tarama başlatıldığında her kullanıcı Firebase'e yüklenir
|
| 532 |
+
- Telegram'a bildirim gönderilir
|
| 533 |
+
- Durdurmak için Space'i durdurmanız gerekir
|
| 534 |
+
- Veriler: https://tiktokdata-73ad6-default-rtdb.firebaseio.com/data.json
|
| 535 |
+
""")
|
| 536 |
+
|
| 537 |
+
if __name__ == "__main__":
|
| 538 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|