created remote transcriber
This commit is contained in:
1 parent
856ab439f7
commit
38e0cc6764
10 files changed
+718
-68
No files matched your search
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env python3
|
||||
from tiktok_uploader.upload import upload_video
|
||||
from pathlib import Path
|
||||
import json
|
||||
import time
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
COOKIES_FILE = "cookies.txt"
|
||||
|
||||
def get_last_video_link(username):
|
||||
"""Grab newest video link from profile"""
|
||||
url = f"https://www.tiktok.com/@{username}"
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
context = browser.new_context(storage_state=COOKIES_FILE) if Path(COOKIES_FILE).exists() else browser.new_context()
|
||||
page = context.new_page()
|
||||
page.goto(url, timeout=60000)
|
||||
page.wait_for_selector('[data-e2e="user-post-item"] a', timeout=15000)
|
||||
first_video = page.query_selector('[data-e2e="user-post-item"] a')
|
||||
link = first_video.get_attribute('href') if first_video else None
|
||||
browser.close()
|
||||
return link
|
||||
|
||||
def upload_to_tiktok(video_path, description, hashtags=[], username="YOUR_USERNAME_HERE"):
|
||||
tags = " ".join([f"#{t}" for t in hashtags])
|
||||
full_desc = f"{description}\n\n{tags}"
|
||||
|
||||
failed = upload_video(
|
||||
filename=str(video_path),
|
||||
description=full_desc,
|
||||
cookies=COOKIES_FILE,
|
||||
headless=True,
|
||||
browser="chrome"
|
||||
)
|
||||
|
||||
if len(failed) != 0:
|
||||
print(f"❌ Failed {video_path}: {failed}")
|
||||
return None
|
||||
|
||||
print(f"✅ Uploaded {video_path} - fetching link...")
|
||||
time.sleep(8) # give TikTok time to process
|
||||
|
||||
# Try 3 times, TikTok takes ~10-30s to show new video
|
||||
for i in range(3):
|
||||
link = get_last_video_link(username)
|
||||
if link:
|
||||
print(f"🔗 {link}")
|
||||
return link
|
||||
print(f" Waiting for TikTok to publish... retry {i+1}/3")
|
||||
time.sleep(10)
|
||||
|
||||
return f"https://www.tiktok.com/@{username} (uploaded, but link not ready yet - check profile)"
|
||||
|
||||
if __name__ == "__main__":
|
||||
USERNAME = "your_tiktok_username" # <-- CHANGE THIS, no @
|
||||
|
||||
with open("highlights.json") as f:
|
||||
data = json.load(f)
|
||||
|
||||
for h in data['highlights'][:3]:
|
||||
video_file = f"highlights/highlight_{h['id']}_{h['start_timestamp'].replace(':','-')}.mp4"
|
||||
if not Path(video_file).exists():
|
||||
continue
|
||||
|
||||
desc = h['transcript'][:150]
|
||||
link = upload_to_tiktok(
|
||||
video_file,
|
||||
description=desc,
|
||||
hashtags=["fyp", "clutch", "highlight", "pog"],
|
||||
username=USERNAME
|
||||
)
|
||||
print(f"LINK: {link}\n")
|
||||
Reference in new issue
Block a user