diff --git a/TTS/engine_wrapper.py b/TTS/engine_wrapper.py index 209ce3d..04e7ec5 100644 --- a/TTS/engine_wrapper.py +++ b/TTS/engine_wrapper.py @@ -57,7 +57,7 @@ class TTSEngine: i = 1 for comment in self.reddit_object["comments"]: - + # remove links regex_urls = r"((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z]){2,6}([a-zA-Z0-9\.\&\/\?\:@\-_=#])*" comment["comment_body"] = re.sub(regex_urls, " ", comment["comment_body"]) @@ -73,7 +73,7 @@ class TTSEngine: def run(self) -> Tuple[int, int]: from utils.imagenarator import comment_image_maker - + Path(self.path).mkdir(parents=True, exist_ok=True) print_step("Saving Text to MP3 files...") @@ -107,11 +107,12 @@ class TTSEngine: if ( len(comment["comment_body"]) > self.tts_module.max_chars ): # Split the comment if it is too long - self.split_post(comment["comment_body"], idx) # Split the comment + self.split_post(comment["comment_body"], idx) # Split the comment else: # If the comment is not too long, just call the tts engine self.call_tts(f"{idx}", process_text(comment["comment_body"])) - comment_image_maker((0, 0, 0, 0), self.reddit_object, comments, (255, 255, 255), transparent=True) + if settings.config["settings"]["storymodemethod"] != 0: + comment_image_maker((0, 0, 0, 0), self.reddit_object, comments, (255, 255, 255), transparent=True) print_substep("Saved Text to MP3 files successfully.", style="bold green") return self.length, idx @@ -161,7 +162,7 @@ class TTSEngine: self.tts_module.run( text, filepath=f"{self.path}/{filename}.mp3", - random_voice=settings.config["settings"]["tts"]["random_voice"], + random_voice=settings.config["settings"]["tts"]["random_voice"], ) # try: # self.length += MP3(f"{self.path}/{filename}.mp3").info.length diff --git a/utils/capcut.py b/utils/capcut.py index dd87cd7..5fef363 100644 --- a/utils/capcut.py +++ b/utils/capcut.py @@ -14,9 +14,9 @@ from utils import settings def check_similarity(video_title, text): video_title_words = set(video_title.lower().split()) text_words = set(text.lower().split()) - + common_words = text_words.intersection(video_title_words) - + return len(common_words) / len(text_words) >= 0.6 # Runthrough @@ -32,11 +32,11 @@ def generate_captions(file_path, title): video_title = title.lower() video_file_name = title.replace(" ", "_") - page.click("//span[contains(text(),'Decline all')]") + page.click("//span[contains(text(),'Decline all')]") page.click("//span[contains(text(),'OK')]") - - page.click("//span[contains(text(),'Sign in')]") + + page.goto("https://www.capcut.com/login") page.fill("//input[@class='lv-input lv-input-size-default lv_sign_in_panel_wide-input']", email) @@ -44,30 +44,31 @@ def generate_captions(file_path, title): # time.sleep(5) - page.fill("//input[@type='password']", password) + page.fill("//input[@type='password']", password) page.click("//span[contains(text(),'Sign in')]") - try: + try: page.click("//div[@class='skip--kncMC']") except: pass - + page.goto(f"https://www.capcut.com/my-cloud/{str(settings.config['capcut']['cloud_id'])}?start_tab=video&enter_from=page_header&from_page=work_space&tab=all") try: - page.click("//span[contains(text(),'Decline all')]") - + page.click("//span[contains(text(),'Decline all')]") + except: pass - page.click("//div[@class='guide-modal-close-icon']") + if page.is_visible("//div[@class='guide-modal-close-icon']"): + page.click("//div[@class='guide-modal-close-icon']") if page.is_visible("//div[@data-selectable-item-id]"): page.hover("//div[@data-selectable-item-id]") - + page.click("//*[@width='16']") page.click("//div[contains(text(),'Move to Trash')]") @@ -84,17 +85,26 @@ def generate_captions(file_path, title): page.goto("https://www.capcut.com/editor?enter_from=create_new¤t_page=landing_page&from_page=work_space&start_tab=video&__action_from=my_draft&position=my_draft&scenario=youtube_ads&scale=9%3A16") - page.click("//div[@class='guide-close-icon-f8J9FZ']//*[name()='svg']") - - page.click("//div[@class='guide-placeholder-before-OsTdXF']") + if page.is_visible("//div[@class='guide-close-icon-f8J9FZ']//*[name()='svg']"): + page.click("//div[@class='guide-close-icon-f8J9FZ']//*[name()='svg']") + + if page.is_visible("//div[@class='guide-placeholder-before-OsTdXF']"): + page.click("//div[@class='guide-placeholder-before-OsTdXF']") + + if page.is_visible("//div[@class='guide-close-icon-f8J9FZ']//*[name()='svg']"): + page.click("//div[@class='guide-close-icon-f8J9FZ']//*[name()='svg']") + + if page.is_visible("//div[@class='guide-close-icon-Gtxdju']//*[name()='svg']"): + page.click("//div[@class='guide-close-icon-Gtxdju']//*[name()='svg']") - page.click("//div[@class='guide-close-icon-f8J9FZ']//*[name()='svg']") + if page.is_visible("//div[@class='guide-close-icon-Gtxdju']"): + page.click("//div[@class='guide-close-icon-Gtxdju']") - page.set_input_files("(//input[@type='file'])[1]", file_path) + page.set_input_files("(//input[@type='file'])[1]", file_path) time.sleep(2) - page.click("//div[@class='tools-ZGlCP0']") + page.click("//div[@class='tools-dCzTyg']") page.click("(//li[@role='option'])[5]") time.sleep(18) @@ -102,7 +112,7 @@ def generate_captions(file_path, title): page.click("//div[@id='siderMenuCaption']//div[@class='menu-inner-box']//*[name()='svg']") page.click("//div[normalize-space()='Auto captions']") - + video_ready = False while not video_ready: page.click("//footer[@class='active-panel']//span[contains(text(),'Generate')]") @@ -127,7 +137,7 @@ def generate_captions(file_path, title): time.sleep(1) - page.click(f"(//img[@class='image-DUnWNW'])[{str(settings.config['capcut']['preset_number'])}]") + page.click(f"(//img[@class='image-QII91y'])[{str(settings.config['capcut']['preset_number'])}]") time.sleep(2) @@ -174,8 +184,8 @@ def generate_captions(file_path, title): page.click("//li[contains(text(),'High quality')]") - page.click("//span[contains(text(),'30fps')]") - + page.click("//span[contains(text(),'30fps')]") + page.click("//li[contains(text(),'60fps')]") time.sleep(2) @@ -189,14 +199,14 @@ def generate_captions(file_path, title): with page.expect_download() as download_info: page.locator("//a[@class='shadowAnchor_5bc06']").click() - + dl = download_info.value print(dl.path()) working_dir_path = os.getcwd() - os.makedirs(os.path.join(working_dir_path, "capcut_results", "videos"), exist_ok=True) + os.makedirs(os.path.join(working_dir_path, "capcut_results", "videos"), exist_ok=True) final_path = os.path.join(working_dir_path, "capcut_results", "videos", video_file_name + ".mp4") print(final_path) dl.save_as(final_path) - browser.close() \ No newline at end of file + browser.close() diff --git a/video_creation/final_video.py b/video_creation/final_video.py index cc24edb..a8b7b02 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -245,7 +245,7 @@ def make_final_video( if not settings.config["settings"]["mememode"]: Path(f"assets/temp/{reddit_id}/png").mkdir(parents=True, exist_ok=True) - + # Copyright 2024 beingbored (aka. Tim), MIT License, permission granted to use, copy, modify, and distribute. # get the title_template image and draw a text in the middle part of it with the title of the thread title_template = Image.open("assets/title_template.png") @@ -349,17 +349,18 @@ def make_final_video( "scale", screenshot_width, -1 ) ) + if i == 0: time_for_clip = float(ffmpeg.probe(f"assets/temp/{reddit_id}/mp3/title.mp3")["format"]["duration"]) - image_overlay = image_clips[i].filter("colorchannelmixer", aa=opacity) - background_clip = background_clip.overlay( - image_overlay, - enable=f"between(t,{current_time},{current_time + time_for_clip})", - x="(main_w-overlay_w)/2", - y="(main_h-overlay_h)/2", - ) - current_time += time_for_clip + image_overlay = image_clips[i].filter("colorchannelmixer", aa=opacity) + background_clip = background_clip.overlay( + image_overlay, + enable=f"between(t,{current_time},{current_time + time_for_clip})", + x="(main_w-overlay_w)/2", + y="(main_h-overlay_h)/2", + ) + current_time += time_for_clip title = re.sub(r"[^\w\s-]", "", reddit_obj["thread_title"]) idx = re.sub(r"[^\w\s-]", "", reddit_obj["thread_id"]) diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index fba1737..6684fd8 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -11,7 +11,7 @@ from rich.progress import track from utils import settings from utils.console import print_step, print_substep -from utils.imagenarator import imagemaker, comment_image_maker +from utils.imagenarator import imagemaker from utils.playwright import clear_cookie_by_name from utils.videos import save_data @@ -24,7 +24,7 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): reddit_object (Dict): Reddit object received from reddit/subreddit.py screenshot_num (int): Number of screenshots to download """ - + # settings values W: Final[int] = int(settings.config["settings"]["resolution_w"]) H: Final[int] = int(settings.config["settings"]["resolution_h"]) @@ -70,7 +70,7 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): txtclr=txtcolor, transparent=transparent, ) - + if settings.config["settings"]["storymodemethod"] == 1: return @@ -183,4 +183,4 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): # close browser instance when we are done using it browser.close() - print_substep("Screenshots downloaded Successfully.", style="bold green") \ No newline at end of file + print_substep("Screenshots downloaded Successfully.", style="bold green")