From fcafb40656b2d01e9e08ddc2295d5fcc986d54d7 Mon Sep 17 00:00:00 2001 From: CoasterFreakDE Date: Mon, 20 Jun 2022 20:51:44 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=8C=EF=B8=8F=20Title=20and=20Tags?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 14 ++++++++------ video_creation/data/videos.json | 7 +++++++ video_creation/video_uploader.py | 28 ++++++++++++++++++++++++---- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index 1a51eb8..49dc59c 100755 --- a/main.py +++ b/main.py @@ -39,6 +39,7 @@ password = getenv("REDDIT_PASSWORD") reddit2fa = getenv("REDDIT_2FA") tiktok_email = getenv("TIKTOK_EMAIL") tiktok_password = getenv("TIKTOK_PASSWORD") +tiktok_tags = getenv("TIKTOK_TAGS") def main(): @@ -49,12 +50,13 @@ def main(): reddit_obj = get_subreddit_threads() return reddit_obj - reddit_object = get_obj() - length, number_of_comments = save_text_to_mp3(reddit_object) - download_screenshots_of_reddit_posts(reddit_object, number_of_comments) - download_background() - chop_background_video(length) - video_file_name = make_final_video(number_of_comments, length) + # reddit_object = get_obj() + # length, number_of_comments = save_text_to_mp3(reddit_object) + # download_screenshots_of_reddit_posts(reddit_object, number_of_comments) + # download_background() + # chop_background_video(length) + # video_file_name = make_final_video(number_of_comments, length) + video_file_name = "Whats something people in this....mp4" loop = asyncio.get_event_loop() loop.run_until_complete(upload_video_to_tiktok(video_file_name)) loop.close() diff --git a/video_creation/data/videos.json b/video_creation/data/videos.json index 3ed2621..5569348 100644 --- a/video_creation/data/videos.json +++ b/video_creation/data/videos.json @@ -54,5 +54,12 @@ "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 4c9066b..40fff70 100644 --- a/video_creation/video_uploader.py +++ b/video_creation/video_uploader.py @@ -1,6 +1,6 @@ from asyncio import sleep import asyncio -import json +import imp from os import getenv import os from pathlib import Path @@ -9,14 +9,13 @@ 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 selenium.webdriver.common.keys import Keys from playwright.async_api import async_playwright import undetected_chromedriver.v2 as uc -from fake_useragent import UserAgent, FakeUserAgentError +from fake_useragent import UserAgent from utils.console import print_step, print_substep -import json from rich.console import Console console = Console() @@ -70,6 +69,27 @@ async def upload_video_to_tiktok(videofile): 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) + + title = os.getenv("VIDEO_TITLE") or videofile.split(".")[0] + tags = os.getenv("TIKTOK_TAGS") or "#AskReddit" + + if len(title) + len(tags) > 150: + if len(tags) > 150: + print_substep("Tags are too long, please shorten them.") + return + + remove = 149 - len(tags) + title = title[:remove] + " " + tags + else: + title = title + " " + tags + + title_input = browser.find_elements(By.XPATH, '//*[@id="root"]/div/div/div/div/div[2]/div[2]/div[1]/div/div[1]/div[2]/div/div[1]/div/div/div/div/div/div')[0] + title_input.send_keys(Keys.CONTROL, "a") + title_input.send_keys(Keys.BACKSPACE) + title_input.send_keys(title) + + await asyncio.sleep(1) + 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)