some code improvements

pull/280/head
iaacornus 3 years ago
parent b05143e955
commit 4467153553
No known key found for this signature in database
GPG Key ID: 281739AE7252598C

@ -1,14 +1,11 @@
import argparse
from rich.console import Console
from main import main
from setup_program import setup
from utils.console import print_substep
def program_options():
console = Console()
description = """\
DESCRIPTION HERE.

@ -10,6 +10,7 @@ from video_creation.voices import save_text_to_mp3
from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts
from video_creation.final_video import make_final_video
from utils.console import print_markdown, print_substep
from setup_program import setup
def main(subreddit_=None, background=None, filename=None, thread_link_=None):
@ -40,13 +41,17 @@ def main(subreddit_=None, background=None, filename=None, thread_link_=None):
configured = True
if not os.path.exists(".env"):
shutil.copy(".env.template", ".env")
console.print("[red] Your .env file is invalid, or was never created. Standby.[/red]")
console.print(
"[bold red] Your .env file is invalid, or was never created. Standby.[/bold red]"
)
console.print("[bold green]Checking environment variables...")
console.print("[bold green]Checking environment variables...[/bol green]")
for val in REQUIRED_VALUES:
if not os.getenv(val):
print_substep(f"Please set the variable \"{val}\" in your .env file.", style="bold red")
print_substep(
f"Please set the variable \"{val}\" in your .env file.", style="bold red"
)
configured = False
if configured:
@ -54,12 +59,11 @@ def main(subreddit_=None, background=None, filename=None, thread_link_=None):
float(os.getenv("OPACITY"))
except:
console.print(
f"[red]Please ensure that OPACITY is set between 0 and 1 in your .env file"
f"[bold red]Please ensure that OPACITY is between 0 and 1 in .env file.[/bold red]"
)
configured = False
exit()
raise SystemExit()
console.log("[bold green]Enviroment Variables are set! Continuing...[/bold green]")
console.print("[bold green]Enviroment Variables are set! Continuing...[/bold green]")
reddit_object = get_subreddit_threads(subreddit_, thread_link_)
length, number_of_comments = save_text_to_mp3(reddit_object)
@ -70,12 +74,12 @@ def main(subreddit_=None, background=None, filename=None, thread_link_=None):
)
download_background(background)
chop_background_video(length)
final_video = make_final_video(number_of_comments, filename)
make_final_video(number_of_comments, filename)
else:
console.print(
"[red]Looks like you need to set your Reddit credentials in the .env file. "
+ "Please follow the instructions in the README.md file to set them up.[/red]"
"[bold red]Looks like you need to set your Reddit credentials in the .env file. "
+ "Please follow the instructions in the README.md file to set them up.[/bold red]"
)
setup_ask = input("\033[1mLaunch setup wizard? [y/N] > \033[0m")
if setup_ask in ["y", "Y"]:
os.system("python3 setup.py")
setup()

@ -42,7 +42,9 @@ def make_final_video(number_of_clips, file_name):
FloatingPointError,
TypeError
):
print(f"Please ensure that OPACITY is set between 0 and 1 in your .env file")
print_substep(
f"Please ensure that OPACITY is between 0 and 1 in .env file", style="bold red"
)
# Gather all audio clips
audio_clips = []
@ -83,9 +85,7 @@ def make_final_video(number_of_clips, file_name):
.set_opacity(float(opacity)),
)
image_concat = concatenate_videoclips(
image_clips).set_position(("center", "center")
)
image_concat = concatenate_videoclips(image_clips).set_position(("center", "center"))
image_concat.audio = audio_composite
final = CompositeVideoClip([background_clip, image_concat])

@ -40,14 +40,11 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme):
print_substep("Post is NSFW. You are spicy...")
page.locator('[data-testid="content-gate"] button').click()
page.locator('[data-test-id="post-content"]').screenshot(
path="assets/png/title.png"
)
page.locator('[data-test-id="post-content"]').screenshot(path="assets/png/title.png")
for idx, comment in track(
enumerate(reddit_object["comments"]), "Downloading screenshots..."
):
# Stop if we have reached the screenshot_num
if idx >= screenshot_num:
break
@ -56,10 +53,8 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme):
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/png/comment_{idx}.png"
)
page.locator(
f"#t1_{comment['comment_id']}"
).screenshot(path=f"assets/png/comment_{idx}.png")
print_substep(
"Screenshots downloaded Successfully.", style="bold green"
)
print_substep("Screenshots downloaded Successfully.", style="bold green")

Loading…
Cancel
Save