diff --git a/video_creation/data/videos.json b/video_creation/data/videos.json index 5569348..1610ea1 100644 --- a/video_creation/data/videos.json +++ b/video_creation/data/videos.json @@ -1,65 +1,3 @@ [ - { - "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" - }, - { - "id": "vgo3dv", - "time": "1655749966", - "background_credit": "bbswitzer", - "reddit_title": "Whats something people in this generation really need to hear", - "filename": "Whats something people in this....mp4" - } + ] \ No newline at end of file diff --git a/video_creation/video_uploader.py b/video_creation/video_uploader.py index c198ffc..61a93cf 100644 --- a/video_creation/video_uploader.py +++ b/video_creation/video_uploader.py @@ -34,12 +34,20 @@ async def upload_video_to_tiktok(videofile): Path("results").mkdir(parents=True, exist_ok=True) - async with async_playwright() as p: - print_substep("Launching Headless Browser...") - + async with async_playwright() as p: options = uc.ChromeOptions() options.add_argument("--user-agent=" + UserAgent().random) - options.add_argument("--headless") + + cookie_path = "./video_creation/data/tiktok.cookie" + has_cookie = False + try: + cookie_file = open(cookie_path, "rb") + has_cookie = True + options.add_argument("--headless") + print_substep("Launching Headless Browser...") + except FileNotFoundError: + print_substep("Launching Browser to manually log you in (only first time).") + browser = uc.Chrome(options=options) browser.delete_all_cookies() @@ -48,7 +56,14 @@ async def upload_video_to_tiktok(videofile): await asyncio.sleep(3) - cookie_file = open("./video_creation/data/tiktok.cookie", "rb") + if not has_cookie: + print("Your browser currently shows the tiktok login page, please login in.") + input("After you have logged in fully, please press any button to continue...") + print("#####") + pickle.dump(browser.get_cookies(), open(cookie_path, "wb+")) + print("Cookie has been created successfully, resuming upload!") + cookie_file = open(cookie_path, "rb") + cookie_data = pickle.load(cookie_file) for cookie in cookie_data: if 'sameSite' in cookie: @@ -67,6 +82,7 @@ async def upload_video_to_tiktok(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)