chore: cleanup irrelevant files and debug scripts

This commit is contained in:
Khoa Vo 2026-01-25 18:59:58 +07:00
parent 05beadb055
commit 43f7b1b831
16 changed files with 3 additions and 667 deletions

View file

@ -1,44 +0,0 @@
import asyncio
import httpx
import sys
from core.playwright_manager import PlaywrightManager
async def test_api():
print("Loading credentials...")
cookies, user_agent = PlaywrightManager.load_stored_credentials()
headers = {
"User-Agent": user_agent or "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"Referer": "https://www.tiktok.com/",
"Cookie": "; ".join([f"{c['name']}={c['value']}" for c in cookies]),
}
username = "x.ka.baongoc"
url = f"https://www.tiktok.com/api/user/detail/?uniqueId={username}"
print(f"Fetching {url}...")
async with httpx.AsyncClient(timeout=10.0, follow_redirects=True) as client:
res = await client.get(url, headers=headers)
print(f"Status: {res.status_code}")
if res.status_code == 200:
try:
data = res.json()
user = data.get("userInfo", {}).get("user", {})
sec_uid = user.get("secUid")
print(f"SecUid: {sec_uid}")
if not sec_uid:
print("Response body preview:", str(data)[:500])
except:
print("JSON Decode Failed. Content preview:")
print(res.text[:500])
else:
print("Response:", res.text[:500])
if __name__ == "__main__":
try:
if sys.platform == "win32":
loop = asyncio.ProactorEventLoop()
asyncio.set_event_loop(loop)
loop.run_until_complete(test_api())
except Exception as e:
print(e)

View file

@ -1,17 +0,0 @@
import asyncio
from backend.core.playwright_manager import PlaywrightManager
async def test_search():
print("Testing search_videos with STORED COOKIES...")
cookies, ua = PlaywrightManager.load_stored_credentials()
print(f"Loaded {len(cookies)} cookies. UA: {ua[:50]}...")
videos = await PlaywrightManager.search_videos("gai xinh nhay", cookies=cookies, user_agent=ua, limit=5)
print(f"Found {len(videos)} videos.")
for i, v in enumerate(videos):
play_addr = v.get("video", {}).get("play_addr")
print(f"Video {i} Play Addr: {play_addr}")
if __name__ == "__main__":
asyncio.run(test_search())

View file

