Added subtext of thread post to TTS

pull/253/head
satya ratnam 3 years ago
parent 94cead36a2
commit 021ba0445b

@ -19,17 +19,18 @@ print_markdown(
time.sleep(3) 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) # 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 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 https://gtts.readthedocs.io/en/latest/module.html?highlight=accent
VOICE_ACCENT = "co.uk" VOICE_ACCENT = "co.uk"
# Background video to use (video id from youtube) # Background video to use (video id from youtube)
# Use an array of videos to create a random background video # 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 # select random 1
BACKGROUND_VIDEO = BACKGROUND_VIDEO_ARRAY[random.randrange(0, len(BACKGROUND_VIDEO_ARRAY))] BACKGROUND_VIDEO = BACKGROUND_VIDEO_ARRAY[random.randrange(0, len(BACKGROUND_VIDEO_ARRAY))]

@ -74,6 +74,7 @@ def get_subreddit_threads():
content["thread_url"] = submission.url content["thread_url"] = submission.url
content["thread_title"] = submission.title content["thread_title"] = submission.title
content["thread_selftext"] = submission.selftext
content["comments"] = [] content["comments"] = []
content["subreddit"] = subreddit_title.upper() content["subreddit"] = subreddit_title.upper()
content["ffmpeg_exe"] = str(ffmpeg_exe) content["ffmpeg_exe"] = str(ffmpeg_exe)

@ -15,10 +15,10 @@ def get_start_and_end_times(video_length, length_of_clip):
def download_background(youtube_id): def download_background(youtube_id):
if not Path(f"assets/mp4/background-{youtube_id}.mp4").is_file(): if not Path(f"assets/mp4/background-{youtube_id}.mp4").is_file():
print_step( 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 = { ydl_opts = {
"outtmpl": f"assets/mp4/background-{youtube_id}.mp4", "outtmpl": f"assets/mp4/background-{youtube_id}.mp4",

@ -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 reddit_object: The Reddit Object you received in askreddit.py
screenshot_num: The number of screenshots you want to download. 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 # ! Make sure the reddit screenshots folder exists
Path("assets/png").mkdir(parents=True, exist_ok=True) 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 # Get the thread screenshot
page = context.new_page() page = context.new_page()
page.goto(reddit_object["thread_url"]) 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(): if page.locator('[data-testid="content-gate"]').is_visible():
# This means the post is NSFW and requires to click the proceed button. # 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( page.locator('[data-test-id="post-content"]').screenshot(
path="assets/png/title.png" 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( for idx, comment in track(
enumerate(reddit_object["comments"]), "Downloading screenshots..." 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" path=f"assets/png/comment_{idx}.png"
) )
print_substep("Screenshots downloaded Successfully.", print_substep("Screenshots downloaded Successfully.", style="bold green")
style="bold green")

@ -17,7 +17,7 @@ def save_text_to_mp3(reddit_obj, maxlength, accent):
# Create a folder for the mp3 files. # Create a folder for the mp3 files.
Path("assets/mp3").mkdir(parents=True, exist_ok=True) 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") tts.save(f"assets/mp3/title.mp3")
length += MP3(f"assets/mp3/title.mp3").info.length length += MP3(f"assets/mp3/title.mp3").info.length

Loading…
Cancel
Save