parent
8d54e373df
commit
5cbd62054d
@ -1 +1,58 @@
|
||||
[]
|
||||
[
|
||||
{
|
||||
"id": "vgeixb",
|
||||
"time": "1655721481",
|
||||
"background_credit": "bbswitzer",
|
||||
"reddit_title": "Whats an opinion you have thats considered unacceptable by societal standards",
|
||||
"filename": "Whats an opinion you have that....mp4"
|
||||
},
|
||||
{
|
||||
"id": "vg1q2d",
|
||||
"time": "1655727334",
|
||||
"background_credit": "loopylongplays",
|
||||
"reddit_title": "Whats a middle life crisis for people who could never afford a sports car",
|
||||
"filename": "Whats a middle life crisis for....mp4"
|
||||
},
|
||||
{
|
||||
"id": "vfxpph",
|
||||
"time": "1655727738",
|
||||
"background_credit": "bbswitzer",
|
||||
"reddit_title": "What unimpressive things are people idiotically proud of",
|
||||
"filename": "What unimpressive things are p....mp4"
|
||||
},
|
||||
{
|
||||
"id": "vfyy54",
|
||||
"time": "1655728587",
|
||||
"background_credit": "loopylongplays",
|
||||
"reddit_title": "What do you find oddly attractive",
|
||||
"filename": "What do you find oddly attractive.mp4"
|
||||
},
|
||||
{
|
||||
"id": "vg321p",
|
||||
"time": "1655728930",
|
||||
"background_credit": "loopylongplays",
|
||||
"reddit_title": "If you could multiply anything by 10x what would it be",
|
||||
"filename": "If you could multiply anything....mp4"
|
||||
},
|
||||
{
|
||||
"id": "vg822j",
|
||||
"time": "1655731883",
|
||||
"background_credit": "loopylongplays",
|
||||
"reddit_title": "Whats a job that people really underestimate the importance of",
|
||||
"filename": "Whats a job that people really....mp4"
|
||||
},
|
||||
{
|
||||
"id": "vgj2ie",
|
||||
"time": "1655744382",
|
||||
"background_credit": "loopylongplays",
|
||||
"reddit_title": "What is the thing you never imagined youd be able to do it until you did it",
|
||||
"filename": "What is the thing you never im....mp4"
|
||||
},
|
||||
{
|
||||
"id": "vgmldg",
|
||||
"time": "1655744683",
|
||||
"background_credit": "loopylongplays",
|
||||
"reddit_title": "How does someone politely end a conversation with a person who wont stop talking",
|
||||
"filename": "How does someone politely end ....mp4"
|
||||
}
|
||||
]
|
@ -0,0 +1,76 @@
|
||||
from asyncio import sleep
|
||||
import asyncio
|
||||
import json
|
||||
from os import getenv
|
||||
import os
|
||||
from pathlib import Path
|
||||
import pickle
|
||||
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.wait import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
import selenium.common
|
||||
|
||||
from playwright.async_api import async_playwright
|
||||
import undetected_chromedriver.v2 as uc
|
||||
from fake_useragent import UserAgent, FakeUserAgentError
|
||||
|
||||
from utils.console import print_step, print_substep
|
||||
import json
|
||||
from rich.console import Console
|
||||
|
||||
console = Console()
|
||||
|
||||
storymode = False
|
||||
|
||||
|
||||
async def upload_video_to_tiktok(videofile):
|
||||
"""Uploads the video to tiktok.
|
||||
Args:
|
||||
videofile: The video file you want to upload inside of /results.
|
||||
"""
|
||||
print_step("Uploading video to tiktok...")
|
||||
|
||||
# ! Make sure the reddit screenshots folder exists
|
||||
Path("results").mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
async with async_playwright() as p:
|
||||
print_substep("Launching Headless Browser...")
|
||||
|
||||
options = uc.ChromeOptions()
|
||||
options.add_argument("--user-agent=" + UserAgent().random)
|
||||
options.add_argument("--headless")
|
||||
browser = uc.Chrome(options=options)
|
||||
browser.delete_all_cookies()
|
||||
|
||||
# Get the thread screenshot
|
||||
browser.get("https://www.tiktok.com/login")
|
||||
|
||||
await asyncio.sleep(3)
|
||||
|
||||
cookie_file = open("./video_creation/data/tiktok.cookie", "rb")
|
||||
cookie_data = pickle.load(cookie_file)
|
||||
for cookie in cookie_data:
|
||||
if 'sameSite' in cookie:
|
||||
if cookie['sameSite'] == 'None':
|
||||
cookie['sameSite'] = 'Strict'
|
||||
browser.add_cookie(cookie)
|
||||
browser.refresh()
|
||||
|
||||
await asyncio.sleep(3)
|
||||
print_substep("Logged in...")
|
||||
|
||||
browser.get('https://www.tiktok.com/upload')
|
||||
await asyncio.sleep(5)
|
||||
WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.TAG_NAME, "iframe")))
|
||||
abs_path = os.path.join(os.getcwd(), f'results/{videofile}')
|
||||
browser.switch_to.frame(0)
|
||||
browser.implicitly_wait(1)
|
||||
browser.find_elements(By.XPATH, '//*[@id="root"]/div/div/div/div/div[2]/div[1]/div/input')[0].send_keys(abs_path)
|
||||
print_substep("Uploading video...")
|
||||
await asyncio.sleep(10)
|
||||
browser.find_elements(By.XPATH, '//*[@id="root"]/div/div/div/div/div[2]/div[2]/div[7]/div[2]/button')[0].click()
|
||||
await asyncio.sleep(5)
|
||||
|
||||
print_substep("Video uploaded Successfully.", style="bold green")
|
Loading…
Reference in new issue