@ -461,7 +461,7 @@ export const VideoPlayer: React.FC<VideoPlayerProps> = ({
)} )}
{/* Video Timeline/Progress Bar */} {/* Video Timeline/Progress Bar */}
<div className="absolute bottom-0 left-0 right-0 z-30"> <div className="absolute bottom-0 left-0 right-0 z-50">
<div <div
ref={progressBarRef} ref={progressBarRef}
className={`h-2 bg-white/20 cursor-pointer group ${isSeeking ? 'h-3' : ''}`} className={`h-2 bg-white/20 cursor-pointer group ${isSeeking ? 'h-3' : ''}`}
@ -496,7 +496,7 @@ export const VideoPlayer: React.FC<VideoPlayerProps> = ({
{/* Side Controls - Always visible on hover or when paused */} {/* Side Controls - Always visible on hover or when paused */}
<div <div
className={`absolute bottom-36 right-4 flex flex-col gap-3 transition-all duration-300 transform ${showControls || isPaused ? 'translate-x-0 opacity-100' : 'translate-x-2 opacity-0' className={`absolute bottom-36 right-4 flex flex-col gap-3 transition-all duration-300 transform z-40 ${showControls || isPaused ? 'translate-x-0 opacity-100' : 'translate-x-2 opacity-0'
}`} }`}
> >
{/* Follow Button */} {/* Follow Button */}
@ -535,7 +535,7 @@ export const VideoPlayer: React.FC<VideoPlayerProps> = ({
</div> </div>
{/* Author Info - Only show when video is paused */} {/* Author Info - Only show when video is paused */}
<div className={`absolute bottom-10 left-4 right-20 z-10 transition-opacity duration-300 ${isPaused ? 'opacity-100' : 'opacity-0 pointer-events-none'}`}> <div className={`absolute bottom-10 left-4 right-20 z-20 transition-opacity duration-300 ${isPaused ? 'opacity-100' : 'opacity-0 pointer-events-none'}`}>
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<button <button
onClick={(e) => { onClick={(e) => {

View file

@ -1,2 +0,0 @@
$env:PYTHONPATH = "c:\Users\Admin\Downloads\kv-tiktok\backend"
& "c:\Users\Admin\Downloads\kv-tiktok\.venv\Scripts\python.exe" tests/debug_search.py

View file

@ -1,3 +0,0 @@
@echo off
cd /d "%~dp0"
powershell -ExecutionPolicy Bypass -File manage_app.ps1 start

View file

@ -1,4 +0,0 @@
@echo off
cd /d "%~dp0"
powershell -ExecutionPolicy Bypass -File manage_app.ps1 stop
pause

View file

@ -1,314 +0,0 @@
{
"credentials": [
{
"domain": ".www.tiktok.com",
"expirationDate": 1784039026,
"hostOnly": false,
"httpOnly": false,
"name": "delay_guest_mode_vid",
"path": "/",
"sameSite": null,
"secure": true,
"session": false,
"storeId": null,
"value": "8"
},
{
"domain": ".tiktok.com",
"expirationDate": 1768131143.251207,
"hostOnly": false,
"httpOnly": false,
"name": "msToken",
"path": "/",
"sameSite": "no_restriction",
"secure": true,
"session": false,
"storeId": null,
"value": "jntmMFSrdBzHw3GQQ7xigi2HLM03wLgd2s8xW8sa8bm3gVg-VJu63FlYSfvPAW6tmoNM-Ww9ho9sOKZc75EN1XIGwct0ndkyOairFWbXgkiFwPXfDpQaBA9pn2_9mSOYSylT1H60yH1ufg=="
},
{
"domain": ".tiktok.com",
"expirationDate": 1782817620.646103,
"hostOnly": false,
"httpOnly": true,
"name": "tt_session_tlb_tag",
"path": "/",
"sameSite": "no_restriction",
"secure": true,
"session": false,
"storeId": null,
"value": "sttt%7C1%7C6M35zM57kkqAGSs_LSUdRP_________zyplxYaEARSr2PNU_6cKcB0lq4WRz1GKKY43u399i5hs%3D"
},
{
"domain": ".tiktok.com",
"expirationDate": 1798369620.645922,
"hostOnly": false,
"httpOnly": true,
"name": "sid_guard",
"path": "/",
"sameSite": null,
"secure": true,
"session": false,
"storeId": null,
"value": "e8cdf9ccce7b924a80192b3f2d251d44%7C1767265616%7C15552000%7CTue%2C+30-Jun-2026+11%3A06%3A56+GMT"
},
{
"domain": ".tiktok.com",
"expirationDate": 1798801628.385793,
"hostOnly": false,
"httpOnly": true,
"name": "ttwid",
"path": "/",
"sameSite": "no_restriction",
"secure": true,
"session": false,
"storeId": null,
"value": "1%7CAYDsetgnxt5vzYX8hD6Wq2DQ4FXiL_pqcdLwHWwz6B8%7C1767265624%7C6121d82381fb651afeae94341e45b87fca1d903fbec0d8a19e4dd5440a89a424"
},
{
"domain": ".www.tiktok.com",
"expirationDate": 1767870430,
"hostOnly": false,
"httpOnly": false,
"name": "perf_feed_cache",
"path": "/",
"sameSite": null,
"secure": true,
"session": false,
"storeId": null,
"value": "{%22expireTimestamp%22:1767438000000%2C%22itemIds%22:[%227588749061168123154%22%2C%227589493510613552404%22%2C%227586917939568332054%22]}"
},
{
"domain": ".tiktok.com",
"expirationDate": 1782817620.645952,
"hostOnly": false,
"httpOnly": true,
"name": "uid_tt",
"path": "/",
"sameSite": null,
"secure": true,
"session": false,
"storeId": null,
"value": "44deb1e89d254f610eefd18c39ec97fa708e9c0f22c0207f7140c6ffd6c81b2c"
},
{
"domain": ".tiktok.com",
"expirationDate": 1772449601.742227,
"hostOnly": false,
"httpOnly": false,
"name": "passport_csrf_token_default",
"path": "/",
"sameSite": null,
"secure": true,
"session": false,
"storeId": null,
"value": "9c66ab10306611c75fa19c87e54fd31b"
},
{
"domain": ".tiktok.com",
"hostOnly": false,
"httpOnly": false,
"name": "s_v_web_id",
"path": "/",
"sameSite": "no_restriction",
"secure": true,
"session": true,
"storeId": null,
"value": "verify_mjvcbi31_l3mxUEeU_ykis_4x6z_859S_8zEFmNseEnJU"
},
{
"domain": ".tiktok.com",
"expirationDate": 1782817620.64617,
"hostOnly": false,
"httpOnly": true,
"name": "ssid_ucp_v1",
"path": "/",
"sameSite": "no_restriction",
"secure": true,
"session": false,
"storeId": null,
"value": "1.0.1-KDlhMTg2NTQ1MmJiZmNlZjgzYzNiZGU4ZjAyNzk1NWRkNTlkOTYxNjIKIQiBiIHG4PKvxV8Q0KrZygYYswsgDDC50ZfDBjgIQBJIBBADGgJteSIgZThjZGY5Y2NjZTdiOTI0YTgwMTkyYjNmMmQyNTFkNDQyTgog40q2JTBb3lGgiNKowpX3zbxplmW4zO3AUFhAo6LMB-wSIDpAp_OQ2Q5qEBZvL59v7fgLmw27UIxLQHoimzDg3U5BGAIiBnRpa3Rvaw"
},
{
"domain": ".www.tiktok.com",
"expirationDate": 1793185625,
"hostOnly": false,
"httpOnly": false,
"name": "tiktok_webapp_theme",
"path": "/",
"sameSite": null,
"secure": true,
"session": false,
"storeId": null,
"value": "dark"
},
{
"domain": ".tiktok.com",
"expirationDate": 1799409936.219767,
"hostOnly": false,
"httpOnly": false,
"name": "_ttp",
"path": "/",
"sameSite": "no_restriction",
"secure": true,
"session": false,
"storeId": null,
"value": "32XOXKxwj8YLtBQf0OBn4TvlkPN"
},
{
"domain": ".tiktok.com",
"expirationDate": 1772449620.645821,
"hostOnly": false,
"httpOnly": true,
"name": "cmpl_token",
"path": "/",
"sameSite": null,
"secure": true,
"session": false,
"storeId": null,
"value": "AgQYAPOF_hfkTtKPtFExgPKdOPKrXVkNUj-FDmCi6K4"
},
{
"domain": ".tiktok.com",
"expirationDate": 1772449620.645628,
"hostOnly": false,
"httpOnly": true,
"name": "multi_sids",
"path": "/",
"sameSite": null,
"secure": true,
"session": false,
"storeId": null,
"value": "6884525631502042113%3Ae8cdf9ccce7b924a80192b3f2d251d44"
},
{
"domain": ".tiktok.com",
"expirationDate": 1769857620.645892,
"hostOnly": false,
"httpOnly": true,
"name": "passport_auth_status_ss",
"path": "/",
"sameSite": "no_restriction",
"secure": true,
"session": false,
"storeId": null,
"value": "966972581a398dbb9ead189c044cf98c%2C"
},
{
"domain": ".tiktok.com",
"expirationDate": 1772449601.742082,
"hostOnly": false,
"httpOnly": false,
"name": "passport_csrf_token",
"path": "/",
"sameSite": "no_restriction",
"secure": true,
"session": false,
"storeId": null,
"value": "9c66ab10306611c75fa19c87e54fd31b"
},
{
"domain": ".tiktok.com",
"expirationDate": 1782817620.646041,
"hostOnly": false,
"httpOnly": true,
"name": "sessionid",
"path": "/",
"sameSite": null,
"secure": true,
"session": false,
"storeId": null,
"value": "e8cdf9ccce7b924a80192b3f2d251d44"
},
{
"domain": ".tiktok.com",
"expirationDate": 1782817620.646073,
"hostOnly": false,
"httpOnly": true,
"name": "sessionid_ss",
"path": "/",
"sameSite": "no_restriction",
"secure": true,
"session": false,
"storeId": null,
"value": "e8cdf9ccce7b924a80192b3f2d251d44"
},
{
"domain": ".tiktok.com",
"expirationDate": 1782817620.646008,
"hostOnly": false,
"httpOnly": true,
"name": "sid_tt",
"path": "/",
"sameSite": null,
"secure": true,
"session": false,
"storeId": null,
"value": "e8cdf9ccce7b924a80192b3f2d251d44"
},
{
"domain": ".tiktok.com",
"expirationDate": 1782817620.646132,
"hostOnly": false,
"httpOnly": true,
"name": "sid_ucp_v1",
"path": "/",
"sameSite": null,
"secure": true,
"session": false,
"storeId": null,
"value": "1.0.1-KDlhMTg2NTQ1MmJiZmNlZjgzYzNiZGU4ZjAyNzk1NWRkNTlkOTYxNjIKIQiBiIHG4PKvxV8Q0KrZygYYswsgDDC50ZfDBjgIQBJIBBADGgJteSIgZThjZGY5Y2NjZTdiOTI0YTgwMTkyYjNmMmQyNTFkNDQyTgog40q2JTBb3lGgiNKowpX3zbxplmW4zO3AUFhAo6LMB-wSIDpAp_OQ2Q5qEBZvL59v7fgLmw27UIxLQHoimzDg3U5BGAIiBnRpa3Rvaw"
},
{
"domain": ".www.tiktok.com",
"expirationDate": 1793185625,
"hostOnly": false,
"httpOnly": false,
"name": "tiktok_webapp_theme_source",
"path": "/",
"sameSite": null,
"secure": true,
"session": false,
"storeId": null,
"value": "auto"
},
{
"domain": ".tiktok.com",
"expirationDate": 1782817624.001151,
"hostOnly": false,
"httpOnly": true,
"name": "tt_chain_token",
"path": "/",
"sameSite": null,
"secure": true,
"session": false,
"storeId": null,
"value": "6deMEWrkAGUe9R0tCISIoQ=="
},
{
"domain": ".tiktok.com",
"hostOnly": false,
"httpOnly": true,
"name": "tt_csrf_token",
"path": "/",
"sameSite": "lax",
"secure": true,
"session": true,
"storeId": null,
"value": "q0Q4ki72-I7zQB6eLbpBBaqFBGrUF_v85N9s"
},
{
"domain": ".tiktok.com",
"expirationDate": 1782817620.645979,
"hostOnly": false,
"httpOnly": true,
"name": "uid_tt_ss",
"path": "/",
"sameSite": "no_restriction",
"secure": true,
"session": false,
"storeId": null,
"value": "44deb1e89d254f610eefd18c39ec97fa708e9c0f22c0207f7140c6ffd6c81b2c"
}
]
}

View file

@ -1,12 +0,0 @@
import sys
print(f"Python: {sys.executable}")
print(f"Path: {sys.path}")
try:
import playwright_stealth
print(f"Module: {playwright_stealth}")
from playwright_stealth import stealth_async
print("Import successful!")
except ImportError as e:
print(f"Import failed: {e}")
except Exception as e:
print(f"Error: {e}")

View file

@ -1,41 +0,0 @@
import json
import urllib.request
import urllib.parse
import os
import sys
def debug_search():
base_url = "http://localhost:8002/api/user/search"
query = "hot trend"
params = urllib.parse.urlencode({"query": query, "limit": 10})
url = f"{base_url}?{params}"
print(f"Testing search for: '{query}'")
print(f"URL: {url}")
try:
req = urllib.request.Request(url)
with urllib.request.urlopen(req, timeout=60) as response:
status_code = response.getcode()
print(f"Status Code: {status_code}")
if status_code == 200:
data = json.loads(response.read().decode('utf-8'))
print(f"Source: {data.get('source')}")
print(f"Count: {data.get('count')}")
videos = data.get("videos", [])
if not videos:
print("ERROR: No videos returned!")
else:
print(f"First video: {videos[0].get('id')} - {videos[0].get('desc', 'No desc')}")
else:
print(f"Error: Status {status_code}")
except urllib.error.HTTPError as e:
print(f"HTTP Error: {e.code} - {e.reason}")
print(e.read().decode('utf-8'))
except Exception as e:
print(f"Request failed: {e}")
if __name__ == "__main__":
debug_search()

View file

@ -1,29 +0,0 @@
from bs4 import BeautifulSoup
import re
with open("debug_search_page.html", "r", encoding="utf-8") as f:
html = f.read()
soup = BeautifulSoup(html, "html.parser")
# Inspect text occurrences
print("\n--- Searching for 'trend' text ---")
text_matches = soup.find_all(string=re.compile("trend", re.IGNORECASE))
print(f"Found {len(text_matches)} text matches.")
unique_parents = set()
for text in text_matches:
parent = text.parent
if parent and parent.name != "script" and parent.name != "style":
# Get up to 3 levels of parents
chain = []
curr = parent
for _ in range(3):
if curr:
chain.append(f"<{curr.name} class='{'.'.join(curr.get('class', []))}'>")
curr = curr.parent
unique_parents.add(" -> ".join(chain))
for p in list(unique_parents)[:10]:
print(p)

View file

@ -1,45 +0,0 @@
from bs4 import BeautifulSoup
import json
with open("debug_search_page.html", "r", encoding="utf-8") as f:
html = f.read()
soup = BeautifulSoup(html, "html.parser")
script = soup.find("script", id="__UNIVERSAL_DATA_FOR_REHYDRATION__")
if script:
try:
data = json.loads(script.string)
print("Found SSR Data!")
# Save pretty printed
with open("ssr_data.json", "w", encoding="utf-8") as f:
json.dump(data, f, indent=2)
# Search for video list
# Look in __DEFAULT_SCOPE__ -> webapp.search-video -> searchVideoList (guessing keys)
# or just traverse and print keys
def find_keys(obj, target_key, path=""):
if isinstance(obj, dict):
for k, v in obj.items():
current_path = f"{path}.{k}"
if target_key.lower() in k.lower():
print(f"Found key '{k}' at {current_path}")
find_keys(v, target_key, current_path)
elif isinstance(obj, list):
for i, item in enumerate(obj):
find_keys(item, target_key, f"{path}[{i}]")
print("\nSearching for 'item' or 'list' keys...")
find_keys(data, "item")
find_keys(data, "list")
# Check specific known paths
default_scope = data.get("__DEFAULT_SCOPE__", {})
print(f"\nTop level keys: {list(default_scope.keys())}")
except json.JSONDecodeError as e:
print(f"JSON Error: {e}")
else:
print("Script tag not found.")

View file

@ -1,30 +0,0 @@
import urllib.request
import json
try:
print("Testing /health...")
with urllib.request.urlopen("http://localhost:8002/health", timeout=5) as r:
print(f"Health: {r.status}")
print("Testing /api/feed...")
with open("temp_cookies.json", "r") as f:
data = json.load(f)
# Ensure list format
if isinstance(data, dict) and "credentials" in data:
data = data["credentials"]
# Prepare body as dict for safety with new Union type
body = {"credentials": data}
req = urllib.request.Request(
"http://localhost:8002/api/feed",
data=json.dumps(body).encode('utf-8'),
headers={'Content-Type': 'application/json'}
)
with urllib.request.urlopen(req, timeout=30) as r:
print(f"Feed: {r.status}")
print(r.read().decode('utf-8')[:100])
except Exception as e:
print(f"Error: {e}")

View file

@ -1,42 +0,0 @@
import asyncio
import base64
from crawl4ai import AsyncWebCrawler
async def main():
print("Starting Crawl4AI test...")
async with AsyncWebCrawler(verbose=True) as crawler:
url = "https://www.tiktok.com/search?q=hot+trend"
print(f"Crawling: {url}")
# Browser config
run_conf = {
"url": url,
"wait_for": "css:[data-e2e='search_video_item']",
"css_selector": "[data-e2e='search_video_item']",
"screenshot": True,
"magic": True
}
print(f"Crawling with config: {run_conf}")
result = await crawler.arun(**run_conf)
if result.success:
print("Crawl successful!")
print(f"HTML length: {len(result.html)}")
if result.screenshot:
with open("crawl_screenshot.png", "wb") as f:
f.write(base64.b64decode(result.screenshot))
print("Saved screenshot to crawl_screenshot.png")
# Save for inspection
with open("crawl_debug.html", "w", encoding="utf-8") as f:
f.write(result.html)
with open("crawl_debug.md", "w", encoding="utf-8") as f:
f.write(result.markdown)
else:
print(f"Crawl failed: {result.error_message}")
if __name__ == "__main__":
asyncio.run(main())

View file

@ -1,16 +0,0 @@
import requests
import time
URL = "http://localhost:8002/api/auth/admin-login"
def test_login():
print("Testing Admin Login...")
try:
res = requests.post(URL, json={"password": "admin123"})
print(f"Status: {res.status_code}")
print(f"Response: {res.text}")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
test_login()

View file

@ -1,30 +0,0 @@
import urllib.request
import json
import os
with open("temp_cookies.json", "r") as f:
data = json.load(f)
# Ensure data is in the expected dict format for the request body
if isinstance(data, list):
# If temp_cookies is just the list, wrap it
body = {"credentials": data}
elif "credentials" not in data:
body = {"credentials": data}
else:
body = data
req = urllib.request.Request(
"http://localhost:8002/api/feed",
data=json.dumps(body).encode('utf-8'),
headers={'Content-Type': 'application/json'}
)
try:
with urllib.request.urlopen(req) as response:
print(response.read().decode('utf-8'))
except urllib.error.HTTPError as e:
print(f"HTTP Error: {e.code}")
print(e.read().decode('utf-8'))
except Exception as e:
print(f"Error: {e}")

View file

@ -1,35 +0,0 @@
import requests
import json
import time
BASE_URL = "http://localhost:8002/api/user/search"
def test_search():
print("Testing Search API...")
try:
# Simple query
params = {
"query": "dance",
"limit": 50,
"cursor": 0
}
start = time.time()
res = requests.get(BASE_URL, params=params)
duration = time.time() - start
print(f"Status Code: {res.status_code}")
print(f"Duration: {duration:.2f}s")
if res.status_code == 200:
data = res.json()
print(f"Videos Found: {len(data.get('videos', []))}")
# print(json.dumps(data, indent=2))
else:
print("Error Response:")
print(res.text)
except Exception as e:
print(f"Request Failed: {e}")
if __name__ == "__main__":
test_search()