From 021ba0445b8480ad25d936c84bf996ab75c8cb6a Mon Sep 17 00:00:00 2001 From: satya ratnam Date: Sun, 5 Jun 2022 08:01:02 +0800 Subject: [PATCH] Added subtext of thread post to TTS --- main.py | 7 ++++--- reddit/subreddit.py | 1 + video_creation/background.py | 4 ++-- video_creation/screenshot_downloader.py | 12 ++++++++---- video_creation/voices.py | 2 +- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index ba5e079..e501726 100644 --- a/main.py +++ b/main.py @@ -19,17 +19,18 @@ print_markdown( time.sleep(3) # The maximum length of the video in seconds. (This is the length of the video that will be created, but not 100% accurate) -MAX_LENGTH = 60 +MAX_LENGTH = 55 # Video speed multiplier (1.0 = normal speed, 2.0 = double speed, 0.5 = half speed) -VIDEO_SPEED = 1.4 +VIDEO_SPEED = 1.2 # Voice accent https://gtts.readthedocs.io/en/latest/module.html?highlight=accent VOICE_ACCENT = "co.uk" # Background video to use (video id from youtube) # Use an array of videos to create a random background video -BACKGROUND_VIDEO_ARRAY = ["5sYdvjXX7YU", "Pt5_GSKIWQM"] + +BACKGROUND_VIDEO_ARRAY = ["5sYdvjXX7YU", "Pt5_GSKIWQM", "uVKxtdMgJVU","E-8JlyO59Io","cEXWuxP1cW0","aeiAt1lFkGg","r9QzNn25SDs","vVJuMq1CMNo","xVqwTUTOOWg","U0By6YNp2C4"] # select random 1 BACKGROUND_VIDEO = BACKGROUND_VIDEO_ARRAY[random.randrange(0, len(BACKGROUND_VIDEO_ARRAY))] diff --git a/reddit/subreddit.py b/reddit/subreddit.py index ebea13b..459aa4a 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -74,6 +74,7 @@ def get_subreddit_threads(): content["thread_url"] = submission.url content["thread_title"] = submission.title + content["thread_selftext"] = submission.selftext content["comments"] = [] content["subreddit"] = subreddit_title.upper() content["ffmpeg_exe"] = str(ffmpeg_exe) diff --git a/video_creation/background.py b/video_creation/background.py index dc86e0e..fa637f7 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -15,10 +15,10 @@ def get_start_and_end_times(video_length, length_of_clip): def download_background(youtube_id): if not Path(f"assets/mp4/background-{youtube_id}.mp4").is_file(): print_step( - "We need to download the background video. This is fairly large but it's only done once." + "We need to download the background video. This is fairly large but it's only done once per video." ) - print_substep("Downloading the background video... please be patient.") + print_substep("Downloading the background video...") ydl_opts = { "outtmpl": f"assets/mp4/background-{youtube_id}.mp4", diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index d3d32ef..d79a882 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -12,7 +12,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): reddit_object: The Reddit Object you received in askreddit.py screenshot_num: The number of screenshots you want to download. """ - print_step("Downloading Screenshots of Reddit Posts 📷") + print_step(f"Downloading Screenshots of Reddit Posts: {screenshot_num} 📷") # ! Make sure the reddit screenshots folder exists Path("assets/png").mkdir(parents=True, exist_ok=True) @@ -31,7 +31,9 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): # Get the thread screenshot page = context.new_page() page.goto(reddit_object["thread_url"]) - page.set_viewport_size(ViewportSize(width=1920, height=1080)) + # page.set_viewport_size(ViewportSize(width=1080, height=1920)) + page.set_viewport_size(ViewportSize(width=700, height=1280, device_scale_factor=0.5)) + if page.locator('[data-testid="content-gate"]').is_visible(): # This means the post is NSFW and requires to click the proceed button. @@ -41,6 +43,9 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): page.locator('[data-test-id="post-content"]').screenshot( path="assets/png/title.png" ) + # page.evaluate('() => { const styleSheet = document.createElement("style");styleSheet.type = "text/css"; const css = "p{font-size:2em !important}";styleSheet.innerText = css;document.head.appendChild(styleSheet); }') + # page.set_viewport_size(ViewportSize(width=720, height=1920, device_scale_factor=1)) + # page.goto(reddit_object["thread_url"]) for idx, comment in track( enumerate(reddit_object["comments"]), "Downloading screenshots..." @@ -58,5 +63,4 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): path=f"assets/png/comment_{idx}.png" ) - print_substep("Screenshots downloaded Successfully.", - style="bold green") + print_substep("Screenshots downloaded Successfully.", style="bold green") diff --git a/video_creation/voices.py b/video_creation/voices.py index 9046ab8..e309fad 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -17,7 +17,7 @@ def save_text_to_mp3(reddit_obj, maxlength, accent): # Create a folder for the mp3 files. Path("assets/mp3").mkdir(parents=True, exist_ok=True) - tts = gTTS(text=reddit_obj["thread_title"], lang="en", tld=accent, slow=False) + tts = gTTS(text=reddit_obj["thread_title"]+reddit_obj["thread_selftext"], lang="en", tld=accent, slow=False) tts.save(f"assets/mp3/title.mp3") length += MP3(f"assets/mp3/title.mp3").info.length