From 054cc84186b75e1ea58169a0e2f8baac8f9b8573 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Fri, 10 Jun 2022 23:15:19 +0200 Subject: [PATCH 01/19] Update subreddit.py --- reddit/subreddit.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index c560293..a448dcd 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -67,13 +67,14 @@ def get_subreddit_threads(): for top_level_comment in submission.comments: if not top_level_comment.stickied: - content["comments"].append( - { - "comment_body": top_level_comment.body, - "comment_url": top_level_comment.permalink, - "comment_id": top_level_comment.id, - } - ) + if not comment.author == None: + content["comments"].append( + { + "comment_body": top_level_comment.body, + "comment_url": top_level_comment.permalink, + "comment_id": top_level_comment.id, + } + ) except AttributeError as e: pass From d907dc79177124e5e6d42ed78129816bbf10fd0e Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Mon, 13 Jun 2022 14:03:14 -0700 Subject: [PATCH 02/19] fixed error --- reddit/subreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index a448dcd..b01b058 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -67,7 +67,7 @@ def get_subreddit_threads(): for top_level_comment in submission.comments: if not top_level_comment.stickied: - if not comment.author == None: + if not top_level_comment.author == None: content["comments"].append( { "comment_body": top_level_comment.body, From c9421ca4bcf8273e1eef3f27a8cb41c8627c311c Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 22 Jun 2022 22:37:07 -0400 Subject: [PATCH 03/19] fix: video chopping issue closes #385 fixes #348 --- video_creation/background.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/video_creation/background.py b/video_creation/background.py index fb300e6..d78ce15 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -2,9 +2,11 @@ import random from os import listdir, environ from pathlib import Path from random import randrange -from pytube import YouTube -from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip + from moviepy.editor import VideoFileClip +from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip +from pytube import YouTube + from utils.console import print_step, print_substep @@ -26,7 +28,7 @@ def download_background(): ] # note: make sure the file name doesn't include an - in it if not len(listdir("./assets/backgrounds")) >= len( - background_options + background_options ): # if there are any background videos not installed print_step( "We need to download the backgrounds videos. they are fairly large but it's only done once. 😎" @@ -51,11 +53,17 @@ def chop_background_video(video_length): background = VideoFileClip(f"assets/backgrounds/{choice}") start_time, end_time = get_start_and_end_times(video_length, background.duration) - ffmpeg_extract_subclip( - f"assets/backgrounds/{choice}", - start_time, - end_time, - targetname="assets/temp/background.mp4", - ) + try: + ffmpeg_extract_subclip( + f"assets/backgrounds/{choice}", + start_time, + end_time, + targetname="assets/temp/background.mp4", + ) + except (OSError, IOError): # ffmpeg issue see #348 + print_substep("FFMPEG issue. Trying again...") + with VideoFileClip(f"assets/backgrounds/{choice}") as video: + new = video.subclip(start_time, end_time) + new.write_videofile("assets/temp/background.mp4") print_substep("Background video chopped successfully!", style="bold green") return True From e7d19402c7a05580da75c402af73b1e7fb8050b7 Mon Sep 17 00:00:00 2001 From: LevaniVashadze <100613979+LevaniVashadze@users.noreply.github.com> Date: Fri, 24 Jun 2022 12:57:56 +0400 Subject: [PATCH 04/19] python version update to python 3.7 playwright needs python 3.7+ as seen here https://playwright.dev/python/docs/intro#system-requirements Getting started | Playwright Python --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 77b11b2..ace74f8 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ The only original thing being done is the editing and gathering of all materials ## Requirements -- Python 3.6+ +- Python 3.7+ - Playwright (this should install automatically in installation) ## Installation 👩‍💻 From 0d6e1238a7a563263b513bd614da313fccd0feab Mon Sep 17 00:00:00 2001 From: Vaughn Bosu <76852813+null3000@users.noreply.github.com> Date: Fri, 24 Jun 2022 18:32:16 -0700 Subject: [PATCH 05/19] Update final_video.py --- video_creation/final_video.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 37b1ac2..9ecb4d1 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -2,6 +2,7 @@ import json import os import time +import multiprocessing from os.path import exists from moviepy.editor import ( @@ -134,7 +135,7 @@ def make_final_video(number_of_clips, length): print_substep("the results folder didn't exist so I made it") os.mkdir("./results") - final.write_videofile("assets/temp/temp.mp4", fps=30, audio_codec="aac", audio_bitrate="192k") + final.write_videofile("assets/temp/temp.mp4", verbose=False, logger=None, threads=multiprocessing.cpu_count(), fps=30, audio_codec="aac", audio_bitrate="192k") ffmpeg_tools.ffmpeg_extract_subclip( "assets/temp/temp.mp4", 0, length, targetname=f"results/{filename}" ) From eb00cf319a939d1f23d35ccd0d6f283091132b07 Mon Sep 17 00:00:00 2001 From: Vaughn Bosu <76852813+null3000@users.noreply.github.com> Date: Fri, 24 Jun 2022 18:48:13 -0700 Subject: [PATCH 06/19] Update final_video.py --- video_creation/final_video.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 9ecb4d1..19621ea 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -135,7 +135,7 @@ def make_final_video(number_of_clips, length): print_substep("the results folder didn't exist so I made it") os.mkdir("./results") - final.write_videofile("assets/temp/temp.mp4", verbose=False, logger=None, threads=multiprocessing.cpu_count(), fps=30, audio_codec="aac", audio_bitrate="192k") + final.write_videofile("assets/temp/temp.mp4", threads=multiprocessing.cpu_count(), fps=30, audio_codec="aac", audio_bitrate="192k") ffmpeg_tools.ffmpeg_extract_subclip( "assets/temp/temp.mp4", 0, length, targetname=f"results/{filename}" ) From 7b8e60f8dbe83fd00527ecd613a63951c6550000 Mon Sep 17 00:00:00 2001 From: Vaughn Bosu <76852813+null3000@users.noreply.github.com> Date: Fri, 24 Jun 2022 18:50:36 -0700 Subject: [PATCH 07/19] Update final_video.py --- video_creation/final_video.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 19621ea..3252d93 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -135,7 +135,7 @@ def make_final_video(number_of_clips, length): print_substep("the results folder didn't exist so I made it") os.mkdir("./results") - final.write_videofile("assets/temp/temp.mp4", threads=multiprocessing.cpu_count(), fps=30, audio_codec="aac", audio_bitrate="192k") + final.write_videofile("assets/temp/temp.mp4", verbose=False, threads=multiprocessing.cpu_count(), fps=30, audio_codec="aac", audio_bitrate="192k") ffmpeg_tools.ffmpeg_extract_subclip( "assets/temp/temp.mp4", 0, length, targetname=f"results/{filename}" ) From acfcf2adc829556f8ef577472f79af07eccb19a4 Mon Sep 17 00:00:00 2001 From: Jason <66544866+JasonLovesDoggo@users.noreply.github.com> Date: Sat, 25 Jun 2022 16:10:20 -0400 Subject: [PATCH 08/19] Update screenshot_downloader.py --- video_creation/screenshot_downloader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 4620677..9317e87 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -3,7 +3,7 @@ from os import getenv import os from pathlib import Path -from playwright.async_api import async_playwright +from playwright.async_api import async_playwright # do not remove this line from playwright.sync_api import sync_playwright, ViewportSize from rich.progress import track From f9e0c9a2f87a93c946c0a2e4787b6617992da0f7 Mon Sep 17 00:00:00 2001 From: Jason <66544866+JasonLovesDoggo@users.noreply.github.com> Date: Sat, 25 Jun 2022 16:20:50 -0400 Subject: [PATCH 09/19] Update streamlabs_polly.py Potential fix for #691 --- TTS/streamlabs_polly.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TTS/streamlabs_polly.py b/TTS/streamlabs_polly.py index 500cb16..8a24364 100644 --- a/TTS/streamlabs_polly.py +++ b/TTS/streamlabs_polly.py @@ -28,7 +28,7 @@ voices = [ class StreamlabsPolly: def __init__(self): self.url = "https://streamlabs.com/polly/speak" - self.max_chars = 550 + self.max_chars = 349 self.voices = voices def run(self, text, filepath, random_voice: bool = False): From 69f4f59bb6967f6359f489fe400a8a0f8aff736e Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Mon, 27 Jun 2022 16:22:01 +0100 Subject: [PATCH 10/19] Formatted with python-black --- main.py | 2 - reddit/subreddit.py | 16 ++++---- utils/checker.py | 54 ++++++++++++++++++------- utils/cleanup.py | 6 ++- utils/console.py | 8 +++- utils/subreddit.py | 10 ++--- utils/videos.py | 6 ++- video_creation/background.py | 10 ++--- video_creation/final_video.py | 16 ++++---- video_creation/screenshot_downloader.py | 22 ++++++---- video_creation/voices.py | 4 +- 11 files changed, 95 insertions(+), 59 deletions(-) diff --git a/main.py b/main.py index 5f01e5f..1666f17 100755 --- a/main.py +++ b/main.py @@ -37,8 +37,6 @@ def main(): load_dotenv() cleanup() - - reddit_object = get_subreddit_threads() length, number_of_comments = save_text_to_mp3(reddit_object) download_screenshots_of_reddit_posts(reddit_object, number_of_comments) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index fbfc285..98bf8a1 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -105,13 +105,13 @@ def get_subreddit_threads(): continue # # see https://github.com/JasonLovesDoggo/RedditVideoMakerBot/issues/78 if not top_level_comment.stickied: if len(top_level_comment.body) <= int(try_env("MAX_COMMENT_LENGTH", 500)): - if not top_level_comment.author == None: - content["comments"].append( - { - "comment_body": top_level_comment.body, - "comment_url": top_level_comment.permalink, - "comment_id": top_level_comment.id, - } - ) + if not top_level_comment.author == None: + content["comments"].append( + { + "comment_body": top_level_comment.body, + "comment_url": top_level_comment.permalink, + "comment_id": top_level_comment.id, + } + ) print_substep("Received subreddit threads Successfully.", style="bold green") return content diff --git a/utils/checker.py b/utils/checker.py index 668b40f..9388029 100755 --- a/utils/checker.py +++ b/utils/checker.py @@ -15,7 +15,7 @@ def check_env() -> bool: Returns: bool: Whether or not everything was put in properly - """ + """ if not os.path.exists(".env.template"): console.print("[red]Couldn't find .env.template. Unable to check variables.") return True @@ -35,7 +35,11 @@ def check_env() -> bool: req_envs = [] var_optional = False for line in template.readlines(): - if line.startswith("#") is not True and "=" in line and var_optional is not True: + if ( + line.startswith("#") is not True + and "=" in line + and var_optional is not True + ): req_envs.append(line.split("=")[0]) if "#" in line: examples[line.split("=")[0]] = "#".join(line.split("#")[1:]).strip() @@ -56,7 +60,9 @@ def check_env() -> bool: ) var_optional = False elif line.startswith("#MATCH_TYPE "): - types[req_envs[-1]] = eval(line.removeprefix("#MATCH_TYPE ")[:-1].split()[0]) + types[req_envs[-1]] = eval( + line.removeprefix("#MATCH_TYPE ")[:-1].split()[0] + ) var_optional = False elif line.startswith("#EXPLANATION "): explanations[req_envs[-1]] = line.removeprefix("#EXPLANATION ")[:-1] @@ -82,9 +88,9 @@ def check_env() -> bool: try: temp = types[env](value) if env in bounds.keys(): - (bounds[env][0] <= temp or incorrect.add(env)) and len(bounds[env]) > 1 and ( - bounds[env][1] >= temp or incorrect.add(env) - ) + (bounds[env][0] <= temp or incorrect.add(env)) and len( + bounds[env] + ) > 1 and (bounds[env][1] >= temp or incorrect.add(env)) except ValueError: incorrect.add(env) @@ -107,11 +113,17 @@ def check_env() -> bool: for env in missing: table.add_row( env, - explanations[env] if env in explanations.keys() else "No explanation given", + explanations[env] + if env in explanations.keys() + else "No explanation given", examples[env] if env in examples.keys() else "", - str(bounds[env][0]) if env in bounds.keys() and bounds[env][1] is not None else "", + str(bounds[env][0]) + if env in bounds.keys() and bounds[env][1] is not None + else "", str(bounds[env][1]) - if env in bounds.keys() and len(bounds[env]) > 1 and bounds[env][1] is not None + if env in bounds.keys() + and len(bounds[env]) > 1 + and bounds[env][1] is not None else "", ) console.print(table) @@ -128,7 +140,9 @@ def check_env() -> bool: title_style="#C0CAF5 bold", ) table.add_column("Variable", justify="left", style="#7AA2F7 bold", no_wrap=True) - table.add_column("Current value", justify="left", style="#F7768E", no_wrap=False) + table.add_column( + "Current value", justify="left", style="#F7768E", no_wrap=False + ) table.add_column("Explanation", justify="left", style="#BB9AF7", no_wrap=False) table.add_column("Example", justify="center", style="#F7768E", no_wrap=True) table.add_column("Min", justify="right", style="#F7768E", no_wrap=True) @@ -137,10 +151,14 @@ def check_env() -> bool: table.add_row( env, os.getenv(env), - explanations[env] if env in explanations.keys() else "No explanation given", + explanations[env] + if env in explanations.keys() + else "No explanation given", str(types[env].__name__) if env in types.keys() else "str", str(bounds[env][0]) if env in bounds.keys() else "None", - str(bounds[env][1]) if env in bounds.keys() and len(bounds[env]) > 1 else "None", + str(bounds[env][1]) + if env in bounds.keys() and len(bounds[env]) > 1 + else "None", ) missing.add(env) console.print(table) @@ -177,11 +195,17 @@ def check_env() -> bool: if env in explanations.keys() else "Incorrect input. Try again.", bounds[env][0] if env in bounds.keys() else None, - bounds[env][1] if env in bounds.keys() and len(bounds[env]) > 1 else None, - oob_errors[env] if env in oob_errors.keys() else "Input too long/short.", + bounds[env][1] + if env in bounds.keys() and len(bounds[env]) > 1 + else None, + oob_errors[env] + if env in oob_errors.keys() + else "Input too long/short.", extra_info="[#C0CAF5 bold]⮶ " + ( - explanations[env] if env in explanations.keys() else "No info available" + explanations[env] + if env in explanations.keys() + else "No info available" ), ) ) diff --git a/utils/cleanup.py b/utils/cleanup.py index 858cfe9..44629a9 100644 --- a/utils/cleanup.py +++ b/utils/cleanup.py @@ -7,10 +7,12 @@ def cleanup() -> int: Returns: int: How many files were deleted - """ + """ if exists("./assets/temp"): count = 0 - files = [f for f in os.listdir(".") if f.endswith(".mp4") and "temp" in f.lower()] + files = [ + f for f in os.listdir(".") if f.endswith(".mp4") and "temp" in f.lower() + ] count += len(files) for f in files: os.remove(f) diff --git a/utils/console.py b/utils/console.py index 5a041ec..2a9296c 100644 --- a/utils/console.py +++ b/utils/console.py @@ -64,10 +64,14 @@ def handle_input( except ValueError: console.print("[red]" + err_message) # Type conversion failed continue - if nmin is not None and len(user_input) < nmin: # Check if string is long enough + if ( + nmin is not None and len(user_input) < nmin + ): # Check if string is long enough console.print("[red]" + oob_error) continue - if nmax is not None and len(user_input) > nmax: # Check if string is not too long + if ( + nmax is not None and len(user_input) > nmax + ): # Check if string is not too long console.print("[red]" + oob_error) continue break diff --git a/utils/subreddit.py b/utils/subreddit.py index 3c5cb22..a40b6c3 100644 --- a/utils/subreddit.py +++ b/utils/subreddit.py @@ -9,11 +9,11 @@ def get_subreddit_undone(submissions: list, subreddit): Args: submissions (list): List of posts that are going to potentially be generated into a video - subreddit (praw.Reddit.SubredditHelper): Chosen subreddit + subreddit (praw.Reddit.SubredditHelper): Chosen subreddit Returns: Any: The submission that has not been done - """ + """ """ recursively checks if the top submission in the list was already done. """ @@ -36,8 +36,8 @@ def get_subreddit_undone(submissions: list, subreddit): ) # all of the videos in hot have already been done -def already_done(done_videos: list, submission)->bool: - """Checks to see if the given submission is in the list of videos +def already_done(done_videos: list, submission) -> bool: + """Checks to see if the given submission is in the list of videos Args: done_videos (list): Finished videos @@ -45,7 +45,7 @@ def already_done(done_videos: list, submission)->bool: Returns: Boolean: Whether the video was found in the list - """ + """ for video in done_videos: if video["id"] == str(submission): diff --git a/utils/videos.py b/utils/videos.py index e6510fe..8d6021f 100755 --- a/utils/videos.py +++ b/utils/videos.py @@ -5,8 +5,10 @@ from utils.console import print_step def check_done( - redditobj:dict[str], -)->dict[str]|None: # don't set this to be run anyplace that isn't subreddit.py bc of inspect stack + redditobj: dict[str], +) -> dict[ + str +] | None: # don't set this to be run anyplace that isn't subreddit.py bc of inspect stack """Checks if the chosen post has already been generated Args: diff --git a/video_creation/background.py b/video_creation/background.py index 347ac35..a99355c 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -10,7 +10,7 @@ from pytube import YouTube from utils.console import print_step, print_substep -def get_start_and_end_times(video_length:int, length_of_clip:int)->tuple[int,int]: +def get_start_and_end_times(video_length: int, length_of_clip: int) -> tuple[int, int]: """Generates a random interval of time to be used as the beckground of the video. Args: @@ -19,7 +19,7 @@ def get_start_and_end_times(video_length:int, length_of_clip:int)->tuple[int,int Returns: tuple[int,int]: Start and end time of the randomized interval - """ + """ random_time = randrange(180, int(length_of_clip) - int(video_length)) return random_time, random_time + video_length @@ -37,7 +37,7 @@ def download_background(): ] # note: make sure the file name doesn't include an - in it if not len(listdir("./assets/backgrounds")) >= len( - background_options + background_options ): # if there are any background videos not installed print_step( "We need to download the backgrounds videos. they are fairly large but it's only done once. 😎" @@ -56,12 +56,12 @@ def download_background(): ) -def chop_background_video(video_length:int): +def chop_background_video(video_length: int): """Generates the background footage to be used in the video and writes it to assets/temp/background.mp4 Args: video_length (int): Length of the clip where the background footage is to be taken out of - """ + """ print_step("Finding a spot in the backgrounds video to chop...✂️") choice = random.choice(listdir("assets/backgrounds")) environ["background_credit"] = choice.split("-")[0] diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 146fab8..c05006c 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -26,13 +26,13 @@ console = Console() W, H = 1080, 1920 -def make_final_video(number_of_clips:int, length:int): +def make_final_video(number_of_clips: int, length: int): """Gathers audio clips, gathers all screenshots, stitches them together and saves the final video to assets/temp Args: number_of_clips (int): Index to end at when going through the screenshots length (int): Length of the video - """ + """ print_step("Creating the final video 🎥") VideoFileClip.reW = lambda clip: clip.resize(width=W) VideoFileClip.reH = lambda clip: clip.resize(width=H) @@ -117,10 +117,8 @@ def make_final_video(number_of_clips:int, length:int): image_concat.audio = audio_composite final = CompositeVideoClip([background_clip, image_concat]) - filename = f"{get_video_title()}.mp4" - save_data(filename) if not exists("./results"): @@ -149,12 +147,13 @@ def make_final_video(number_of_clips:int, length:int): f"Reddit title: {os.getenv('VIDEO_TITLE')} \n Background Credit: {os.getenv('background_credit')}" ) -def save_data(filename:str): + +def save_data(filename: str): """Saves the videos that have already been generated to a JSON file in video_creation/data/videos.json Args: filename (str): The finished video title name - """ + """ with open("./video_creation/data/videos.json", "r+") as raw_vids: done_vids = json.load(raw_vids) if str(subreddit.submission.id) in [video["id"] for video in done_vids]: @@ -170,14 +169,15 @@ def save_data(filename:str): raw_vids.seek(0) json.dump(done_vids, raw_vids, ensure_ascii=False, indent=4) + def get_video_title() -> str: """Gets video title from env variable or gives it the name "final_video" Returns: str: Video title - """ + """ title = os.getenv("VIDEO_TITLE") or "final_video" if len(title) <= 35: return title else: - return title[0:30] + "..." \ No newline at end of file + return title[0:30] + "..." diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 9317e87..f638abc 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -3,7 +3,7 @@ from os import getenv import os from pathlib import Path -from playwright.async_api import async_playwright # do not remove this line +from playwright.async_api import async_playwright # do not remove this line from playwright.sync_api import sync_playwright, ViewportSize from rich.progress import track @@ -18,14 +18,14 @@ console = Console() storymode = False -def download_screenshots_of_reddit_posts(reddit_object:dict[str], screenshot_num:int): +def download_screenshots_of_reddit_posts(reddit_object: dict[str], screenshot_num: int): """Downloads screenshots of reddit posts as seen on the web. Downloads to assets/temp/png Args: reddit_object (dict[str]): Reddit object received from reddit/subreddit.py screenshot_num (int): Number of screenshots to downlaod - """ - + """ + print_step("Downloading screenshots of reddit posts...") # ! Make sure the reddit screenshots folder exists @@ -60,10 +60,13 @@ def download_screenshots_of_reddit_posts(reddit_object:dict[str], screenshot_num if getenv("POSTLANG"): print_substep("Translating post...") - texts_in_tl = ts.google(reddit_object["thread_title"], to_language=os.getenv("POSTLANG")) + texts_in_tl = ts.google( + reddit_object["thread_title"], to_language=os.getenv("POSTLANG") + ) page.evaluate( - 'tl_content => document.querySelector(\'[data-test-id="post-content"] > div:nth-child(3) > div > div\').textContent = tl_content', texts_in_tl + "tl_content => document.querySelector('[data-test-id=\"post-content\"] > div:nth-child(3) > div > div').textContent = tl_content", + texts_in_tl, ) else: print_substep("Skipping translation...") @@ -92,9 +95,12 @@ def download_screenshots_of_reddit_posts(reddit_object:dict[str], screenshot_num # translate code if getenv("POSTLANG"): - comment_tl = ts.google(comment["comment_body"], to_language=os.getenv("POSTLANG")) + comment_tl = ts.google( + comment["comment_body"], to_language=os.getenv("POSTLANG") + ) page.evaluate( - '([tl_content, tl_id]) => document.querySelector(`#t1_${tl_id} > div:nth-child(2) > div > div[data-testid="comment"] > div`).textContent = tl_content', [comment_tl, comment['comment_id']] + '([tl_content, tl_id]) => document.querySelector(`#t1_${tl_id} > div:nth-child(2) > div > div[data-testid="comment"] > div`).textContent = tl_content', + [comment_tl, comment["comment_id"]], ) page.locator(f"#t1_{comment['comment_id']}").screenshot( diff --git a/video_creation/voices.py b/video_creation/voices.py index f5ead42..cbe27f5 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -25,7 +25,7 @@ TTSProviders = { VIDEO_LENGTH: int = 40 # secs -def save_text_to_mp3(reddit_obj:dict[str])->tuple[int,int]: +def save_text_to_mp3(reddit_obj: dict[str]) -> tuple[int, int]: """Saves text to MP3 files. Goes through the reddit_obj and generates the title MP3 file and a certain number of comments until the total amount of time exceeds VIDEO_LENGTH seconds. Args: @@ -34,7 +34,7 @@ def save_text_to_mp3(reddit_obj:dict[str])->tuple[int,int]: Returns: tuple[int,int]: (total length of the audio, the number of comments audio was generated for) """ - + env = os.getenv("TTSCHOICE", "") if env.casefold() in map(lambda _: _.casefold(), TTSProviders): text_to_mp3 = TTSEngine( From 87d10206fbca6a4c4c0f7f622ae34decab0bbfdb Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Mon, 27 Jun 2022 16:24:12 +0100 Subject: [PATCH 11/19] Add UTF-8 encoding to all open statements --- setup.py | 4 ++-- utils/checker.py | 8 ++++---- utils/subreddit.py | 4 +++- utils/videos.py | 4 +++- video_creation/final_video.py | 2 +- video_creation/screenshot_downloader.py | 8 ++++++-- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/setup.py b/setup.py index 6063e5a..e3cae6d 100755 --- a/setup.py +++ b/setup.py @@ -142,7 +142,7 @@ theme = handle_input( loader = Loader("Attempting to save your credentials...", "Done!").start() # you can also put a while loop here, e.g. while VideoIsBeingMade == True: ... console.print("Writing to the .env file...") -with open(".env", "w") as f: +with open(".env", "w", encoding="utf-8") as f: f.write( f"""REDDIT_CLIENT_ID="{client_id}" REDDIT_CLIENT_SECRET="{client_sec}" @@ -155,7 +155,7 @@ OPACITY={opacity} """ ) -with open(".setup-done-before", "w") as f: +with open(".setup-done-before", "w", encoding="utf-8") as f: f.write( "This file blocks the setup assistant from running again. Delete this file to run setup again." ) diff --git a/utils/checker.py b/utils/checker.py index 9388029..c56e063 100755 --- a/utils/checker.py +++ b/utils/checker.py @@ -21,10 +21,10 @@ def check_env() -> bool: return True if not os.path.exists(".env"): console.print("[red]Couldn't find the .env file, creating one now.") - with open(".env", "x") as file: + with open(".env", "x", encoding="utf-8") as file: file.write("") success = True - with open(".env.template", "r") as template: + with open(".env.template", "r", encoding="utf-8") as template: # req_envs = [env.split("=")[0] for env in template.readlines() if "=" in env] matching = {} explanations = {} @@ -172,7 +172,7 @@ def check_env() -> bool: console.print("[red]Aborting: Unresolved missing variables") return False if len(incorrect): - with open(".env", "r+") as env_file: + with open(".env", "r+", encoding="utf-8") as env_file: lines = [] for line in env_file.readlines(): line.split("=")[0].strip() not in incorrect and lines.append(line) @@ -180,7 +180,7 @@ def check_env() -> bool: env_file.write("\n".join(lines)) env_file.truncate() console.print("[green]Successfully removed incorrectly set variables from .env") - with open(".env", "a") as env_file: + with open(".env", "a", encoding="utf-8") as env_file: for env in missing: env_file.write( env diff --git a/utils/subreddit.py b/utils/subreddit.py index a40b6c3..94de416 100644 --- a/utils/subreddit.py +++ b/utils/subreddit.py @@ -17,7 +17,9 @@ def get_subreddit_undone(submissions: list, subreddit): """ recursively checks if the top submission in the list was already done. """ - with open("./video_creation/data/videos.json", "r") as done_vids_raw: + with open( + "./video_creation/data/videos.json", "r", encoding="utf-8" + ) as done_vids_raw: done_videos = json.load(done_vids_raw) for submission in submissions: if already_done(done_videos, submission): diff --git a/utils/videos.py b/utils/videos.py index 8d6021f..b41dfa7 100755 --- a/utils/videos.py +++ b/utils/videos.py @@ -18,7 +18,9 @@ def check_done( dict[str]|None: Reddit object in args """ - with open("./video_creation/data/videos.json", "r") as done_vids_raw: + with open( + "./video_creation/data/videos.json", "r", encoding="utf-8" + ) as done_vids_raw: done_videos = json.load(done_vids_raw) for video in done_videos: if video["id"] == str(redditobj): diff --git a/video_creation/final_video.py b/video_creation/final_video.py index c05006c..e0caf10 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -154,7 +154,7 @@ def save_data(filename: str): Args: filename (str): The finished video title name """ - with open("./video_creation/data/videos.json", "r+") as raw_vids: + with open("./video_creation/data/videos.json", "r+", encoding="utf-8") as raw_vids: done_vids = json.load(raw_vids) if str(subreddit.submission.id) in [video["id"] for video in done_vids]: return # video already done but was specified to continue anyway in the .env file diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index f638abc..83dd4c6 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -38,9 +38,13 @@ def download_screenshots_of_reddit_posts(reddit_object: dict[str], screenshot_nu context = browser.new_context() if getenv("THEME").upper() == "DARK": - cookie_file = open("./video_creation/data/cookie-dark-mode.json") + cookie_file = open( + "./video_creation/data/cookie-dark-mode.json", encoding="utf-8" + ) else: - cookie_file = open("./video_creation/data/cookie-light-mode.json") + cookie_file = open( + "./video_creation/data/cookie-light-mode.json", encoding="utf-8" + ) cookies = json.load(cookie_file) context.add_cookies(cookies) # load preference cookies # Get the thread screenshot From 8e05fbf22b650bb7d23f12aa0e0bfbf02f92d03e Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Mon, 27 Jun 2022 16:26:55 +0100 Subject: [PATCH 12/19] Moved to Union over bitwise or --- utils/videos.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/videos.py b/utils/videos.py index b41dfa7..eeb87d5 100755 --- a/utils/videos.py +++ b/utils/videos.py @@ -1,4 +1,5 @@ import json +from typing import Union from os import getenv from utils.console import print_step @@ -6,9 +7,8 @@ from utils.console import print_step def check_done( redditobj: dict[str], -) -> dict[ - str -] | None: # don't set this to be run anyplace that isn't subreddit.py bc of inspect stack +) -> Union[dict[str], None]: + # don't set this to be run anyplace that isn't subreddit.py bc of inspect stack """Checks if the chosen post has already been generated Args: From 82c4353ec95f26c4635047feaf0943056d307df5 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Mon, 27 Jun 2022 16:36:45 +0100 Subject: [PATCH 13/19] Remove unused imports and fix pylint errors 'async_playwright' must stay due to anomalous error --- main.py | 4 ++-- reddit/subreddit.py | 17 ++++++++--------- setup.py | 5 ++--- utils/subreddit.py | 6 ++---- utils/voice.py | 2 +- video_creation/screenshot_downloader.py | 14 ++++++-------- 6 files changed, 21 insertions(+), 27 deletions(-) diff --git a/main.py b/main.py index 1666f17..d87b4fe 100755 --- a/main.py +++ b/main.py @@ -1,18 +1,18 @@ #!/usr/bin/env python from subprocess import Popen -from dotenv import load_dotenv from os import getenv, name +from dotenv import load_dotenv from reddit.subreddit import get_subreddit_threads from utils.cleanup import cleanup from utils.console import print_markdown, print_step +from utils.checker import check_env # from utils.checker import envUpdate from video_creation.background import download_background, chop_background_video from video_creation.final_video import make_final_video from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts from video_creation.voices import save_text_to_mp3 -from utils.checker import check_env VERSION = 2.1 print( diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 98bf8a1..cc36fc3 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -2,11 +2,11 @@ import re from os import getenv, environ import praw +from praw.models import MoreComments from utils.console import print_step, print_substep from utils.subreddit import get_subreddit_undone from utils.videos import check_done -from praw.models import MoreComments TEXT_WHITELIST = set("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890") @@ -26,7 +26,9 @@ def get_subreddit_threads(): """ Returns a list of threads from the AskReddit subreddit. """ - global submission + + submission = None + print_substep("Logging into Reddit.") content = {} @@ -48,9 +50,8 @@ def get_subreddit_threads(): passkey=passkey, check_for_async=False, ) - """ - Ask user for subreddit input - """ + + # Ask user for subreddit input print_step("Getting subreddit threads...") if not getenv( "SUBREDDIT" @@ -89,9 +90,7 @@ def get_subreddit_threads(): print_substep(f"Thread has {upvotes} upvotes", style="bold blue") print_substep(f"Thread has a upvote ratio of {ratio}%", style="bold blue") print_substep(f"Thread has {num_comments} comments", style="bold blue") - environ["VIDEO_TITLE"] = str( - textify(submission.title) - ) # todo use global instend of env vars + environ["VIDEO_TITLE"] = str(textify(submission.title)) environ["VIDEO_ID"] = str(textify(submission.id)) content["thread_url"] = f"https://reddit.com{submission.permalink}" @@ -105,7 +104,7 @@ def get_subreddit_threads(): continue # # see https://github.com/JasonLovesDoggo/RedditVideoMakerBot/issues/78 if not top_level_comment.stickied: if len(top_level_comment.body) <= int(try_env("MAX_COMMENT_LENGTH", 500)): - if not top_level_comment.author == None: + if not top_level_comment.author is None: content["comments"].append( { "comment_body": top_level_comment.body, diff --git a/setup.py b/setup.py index e3cae6d..5aab956 100755 --- a/setup.py +++ b/setup.py @@ -5,11 +5,10 @@ # Imports import os import subprocess -import re -from utils.console import print_markdown -from utils.console import print_step from rich.console import Console from utils.loader import Loader +from utils.console import print_markdown +from utils.console import print_step from utils.console import handle_input console = Console() diff --git a/utils/subreddit.py b/utils/subreddit.py index 94de416..ac684cb 100644 --- a/utils/subreddit.py +++ b/utils/subreddit.py @@ -1,4 +1,3 @@ -from typing import List import json from os import getenv from utils.console import print_substep @@ -14,9 +13,8 @@ def get_subreddit_undone(submissions: list, subreddit): Returns: Any: The submission that has not been done """ - """ - recursively checks if the top submission in the list was already done. - """ + # recursively checks if the top submission in the list was already done. + with open( "./video_creation/data/videos.json", "r", encoding="utf-8" ) as done_vids_raw: diff --git a/utils/voice.py b/utils/voice.py index e78ddad..c4f27bf 100644 --- a/utils/voice.py +++ b/utils/voice.py @@ -2,7 +2,7 @@ import re def sanitize_text(text: str) -> str: - """Sanitizes the text for tts. + r"""Sanitizes the text for tts. What gets removed: - following characters`^_~@!&;#:-%“”‘"%*/{}[]()\|<>?=+` - any http or https links diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 83dd4c6..b4df787 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -1,19 +1,17 @@ import json -from os import getenv import os +from os import getenv from pathlib import Path -from playwright.async_api import async_playwright # do not remove this line -from playwright.sync_api import sync_playwright, ViewportSize -from rich.progress import track +from playwright.async_api import async_playwright # pylint: disable=unused-import -from utils.console import print_step, print_substep -import json -from rich.console import Console +# do not remove the above line +from playwright.sync_api import sync_playwright, ViewportSize +from rich.progress import track import translators as ts -console = Console() +from utils.console import print_step, print_substep storymode = False From 0fa4a3f4dfbd470d8634d0ccb074aff74fa4b38b Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Mon, 27 Jun 2022 16:45:27 +0100 Subject: [PATCH 14/19] Stopped using global variable for submission as well unneeded env vars --- .pylintrc | 2 +- main.py | 2 +- reddit/subreddit.py | 21 ++++--------------- video_creation/final_video.py | 38 ++++++++++++----------------------- 4 files changed, 19 insertions(+), 44 deletions(-) diff --git a/.pylintrc b/.pylintrc index b03c808..9bb7919 100644 --- a/.pylintrc +++ b/.pylintrc @@ -60,7 +60,7 @@ ignored-modules= # Python code to execute, usually for sys.path manipulation such as # pygtk.require(). -#init-hook= +init-hook='import sys; sys.path.append("/")' # Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the # number of processors available to use. diff --git a/main.py b/main.py index d87b4fe..be27079 100755 --- a/main.py +++ b/main.py @@ -42,7 +42,7 @@ def main(): download_screenshots_of_reddit_posts(reddit_object, number_of_comments) download_background() chop_background_video(length) - make_final_video(number_of_comments, length) + make_final_video(number_of_comments, length, reddit_object) def run_many(times): diff --git a/reddit/subreddit.py b/reddit/subreddit.py index cc36fc3..eeae977 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -1,5 +1,5 @@ import re -from os import getenv, environ +from os import getenv import praw from praw.models import MoreComments @@ -8,19 +8,6 @@ from utils.console import print_step, print_substep from utils.subreddit import get_subreddit_undone from utils.videos import check_done -TEXT_WHITELIST = set("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890") - - -def textify(text): - return "".join(filter(TEXT_WHITELIST.__contains__, text)) - - -def try_env(param, backup): - try: - return environ[param] - except KeyError: - return backup - def get_subreddit_threads(): """ @@ -90,20 +77,20 @@ def get_subreddit_threads(): print_substep(f"Thread has {upvotes} upvotes", style="bold blue") print_substep(f"Thread has a upvote ratio of {ratio}%", style="bold blue") print_substep(f"Thread has {num_comments} comments", style="bold blue") - environ["VIDEO_TITLE"] = str(textify(submission.title)) - environ["VIDEO_ID"] = str(textify(submission.id)) content["thread_url"] = f"https://reddit.com{submission.permalink}" content["thread_title"] = submission.title content["thread_post"] = submission.selftext + content["thread_id"] = submission.id content["comments"] = [] + for top_level_comment in submission.comments: if isinstance(top_level_comment, MoreComments): continue if top_level_comment.body in ["[removed]", "[deleted]"]: continue # # see https://github.com/JasonLovesDoggo/RedditVideoMakerBot/issues/78 if not top_level_comment.stickied: - if len(top_level_comment.body) <= int(try_env("MAX_COMMENT_LENGTH", 500)): + if len(top_level_comment.body) <= int(getenv("MAX_COMMENT_LENGTH", "500")): if not top_level_comment.author is None: content["comments"].append( { diff --git a/video_creation/final_video.py b/video_creation/final_video.py index e0caf10..e065d5a 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -1,8 +1,9 @@ #!/usr/bin/env python3 import json -import os import time import multiprocessing +import re +import os from os.path import exists from moviepy.editor import ( @@ -17,7 +18,6 @@ from moviepy.editor import ( from moviepy.video.io import ffmpeg_tools from rich.console import Console -from reddit import subreddit from utils.cleanup import cleanup from utils.console import print_step, print_substep @@ -26,7 +26,7 @@ console = Console() W, H = 1080, 1920 -def make_final_video(number_of_clips: int, length: int): +def make_final_video(number_of_clips: int, length: int, reddit_obj: dict[str]): """Gathers audio clips, gathers all screenshots, stitches them together and saves the final video to assets/temp Args: @@ -116,13 +116,14 @@ def make_final_video(number_of_clips: int, length: int): ) image_concat.audio = audio_composite final = CompositeVideoClip([background_clip, image_concat]) + title = re.sub(r"[^\w\s-]", "", reddit_obj["thread_title"]) + idx = re.sub(r"[^\w\s-]", "", reddit_obj["thread_id"]) + filename = f"{title}.mp4" - filename = f"{get_video_title()}.mp4" - - save_data(filename) + save_data(filename, title, idx) if not exists("./results"): - print_substep("the results folder didn't exist so I made it") + print_substep("The results folder didn't exist so I made it") os.mkdir("./results") final.write_videofile( @@ -144,11 +145,11 @@ def make_final_video(number_of_clips: int, length: int): print_substep("See result in the results folder!") print_step( - f"Reddit title: {os.getenv('VIDEO_TITLE')} \n Background Credit: {os.getenv('background_credit')}" + f'Reddit title: { reddit_obj["thread_title"] } \n Background Credit: {os.getenv("background_credit")}' ) -def save_data(filename: str): +def save_data(filename: str, reddit_title: str, reddit_id: str): """Saves the videos that have already been generated to a JSON file in video_creation/data/videos.json Args: @@ -156,28 +157,15 @@ def save_data(filename: str): """ with open("./video_creation/data/videos.json", "r+", encoding="utf-8") as raw_vids: done_vids = json.load(raw_vids) - if str(subreddit.submission.id) in [video["id"] for video in done_vids]: + if reddit_id in [video["id"] for video in done_vids]: return # video already done but was specified to continue anyway in the .env file payload = { - "id": str(os.getenv("VIDEO_ID")), + "id": reddit_id, "time": str(int(time.time())), "background_credit": str(os.getenv("background_credit")), - "reddit_title": str(os.getenv("VIDEO_TITLE")), + "reddit_title": reddit_title, "filename": filename, } done_vids.append(payload) raw_vids.seek(0) json.dump(done_vids, raw_vids, ensure_ascii=False, indent=4) - - -def get_video_title() -> str: - """Gets video title from env variable or gives it the name "final_video" - - Returns: - str: Video title - """ - title = os.getenv("VIDEO_TITLE") or "final_video" - if len(title) <= 35: - return title - else: - return title[0:30] + "..." From d271159ac9c022ea796b14c26770ad18725d06ca Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Tue, 28 Jun 2022 02:08:11 +0100 Subject: [PATCH 15/19] Move back to 550 character limit for Streamlabs Polly --- TTS/streamlabs_polly.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TTS/streamlabs_polly.py b/TTS/streamlabs_polly.py index 8a24364..500cb16 100644 --- a/TTS/streamlabs_polly.py +++ b/TTS/streamlabs_polly.py @@ -28,7 +28,7 @@ voices = [ class StreamlabsPolly: def __init__(self): self.url = "https://streamlabs.com/polly/speak" - self.max_chars = 349 + self.max_chars = 550 self.voices = voices def run(self, text, filepath, random_voice: bool = False): From c0e8ba8f14c3b99b1e90d2898523725c7e7d6d12 Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 28 Jun 2022 12:43:26 +0200 Subject: [PATCH 16/19] Fixing setup.py creation of .env file with all new parameters #685 #725 --- setup.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/setup.py b/setup.py index 5aab956..7cc284e 100755 --- a/setup.py +++ b/setup.py @@ -60,6 +60,7 @@ console.print("[bold green]Reddit 2FA (yes or no)") console.print("[bold green]Opacity (range of 0-1, decimals are OK)") console.print("[bold green]Subreddit (without r/ or /r/)") console.print("[bold green]Theme (light or dark)") +console.print("[bold green]Random Thread (yes or no)") console.print( "[green]If you don't have these, please follow the instructions in the README.md file to set them up." ) @@ -138,6 +139,13 @@ theme = handle_input( r"(light)|(dark)", "You need to input 'light' or 'dark'", ) +Random_thread = handle_input( + "Random Thread? (yes/no)", + False, + r"(yes)|(no)", + "You need to input either yes or no", +) + loader = Loader("Attempting to save your credentials...", "Done!").start() # you can also put a while loop here, e.g. while VideoIsBeingMade == True: ... console.print("Writing to the .env file...") @@ -148,9 +156,14 @@ REDDIT_CLIENT_SECRET="{client_sec}" REDDIT_USERNAME="{user}" REDDIT_PASSWORD="{passw}" REDDIT_2FA="{twofactor}" +RANDOM_THREAD="no" +RANDOM_THREAD="{Random_thread}" THEME="{theme}" SUBREDDIT="{subreddit}" OPACITY={opacity} +VOICE="Matthew" +TTsChoice="polly" +STORYMODE="False" """ ) From a904c4ab171beff68bb66a7cd821b7b5c7c613cd Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 28 Jun 2022 12:43:26 +0200 Subject: [PATCH 17/19] Fixing setup.py creation of .env file with all new parameters #685 #725 --- setup.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/setup.py b/setup.py index 5aab956..7cc284e 100755 --- a/setup.py +++ b/setup.py @@ -60,6 +60,7 @@ console.print("[bold green]Reddit 2FA (yes or no)") console.print("[bold green]Opacity (range of 0-1, decimals are OK)") console.print("[bold green]Subreddit (without r/ or /r/)") console.print("[bold green]Theme (light or dark)") +console.print("[bold green]Random Thread (yes or no)") console.print( "[green]If you don't have these, please follow the instructions in the README.md file to set them up." ) @@ -138,6 +139,13 @@ theme = handle_input( r"(light)|(dark)", "You need to input 'light' or 'dark'", ) +Random_thread = handle_input( + "Random Thread? (yes/no)", + False, + r"(yes)|(no)", + "You need to input either yes or no", +) + loader = Loader("Attempting to save your credentials...", "Done!").start() # you can also put a while loop here, e.g. while VideoIsBeingMade == True: ... console.print("Writing to the .env file...") @@ -148,9 +156,14 @@ REDDIT_CLIENT_SECRET="{client_sec}" REDDIT_USERNAME="{user}" REDDIT_PASSWORD="{passw}" REDDIT_2FA="{twofactor}" +RANDOM_THREAD="no" +RANDOM_THREAD="{Random_thread}" THEME="{theme}" SUBREDDIT="{subreddit}" OPACITY={opacity} +VOICE="Matthew" +TTsChoice="polly" +STORYMODE="False" """ ) From aa04fd28e841d0e3cf40387cacf84a13bb2c3159 Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 28 Jun 2022 13:45:34 +0200 Subject: [PATCH 18/19] Update setup.py removed static RANDOM_THREAD --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index 7cc284e..63ef952 100755 --- a/setup.py +++ b/setup.py @@ -156,7 +156,6 @@ REDDIT_CLIENT_SECRET="{client_sec}" REDDIT_USERNAME="{user}" REDDIT_PASSWORD="{passw}" REDDIT_2FA="{twofactor}" -RANDOM_THREAD="no" RANDOM_THREAD="{Random_thread}" THEME="{theme}" SUBREDDIT="{subreddit}" From c069d8b5d0e9b93460f29029a6a58fc0e6d322da Mon Sep 17 00:00:00 2001 From: Marcel Date: Wed, 29 Jun 2022 20:12:32 +0200 Subject: [PATCH 19/19] Fixed #736 --- video_creation/final_video.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index e065d5a..fca0e69 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -119,12 +119,13 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict[str]): title = re.sub(r"[^\w\s-]", "", reddit_obj["thread_title"]) idx = re.sub(r"[^\w\s-]", "", reddit_obj["thread_id"]) filename = f"{title}.mp4" + subreddit = os.getenv("SUBREDDIT"); save_data(filename, title, idx) - if not exists("./results"): + if not exists(f"./results/{subreddit}"): print_substep("The results folder didn't exist so I made it") - os.mkdir("./results") + os.mkdir(f"./results/{subreddit}") final.write_videofile( "assets/temp/temp.mp4", @@ -135,7 +136,7 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict[str]): threads=multiprocessing.cpu_count(), ) ffmpeg_tools.ffmpeg_extract_subclip( - "assets/temp/temp.mp4", 0, length, targetname=f"results/{filename}" + "assets/temp/temp.mp4", 0, length, targetname=f"results/{subreddit}/{filename}" ) # os.remove("assets/temp/temp.mp4")