added IN-PROGRESS storymode flag

chore: changed print sizing

feat: started working on #10
pull/418/head
Jason 3 years ago
parent 12af99fd81
commit bd165a2473

@ -20,3 +20,5 @@ OPACITY="1"
# see TTSwrapper.py for all valid options
VOICE="en_us_001" # e.g. en_us_002
# IN-PROGRESS - not yet implemented
STORYMODE="False"

@ -18,7 +18,7 @@ def get_subreddit_threads():
Returns a list of threads from the AskReddit subreddit.
"""
global submission
print_step("Logging into Reddit.")
print_substep("Logging into Reddit.")
content = {}
if getenv("REDDIT_2FA").casefold() == "yes":
@ -78,11 +78,9 @@ def get_subreddit_threads():
) # todo use global instend of env vars
environ["VIDEO_ID"] = str(textify(submission.id))
try:
print(f'{submission.content=}')
print(f'{submission.body=}')
content["thread_url"] = submission.url
content["thread_title"] = submission.title
content["thread_content"] = submission.content
#ontent["thread_content"] = submission.content
content["comments"] = []
for top_level_comment in submission.comments:

@ -2,12 +2,14 @@ import json
from os import getenv
from pathlib import Path
from playwright.async_api import async_playwright
#from playwright.async_api import async_playwright
from playwright.sync_api import sync_playwright, ViewportSize
from rich.progress import track
from utils.console import print_step, print_substep
storymode = False
def download_screenshots_of_reddit_posts(reddit_object, screenshot_num):
"""Downloads screenshots of reddit posts as they are seen on the web.
@ -32,7 +34,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num):
else:
cookie_file = open("./video_creation/data/cookie-light-mode.json")
cookies = json.load(cookie_file)
context.add_cookies(cookies)
context.add_cookies(cookies) # load preference cookies
# Get the thread screenshot
page = context.new_page()
page.set_viewport_size(ViewportSize(width=1920, height=1080))
@ -52,20 +54,22 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num):
page.locator('[data-test-id="post-content"]').screenshot(
path="assets/temp/png/title.png"
)
if storymode:
page.locator('[data-click-id="text"]').screenshot(path="assets/temp/png/story_content.png")
else:
for idx, comment in track(
enumerate(reddit_object["comments"]), "Downloading screenshots..."
):
for idx, comment in track(
enumerate(reddit_object["comments"]), "Downloading screenshots..."
):
# Stop if we have reached the screenshot_num
if idx >= screenshot_num:
break
# Stop if we have reached the screenshot_num
if idx >= screenshot_num:
break
if page.locator('[data-testid="content-gate"]').is_visible():
page.locator('[data-testid="content-gate"] button').click()
if page.locator('[data-testid="content-gate"]').is_visible():
page.locator('[data-testid="content-gate"] button').click()
page.goto(f'https://reddit.com{comment["comment_url"]}')
page.locator(f"#t1_{comment['comment_id']}").screenshot(
path=f"assets/temp/png/comment_{idx}.png"
)
page.goto(f'https://reddit.com{comment["comment_url"]}')
page.locator(f"#t1_{comment['comment_id']}").screenshot(
path=f"assets/temp/png/comment_{idx}.png"
)
print_substep("Screenshots downloaded Successfully.", style="bold green")

@ -1,3 +1,4 @@
from os import getenv
from pathlib import Path
import sox
@ -34,6 +35,9 @@ def save_text_to_mp3(reddit_obj):
length += MP3(f"assets/temp/mp3/title.mp3").info.length
except HeaderNotFoundError: # note to self AudioFileClip
length += sox.file_info.duration(f"assets/temp/mp3/title.mp3")
if getenv("STORYMODE").casefold() == "true":
ttttsw.tts(sanitize_text(reddit_obj["thread_content"]), filename=f"assets/temp/mp3/story_content.mp3", random_speaker=False)
#'story_content'
com = 0
for comment in track((reddit_obj["comments"]), "Saving..."):
# ! Stop creating mp3 files if the length is greater than VIDEO_LENGTH seconds. This can be longer, but this is just a good_voices starting point
@ -62,5 +66,5 @@ def save_text_to_mp3(reddit_obj):
# remove(f"assets/temp/png/comment_{com}.png")# todo might cause odd un-syncing
print_substep("Saved Text to MP3 files Successfully.", style="bold green")
# ! Return the index so we know how many screenshots of comments we need to make.
# ! Return the index, so we know how many screenshots of comments we need to make.
return length, com

Loading…
Cancel
Save