Revert "meme support"

This reverts commit b508f2af73.
pull/1986/head
Kristian 9 months ago
parent b508f2af73
commit 410f442976

@ -75,7 +75,7 @@ class TTSEngine:
# processed_text = ##self.reddit_object["thread_post"] != "" # processed_text = ##self.reddit_object["thread_post"] != ""
idx = 0 idx = 0
if settings.config["settings"]["storymode"] and not settings.config["settings"]["mememode"]: if settings.config["settings"]["storymode"]:
if settings.config["settings"]["storymodemethod"] == 0: if settings.config["settings"]["storymodemethod"] == 0:
if len(self.reddit_object["thread_post"]) > self.tts_module.max_chars: if len(self.reddit_object["thread_post"]) > self.tts_module.max_chars:
self.split_post(self.reddit_object["thread_post"], "postaudio") self.split_post(self.reddit_object["thread_post"], "postaudio")

@ -1,7 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
import math import math
import sys import sys
import os
from os import name from os import name
from pathlib import Path from pathlib import Path
from subprocess import Popen from subprocess import Popen
@ -27,8 +26,6 @@ from video_creation.final_video import make_final_video
from video_creation.screenshot_downloader import get_screenshots_of_reddit_posts from video_creation.screenshot_downloader import get_screenshots_of_reddit_posts
from video_creation.voices import save_text_to_mp3 from video_creation.voices import save_text_to_mp3
from moviepy.editor import VideoFileClip, concatenate_videoclips
__VERSION__ = "3.2.1" __VERSION__ = "3.2.1"
print( print(
@ -66,50 +63,13 @@ def main(POST_ID=None) -> None:
def run_many(times) -> None: def run_many(times) -> None:
if not settings.config["settings"]["mememode"]: for x in range(1, times + 1):
for x in range(1, times + 1): print_step(
print_step( f'on the {x}{("th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th")[x % 10]} iteration of {times}'
f'on the {x}{("th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th")[x % 10]} iteration of {times}' ) # correct 1st 2nd 3rd 4th 5th....
) # correct 1st 2nd 3rd 4th 5th.... main()
main() Popen("cls" if name == "nt" else "clear", shell=True).wait()
Popen("cls" if name == "nt" else "clear", shell=True).wait()
else:
for x in range(1, times + 1):
print_step(
f'on the {x}{("th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th")[x % 10]} iteration of {times}'
) # correct 1st 2nd 3rd 4th 5th....
main()
Popen("cls" if name == "nt" else "clear", shell=True).wait()
make_meme_video()
def make_meme_video():
if not os.path.exists("./clipped"):
os.mkdir("./clipped")
directory = f'./results/{settings.config["reddit"]["thread"]["subreddit"]}'
print(directory)
# Get a list of all MP4 files in the directory
mp4_files = [f for f in os.listdir(directory) if f.endswith('.mp4')]
# Create a list of VideoFileClip objects
clips = [VideoFileClip(os.path.join(directory, f)) for f in mp4_files]
# Concatenate the clips into a single video
final_clip = concatenate_videoclips(clips)
# Write the final video to a file
output_file = './clipped/output.mp4'
final_clip.write_videofile(output_file)
# Close the video clips
for clip in clips:
clip.close()
# Delete the individual MP4 files
for f in mp4_files:
os.remove(os.path.join(directory, f))
def shutdown() -> NoReturn: def shutdown() -> NoReturn:
if "redditid" in globals(): if "redditid" in globals():

@ -25,8 +25,6 @@ theme = { optional = false, default = "dark", example = "light", options = ["dar
times_to_run = { optional = false, default = 1, example = 2, explanation = "Used if you want to run multiple times. Set to an int e.g. 4 or 29 or 1", type = "int", nmin = 1, oob_error = "It's very hard to run something less than once." } times_to_run = { optional = false, default = 1, example = 2, explanation = "Used if you want to run multiple times. Set to an int e.g. 4 or 29 or 1", type = "int", nmin = 1, oob_error = "It's very hard to run something less than once." }
opacity = { optional = false, default = 0.9, example = 0.8, explanation = "Sets the opacity of the comments when overlayed over the background", type = "float", nmin = 0, nmax = 1, oob_error = "The opacity HAS to be between 0 and 1", input_error = "The opacity HAS to be a decimal number between 0 and 1" } opacity = { optional = false, default = 0.9, example = 0.8, explanation = "Sets the opacity of the comments when overlayed over the background", type = "float", nmin = 0, nmax = 1, oob_error = "The opacity HAS to be between 0 and 1", input_error = "The opacity HAS to be a decimal number between 0 and 1" }
#transition = { optional = true, default = 0.2, example = 0.2, explanation = "Sets the transition time (in seconds) between the comments. Set to 0 if you want to disable it.", type = "float", nmin = 0, nmax = 2, oob_error = "The transition HAS to be between 0 and 2", input_error = "The opacity HAS to be a decimal number between 0 and 2" } #transition = { optional = true, default = 0.2, example = 0.2, explanation = "Sets the transition time (in seconds) between the comments. Set to 0 if you want to disable it.", type = "float", nmin = 0, nmax = 2, oob_error = "The transition HAS to be between 0 and 2", input_error = "The opacity HAS to be a decimal number between 0 and 2" }
mememode = { optional = true, type = "bool", default = false, example = false, options = [true, false,], explanation = "Only show post content, and multipile of them (no comments)" }
memes_per_vid = { optional = true, default = 10, example = 10, explanation = "Number of memes per video", type = "int", nmin = 1, oob_error = "It's very hard to run something less than once." }
storymode = { optional = true, type = "bool", default = false, example = false, options = [true, false,], explanation = "Only read out title and post content, great for subreddits with stories" } storymode = { optional = true, type = "bool", default = false, example = false, options = [true, false,], explanation = "Only read out title and post content, great for subreddits with stories" }
storymodemethod= { optional = true, default = 1, example = 1, explanation = "Style that's used for the storymode. Set to 0 for single picture display in whole video, set to 1 for fancy looking video ", type = "int", nmin = 0, oob_error = "It's very hard to run something less than once.", options = [0, 1] } storymodemethod= { optional = true, default = 1, example = 1, explanation = "Style that's used for the storymode. Set to 0 for single picture display in whole video, set to 1 for fancy looking video ", type = "int", nmin = 0, oob_error = "It's very hard to run something less than once.", options = [0, 1] }
storymode_max_length = { optional = true, default = 1000, example = 1000, explanation = "Max length of the storymode video in characters. 200 characters are approximately 50 seconds.", type = "int", nmin = 1, oob_error = "It's very hard to make a video under a second." } storymode_max_length = { optional = true, default = 1000, example = 1000, explanation = "Max length of the storymode video in characters. 200 characters are approximately 50 seconds.", type = "int", nmin = 1, oob_error = "It's very hard to make a video under a second." }

@ -50,7 +50,7 @@ def get_subreddit_undone(submissions: list, subreddit, times_checked=0, similari
f'This post has under the specified minimum of comments ({settings.config["reddit"]["thread"]["min_comments"]}). Skipping...' f'This post has under the specified minimum of comments ({settings.config["reddit"]["thread"]["min_comments"]}). Skipping...'
) )
continue continue
if settings.config["settings"]["storymode"] and not settings.config["settings"]["mememode"]: if settings.config["settings"]["storymode"]:
if not submission.selftext: if not submission.selftext:
print_substep("You are trying to use story mode on post with no post text") print_substep("You are trying to use story mode on post with no post text")
continue continue
@ -65,7 +65,7 @@ def get_subreddit_undone(submissions: list, subreddit, times_checked=0, similari
continue continue
elif len(submission.selftext) < 30: elif len(submission.selftext) < 30:
continue continue
if settings.config["settings"]["storymode"] and not submission.is_self and not settings.config["settings"]["mememode"]: if settings.config["settings"]["storymode"] and not submission.is_self:
continue continue
if similarity_scores is not None: if similarity_scores is not None:
return submission, similarity_scores[i].item() return submission, similarity_scores[i].item()

@ -99,7 +99,7 @@ def prepare_background(reddit_id: str, W: int, H: int) -> str:
.overwrite_output() .overwrite_output()
) )
try: try:
output.run(quiet=False) output.run(quiet=True)
except ffmpeg.Error as e: except ffmpeg.Error as e:
print(e.stderr.decode("utf8")) print(e.stderr.decode("utf8"))
exit(1) exit(1)
@ -166,13 +166,12 @@ def make_final_video(
if settings.config["settings"]["storymode"]: if settings.config["settings"]["storymode"]:
if settings.config["settings"]["storymodemethod"] == 0: if settings.config["settings"]["storymodemethod"] == 0:
audio_clips = [ffmpeg.input(f"assets/temp/{reddit_id}/mp3/title.mp3")] audio_clips = [ffmpeg.input(f"assets/temp/{reddit_id}/mp3/title.mp3")]
#audio_clips.insert(1, ffmpeg.input(f"assets/temp/{reddit_id}/mp3/postaudio.mp3")) audio_clips.insert(1, ffmpeg.input(f"assets/temp/{reddit_id}/mp3/postaudio.mp3"))
elif settings.config["settings"]["storymodemethod"] == 1: elif settings.config["settings"]["storymodemethod"] == 1:
if not settings.config["settings"]["mememode"]: audio_clips = [
audio_clips = [ ffmpeg.input(f"assets/temp/{reddit_id}/mp3/postaudio-{i}.mp3")
ffmpeg.input(f"assets/temp/{reddit_id}/mp3/postaudio-{i}.mp3") for i in track(range(number_of_clips + 1), "Collecting the audio files...")
for i in track(range(number_of_clips + 1), "Collecting the audio files...") ]
]
audio_clips.insert(0, ffmpeg.input(f"assets/temp/{reddit_id}/mp3/title.mp3")) audio_clips.insert(0, ffmpeg.input(f"assets/temp/{reddit_id}/mp3/title.mp3"))
else: else:
@ -192,7 +191,7 @@ def make_final_video(
audio_concat = ffmpeg.concat(*audio_clips, a=1, v=0) audio_concat = ffmpeg.concat(*audio_clips, a=1, v=0)
ffmpeg.output( ffmpeg.output(
audio_concat, f"assets/temp/{reddit_id}/audio.mp3", **{"b:a": "192k"} audio_concat, f"assets/temp/{reddit_id}/audio.mp3", **{"b:a": "192k"}
).overwrite_output().run(quiet=False) ).overwrite_output().run(quiet=True)
console.log(f"[bold green] Video Will Be: {length} Seconds Long") console.log(f"[bold green] Video Will Be: {length} Seconds Long")
@ -205,20 +204,18 @@ def make_final_video(
image_clips.insert( image_clips.insert(
0, 0,
ffmpeg.input(f"assets/temp/{reddit_id}/png/title.png")["v"].filter( ffmpeg.input(f"assets/temp/{reddit_id}/png/title.png")["v"].filter(
"scale", screenshot_width, -1, "scale", screenshot_width, -1
), ),
) )
current_time = 0 current_time = 0
if settings.config["settings"]["storymode"]: if settings.config["settings"]["storymode"]:
audio_clips_durations = [] audio_clips_durations = [
if not settings.config["settings"]["mememode"]: float(
audio_clips_durations = [ ffmpeg.probe(f"assets/temp/{reddit_id}/mp3/postaudio-{i}.mp3")["format"]["duration"]
float( )
ffmpeg.probe(f"assets/temp/{reddit_id}/mp3/postaudio-{i}.mp3")["format"]["duration"] for i in range(number_of_clips)
) ]
for i in range(number_of_clips)
]
audio_clips_durations.insert( audio_clips_durations.insert(
0, 0,
float(ffmpeg.probe(f"assets/temp/{reddit_id}/mp3/title.mp3")["format"]["duration"]), float(ffmpeg.probe(f"assets/temp/{reddit_id}/mp3/title.mp3")["format"]["duration"]),
@ -230,8 +227,6 @@ def make_final_video(
"scale", screenshot_width, -1 "scale", screenshot_width, -1
), ),
) )
if settings.config["settings"]["mememode"]: audio_clips_durations[0] += 2
background_clip = background_clip.overlay( background_clip = background_clip.overlay(
image_clips[0], image_clips[0],
enable=f"between(t,{current_time},{current_time + audio_clips_durations[0]})", enable=f"between(t,{current_time},{current_time + audio_clips_durations[0]})",
@ -239,7 +234,7 @@ def make_final_video(
y="(main_h-overlay_h)/2", y="(main_h-overlay_h)/2",
) )
current_time += audio_clips_durations[0] current_time += audio_clips_durations[0]
elif settings.config["settings"]["storymodemethod"] == 1 and not settings.config["settings"]["mememode"]: elif settings.config["settings"]["storymodemethod"] == 1:
for i in track(range(0, number_of_clips + 1), "Collecting the image files..."): for i in track(range(0, number_of_clips + 1), "Collecting the image files..."):
image_clips.append( image_clips.append(
ffmpeg.input(f"assets/temp/{reddit_id}/png/img{i}.png")["v"].filter( ffmpeg.input(f"assets/temp/{reddit_id}/png/img{i}.png")["v"].filter(
@ -253,8 +248,6 @@ def make_final_video(
y="(main_h-overlay_h)/2", y="(main_h-overlay_h)/2",
) )
current_time += audio_clips_durations[i] current_time += audio_clips_durations[i]
elif settings.config["settings"]["mememode"]:
pass
else: else:
for i in range(0, number_of_clips + 1): for i in range(0, number_of_clips + 1):
image_clips.append( image_clips.append(
@ -361,10 +354,10 @@ def make_final_video(
"threads": multiprocessing.cpu_count(), "threads": multiprocessing.cpu_count(),
}, },
).overwrite_output().global_args("-progress", progress.output_file.name).run( ).overwrite_output().global_args("-progress", progress.output_file.name).run(
quiet=False, quiet=True,
overwrite_output=True, overwrite_output=True,
capture_stdout=False, capture_stdout=False,
capture_stderr=True, capture_stderr=False,
) )
except ffmpeg.Error as e: except ffmpeg.Error as e:
print(e.stderr.decode("utf8")) print(e.stderr.decode("utf8"))
@ -391,10 +384,10 @@ def make_final_video(
"threads": multiprocessing.cpu_count(), "threads": multiprocessing.cpu_count(),
}, },
).overwrite_output().global_args("-progress", progress.output_file.name).run( ).overwrite_output().global_args("-progress", progress.output_file.name).run(
quiet=False, quiet=True,
overwrite_output=True, overwrite_output=True,
capture_stdout=False, capture_stdout=False,
capture_stderr=True, capture_stderr=False,
) )
except ffmpeg.Error as e: except ffmpeg.Error as e:
print(e.stderr.decode("utf8")) print(e.stderr.decode("utf8"))

@ -28,7 +28,6 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
H: Final[int] = int(settings.config["settings"]["resolution_h"]) H: Final[int] = int(settings.config["settings"]["resolution_h"])
lang: Final[str] = settings.config["reddit"]["thread"]["post_lang"] lang: Final[str] = settings.config["reddit"]["thread"]["post_lang"]
storymode: Final[bool] = settings.config["settings"]["storymode"] storymode: Final[bool] = settings.config["settings"]["storymode"]
mememode: Final[bool] = settings.config["settings"]["mememode"]
print_step("Downloading screenshots of reddit posts...") print_step("Downloading screenshots of reddit posts...")
reddit_id = re.sub(r"[^\w\s-]", "", reddit_object["thread_id"]) reddit_id = re.sub(r"[^\w\s-]", "", reddit_object["thread_id"])
@ -169,8 +168,6 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
print_substep("Skipping translation...") print_substep("Skipping translation...")
postcontentpath = f"assets/temp/{reddit_id}/png/title.png" postcontentpath = f"assets/temp/{reddit_id}/png/title.png"
try: try:
if settings.config["settings"]["zoom"] != 1: if settings.config["settings"]["zoom"] != 1:
# store zoom settings # store zoom settings
@ -184,7 +181,6 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
page.screenshot(clip=location, path=postcontentpath) page.screenshot(clip=location, path=postcontentpath)
else: else:
page.locator('[data-test-id="post-content"]').screenshot(path=postcontentpath) page.locator('[data-test-id="post-content"]').screenshot(path=postcontentpath)
except Exception as e: except Exception as e:
print_substep("Something went wrong!", style="red") print_substep("Something went wrong!", style="red")
resp = input( resp = input(
@ -204,11 +200,11 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
raise e raise e
if storymode and not mememode: if storymode:
page.locator('[data-click-id="text"]').first.screenshot( page.locator('[data-click-id="text"]').first.screenshot(
path=f"assets/temp/{reddit_id}/png/story_content.png" path=f"assets/temp/{reddit_id}/png/story_content.png"
) )
elif not mememode: else:
for idx, comment in enumerate( for idx, comment in enumerate(
track( track(
reddit_object["comments"][:screenshot_num], reddit_object["comments"][:screenshot_num],

Loading…
Cancel
Save