fixup: Format Python code with Black
This commit is contained in:
1 parent
5fa7b112be
commit
31312a30d4
3 files changed
+36
-15
No files matched your search
@@ -47,7 +47,7 @@ class StreamlabsPolly:
|
||||
body = {"voice": voice, "text": text, "service": "polly"}
|
||||
headers = {"Referer": "https://streamlabs.com/"}
|
||||
response = requests.post(self.url, headers=headers, data=body)
|
||||
|
||||
|
||||
if not check_ratelimit(response):
|
||||
self.run(text, filepath, random_voice)
|
||||
|
||||
|
||||
@@ -108,33 +108,56 @@ def prepare_background(reddit_id: str, W: int, H: int) -> str:
|
||||
exit(1)
|
||||
return output_path
|
||||
|
||||
|
||||
def create_fancy_thumbnail(image, text, text_color, padding, wrap=35):
|
||||
print_step(f"Creating fancy thumbnail for: {text}")
|
||||
font_title_size = 47
|
||||
font = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), font_title_size)
|
||||
image_width, image_height = image.size
|
||||
lines = textwrap.wrap(text, width=wrap)
|
||||
y = (image_height / 2) - (((font.getsize(text)[1] + (len(lines) * padding) / len(lines)) * len(lines)) / 2) + 30
|
||||
y = (
|
||||
(image_height / 2)
|
||||
- (((font.getsize(text)[1] + (len(lines) * padding) / len(lines)) * len(lines)) / 2)
|
||||
+ 30
|
||||
)
|
||||
draw = ImageDraw.Draw(image)
|
||||
|
||||
username_font = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), 30)
|
||||
draw.text((205, 825), settings.config["settings"]["channel_name"], font=username_font, fill=text_color, align="left")
|
||||
draw.text(
|
||||
(205, 825),
|
||||
settings.config["settings"]["channel_name"],
|
||||
font=username_font,
|
||||
fill=text_color,
|
||||
align="left",
|
||||
)
|
||||
|
||||
if len(lines) == 3:
|
||||
lines = textwrap.wrap(text, width=wrap+10)
|
||||
lines = textwrap.wrap(text, width=wrap + 10)
|
||||
font_title_size = 40
|
||||
font = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), font_title_size)
|
||||
y = (image_height / 2) - (((font.getsize(text)[1] + (len(lines) * padding) / len(lines)) * len(lines)) / 2) + 35
|
||||
y = (
|
||||
(image_height / 2)
|
||||
- (((font.getsize(text)[1] + (len(lines) * padding) / len(lines)) * len(lines)) / 2)
|
||||
+ 35
|
||||
)
|
||||
elif len(lines) == 4:
|
||||
lines = textwrap.wrap(text, width=wrap+10)
|
||||
lines = textwrap.wrap(text, width=wrap + 10)
|
||||
font_title_size = 35
|
||||
font = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), font_title_size)
|
||||
y = (image_height / 2) - (((font.getsize(text)[1] + (len(lines) * padding) / len(lines)) * len(lines)) / 2) + 40
|
||||
y = (
|
||||
(image_height / 2)
|
||||
- (((font.getsize(text)[1] + (len(lines) * padding) / len(lines)) * len(lines)) / 2)
|
||||
+ 40
|
||||
)
|
||||
elif len(lines) > 4:
|
||||
lines = textwrap.wrap(text, width=wrap+10)
|
||||
lines = textwrap.wrap(text, width=wrap + 10)
|
||||
font_title_size = 30
|
||||
font = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), font_title_size)
|
||||
y = (image_height / 2) - (((font.getsize(text)[1] + (len(lines) * padding) / len(lines)) * len(lines)) / 2) + 30
|
||||
y = (
|
||||
(image_height / 2)
|
||||
- (((font.getsize(text)[1] + (len(lines) * padding) / len(lines)) * len(lines)) / 2)
|
||||
+ 30
|
||||
)
|
||||
|
||||
for line in lines:
|
||||
_, line_height = font.getsize(line)
|
||||
@@ -240,7 +263,7 @@ def make_final_video(
|
||||
image_clips = list()
|
||||
|
||||
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")
|
||||
@@ -253,9 +276,7 @@ def make_final_video(
|
||||
padding = 5
|
||||
|
||||
# create_fancy_thumbnail(image, text, text_color, padding
|
||||
title_img = create_fancy_thumbnail(
|
||||
title_template, title, font_color, padding
|
||||
)
|
||||
title_img = create_fancy_thumbnail(title_template, title, font_color, padding)
|
||||
|
||||
title_img.save(f"assets/temp/{reddit_id}/png/title.png")
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
|
||||
bgcolor = (255, 255, 255, 255)
|
||||
txtcolor = (0, 0, 0)
|
||||
transparent = False
|
||||
|
||||
|
||||
if storymode and settings.config["settings"]["storymodemethod"] == 1:
|
||||
# for idx,item in enumerate(reddit_object["thread_post"]):
|
||||
print_substep("Generating images...")
|
||||
@@ -262,4 +262,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")
|
||||
print_substep("Screenshots downloaded Successfully.", style="bold green")
|
||||
Reference in new issue
Block a user