Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Fancy title screen #2051

Merged
merged 28 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d1bb2d1
Fix for new UI by changing domain
Cyteon Mar 20, 2024
f1cce11
Delete video_creation/data/videos.json
Cyteon Mar 20, 2024
853ba49
Merge branch 'develop' into master
Cyteon Mar 20, 2024
b508f2a
meme support
Cyteon Mar 22, 2024
410f442
Revert "meme support"
Cyteon Mar 22, 2024
8859e01
Fix random voice prompt
JasonLovesDoggo Apr 18, 2024
301bb2c
Merge pull request #2020 from elebumm/JasonLovesDoggo-patch-1
JasonLovesDoggo Apr 18, 2024
cb68e84
Update broken discord url
JasonLovesDoggo Apr 20, 2024
69fa2a4
Merge pull request #2026 from elebumm/JasonLovesDoggo-patch-1
JasonLovesDoggo Apr 20, 2024
6a48f22
Update main.py
JasonLovesDoggo Apr 21, 2024
340762e
Merge pull request #2028 from elebumm/JasonLovesDoggo-patch-1
JasonLovesDoggo Apr 21, 2024
1b146ab
fix: Fixes #1812, random_voice True/False acceptance
MagicHatJo Sep 1, 2023
35fac14
fix: fixed the GUI
JasonLovesDoggo Sep 3, 2023
fb49acd
Bump unidecode from 1.3.6 to 1.3.8
dependabot[bot] Jan 12, 2024
c84e34e
Bump transformers from 4.29.2 to 4.37.1
dependabot[bot] Jan 25, 2024
bbf5a82
fixup: Format Python code with Black
github-actions[bot] Jan 28, 2024
f827f9f
Bump pillow from 9.5.0 to 10.2.0
dependabot[bot] Jan 17, 2024
37faf2a
Bump torch from 2.0.1 to 2.2.0
dependabot[bot] Jan 31, 2024
d15740d
Bump gtts from 2.3.2 to 2.5.1
dependabot[bot] Jan 29, 2024
cdf8ad2
Bump transformers from 4.37.1 to 4.37.2
dependabot[bot] Feb 5, 2024
d42ff50
meme support
Cyteon Mar 22, 2024
903081f
Revert "meme support"
Cyteon Mar 22, 2024
bc0abb6
Merge conflict fix
Apr 26, 2024
64f2322
Git merge conflict was not actually resolved
Cyteon Apr 27, 2024
2096308
fancy title screen
May 19, 2024
b67d81a
Merge branch 'develop' into fancy-title-screen
Cyteon May 19, 2024
0522d19
some fixes
May 19, 2024
128953c
fix invite link, and add myself as maintainer
Cyteon May 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

assets/
assets/temp
assets/backgrounds
/.vscode
out
.DS_Store
Expand All @@ -244,4 +245,4 @@ video_creation/data/videos.json
video_creation/data/envvars.txt

config.toml
*.exe
*.exe
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ I have tried to simplify the code so anyone can read it and start contributing a

Please read our [contributing guidelines](CONTRIBUTING.md) for more detailed information.

### For any questions or support join the [Discord](https://discord.gg/Vkanmh6C8V) server
### For any questions or support join the [Discord](https://discord.gg/WBQT52RrHV) server
Cyteon marked this conversation as resolved.
Show resolved Hide resolved

## Developers and maintainers.

Expand Down
2 changes: 2 additions & 0 deletions TTS/streamlabs_polly.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ def run(self, text, filepath, random_voice: bool = False):
f"Please set the config variable STREAMLABS_POLLY_VOICE to a valid voice. options are: {voices}"
)
voice = str(settings.config["settings"]["tts"]["streamlabs_polly_voice"]).capitalize()

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)

Expand Down
Binary file added assets/title_template.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def shutdown() -> NoReturn:


if __name__ == "__main__":
if sys.version_info.major != 3 or sys.version_info.minor != 10:
if sys.version_info.major != 3 or sys.version_info.minor not in [10, 11]:
print(
"Hey! Congratulations, you've made it so far (which is pretty rare with no Python 3.10). Unfortunately, this program only works on Python 3.10. Please install Python 3.10 and try again."
)
Expand Down
2 changes: 1 addition & 1 deletion reddit/subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def get_subreddit_threads(POST_ID: str):
upvotes = submission.score
ratio = submission.upvote_ratio * 100
num_comments = submission.num_comments
threadurl = f"https://reddit.com{submission.permalink}"
threadurl = f"https://new.reddit.com/{submission.permalink}"

