From e86481e15043db93734a0c276888454cf2815008 Mon Sep 17 00:00:00 2001 From: iaacornus Date: Sun, 5 Jun 2022 12:51:01 +0800 Subject: [PATCH 1/2] include strip() method to avoid errors due to trailing spaces --- reddit/subreddit.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index be85874..9d0c93d 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -34,11 +34,11 @@ def get_subreddit_threads(subreddit_): content = {} reddit = praw.Reddit( - client_id=os.getenv("REDDIT_CLIENT_ID"), - client_secret=os.getenv("REDDIT_CLIENT_SECRET"), + client_id=os.getenv("REDDIT_CLIENT_ID").strip(), + client_secret=os.getenv("REDDIT_CLIENT_SECRET").strip(), user_agent="Accessing AskReddit threads", - username=os.getenv("REDDIT_USERNAME"), - password=passkey, + username=os.getenv("REDDIT_USERNAME").strip(), + password=passkey.strip(), ) try: @@ -48,7 +48,7 @@ def get_subreddit_threads(subreddit_): subreddit = reddit.subreddit(subreddit_) except ValueError: if os.getenv("SUBREDDIT"): - subreddit = reddit.subreddit(re.sub(r"r\/", "", os.getenv("SUBREDDIT"))) + subreddit = reddit.subreddit(re.sub(r"r\/", "", os.getenv("SUBREDDIT").strip())) else: subreddit = reddit.subreddit("askreddit") print_substep("Subreddit not defined. Using AskReddit.") From 2ad99f41eff424b73680bbff41e50bc1ed8c29bd Mon Sep 17 00:00:00 2001 From: iaacornus Date: Sun, 5 Jun 2022 13:03:07 +0800 Subject: [PATCH 2/2] features for custom filename as listed in #225 --- cli.py | 12 +++++++++++- main.py | 9 ++++++--- video_creation/final_video.py | 10 ++++++---- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/cli.py b/cli.py index e0dfcb4..79ad3ec 100644 --- a/cli.py +++ b/cli.py @@ -34,12 +34,22 @@ def program_options(): help="Use another video background for video (accepts link).", action="store" ) + parser.add_argument( + "-f", + "--filename", + help="Set a filename for the video.", + action="store" + ) args = parser.parse_args() try: if args.create: - main(args.subreddit, args.background) + main( + args.subreddit, + args.background, + args.filename + ) else: print_substep("Error occured!", style="bold red") raise SystemExit() diff --git a/main.py b/main.py index 36e1c1c..c780dde 100644 --- a/main.py +++ b/main.py @@ -12,7 +12,7 @@ from video_creation.final_video import make_final_video from utils.console import print_markdown, print_substep -def main(subreddit_=None, background=None): +def main(subreddit_=None, background=None, filename=None): REQUIRED_VALUES = [ "REDDIT_CLIENT_ID", "REDDIT_CLIENT_SECRET", @@ -42,7 +42,10 @@ def main(subreddit_=None, background=None): if configured: reddit_object = get_subreddit_threads(subreddit_) length, number_of_comments = save_text_to_mp3(reddit_object) - download_screenshots_of_reddit_posts(reddit_object, number_of_comments, os.getenv("THEME")) + download_screenshots_of_reddit_posts( + reddit_object, number_of_comments, + os.getenv("THEME") + ) download_background(background) chop_background_video(length) - final_video = make_final_video(number_of_comments) + final_video = make_final_video(snumber_of_comments, filename) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index bdf36ad..599026c 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -19,7 +19,7 @@ from utils.console import print_step W, H = 1080, 1920 -def make_final_video(number_of_clips): +def make_final_video(number_of_clips, file_name): # Calls opacity from the .env load_dotenv() opacity = os.getenv('OPACITY') @@ -80,9 +80,11 @@ def make_final_video(number_of_clips): image_concat.audio = audio_composite final = CompositeVideoClip([background_clip, image_concat]) - filename = ( - re.sub('[?\"%*:|<>]', '', ("assets/" + reddit.subreddit.submission.title + ".mp4")) - ) + if file_name is None: + filename = ( + re.sub('[?\"%*:|<>]', '', ("assets/" + reddit.subreddit.submission.title + ".mp4")) + ) + final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k") for i in range(0, number_of_clips): pass