print_substep(f"Video will be: {submission.title} :thumbsup:", style="bold green")
print_substep(f"Thread url is: {threadurl} :thumbsup:", style="bold green")
Expand Down
1 change: 1 addition & 0 deletions utils/.config.template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ storymode_max_length = { optional = true, default = 1000, example = 1000, explan
resolution_w = { optional = false, default = 1080, example = 1440, explantation = "Sets the width in pixels of the final video" }
resolution_h = { optional = false, default = 1920, example = 2560, explantation = "Sets the height in pixels of the final video" }
zoom = { optional = true, default = 1, example = 1.1, explanation = "Sets the browser zoom level. Useful if you want the text larger.", type = "float", nmin = 0.1, nmax = 2, oob_error = "The text is really difficult to read at a zoom level higher than 2" }
channel_name = { optional = true, default = "Reddit Tales", example = "Reddit Stories", explanation = "Sets the channel name for the video" }

[settings.background]
background_video = { optional = true, default = "minecraft", example = "rocket-league", options = ["minecraft", "gta", "rocket-league", "motor-gta", "csgo-surf", "cluster-truck", "minecraft-2","multiversus","fall-guys","steep", ""], explanation = "Sets the background for the video based on game name" }
Expand Down
8 changes: 0 additions & 8 deletions utils/imagenarator.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,17 @@ def imagemaker(theme, reddit_obj: dict, txtclr, padding=5, transparent=False) ->
"""
Render Images for video
"""
title = process_text(reddit_obj["thread_title"], False)
texts = reddit_obj["thread_post"]
id = re.sub(r"[^\w\s-]", "", reddit_obj["thread_id"])

if transparent:
font = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), 100)
tfont = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), 100)
else:
tfont = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), 100) # for title
font = ImageFont.truetype(os.path.join("fonts", "Roboto-Regular.ttf"), 100)
size = (1920, 1080)

image = Image.new("RGBA", size, theme)

# for title
draw_multiple_line_text(image, title, tfont, txtclr, padding, wrap=30, transparent=transparent)

image.save(f"assets/temp/{id}/png/title.png")

for idx, text in track(enumerate(texts), "Rendering Image"):
image = Image.new("RGBA", size, theme)
text = process_text(text, False)
Expand Down
1 change: 0 additions & 1 deletion video_creation/data/videos.json

This file was deleted.

62 changes: 61 additions & 1 deletion video_creation/final_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import re
import tempfile
import threading
import textwrap
import time

from pathlib import Path
from os.path import exists # Needs to be imported specifically
from typing import Final
from typing import Tuple, Dict

import ffmpeg
import translators
from PIL import Image
from PIL import ImageDraw, ImageFont, Image
from rich.console import Console
from rich.progress import track

Expand Down Expand Up @@ -105,6 +108,41 @@ 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
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")

if len(lines) == 3:
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
elif len(lines) == 4:
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
elif len(lines) > 4:
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

for line in lines:
_, line_height = font.getsize(line)
draw.text((120, y), line, font=font, fill=text_color, align="left")
y += line_height + padding

return image


def merge_background_audio(audio: ffmpeg, reddit_id: str):
"""Gather an audio and merge with assets/backgrounds/background.mp3
Expand Down Expand Up @@ -201,6 +239,28 @@ 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")

title = reddit_obj["thread_title"]

title = name_normalize(title)

font_color = "#000000"
padding = 5

# create_fancy_thumbnail(image, text, text_color, padding
title_img = create_fancy_thumbnail(
title_template, title, font_color, padding
)

title_img.save(f"assets/temp/{reddit_id}/png/title.png")

# Copyright end

image_clips.insert(
0,
ffmpeg.input(f"assets/temp/{reddit_id}/png/title.png")["v"].filter(
Expand Down
13 changes: 7 additions & 6 deletions video_creation/screenshot_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +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...")
Expand All @@ -73,7 +74,7 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
print_substep("Launching Headless Browser...")

browser = p.chromium.launch(
headless=True
headless=False
) # headless=False will show the browser for debugging purposes
# Device scale factor (or dsf for short) allows us to increase the resolution of the screenshots
# When the dsf is 1, the width of the screenshot is 600 pixels
Expand All @@ -98,9 +99,9 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
page.set_viewport_size(ViewportSize(width=1920, height=1080))
page.wait_for_load_state()

page.locator('[name="username"]').fill(settings.config["reddit"]["creds"]["username"])
page.locator('[name="password"]').fill(settings.config["reddit"]["creds"]["password"])
page.locator("button[class$='m-full-width']").click()
page.locator(f'input[name="username"]').fill(settings.config["reddit"]["creds"]["username"])
page.locator(f'input[name="password"]').fill(settings.config["reddit"]["creds"]["password"])
page.get_by_role("button", name="Log In").click()
page.wait_for_timeout(5000)

login_error_div = page.locator(".AnimatedForm__errorMessage").first
Expand Down Expand Up @@ -218,7 +219,7 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
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"]}', timeout=0)
page.goto(f"https://new.reddit.com/{comment['comment_url']}")

# translate code

Expand Down Expand Up @@ -261,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")
Loading