diff --git a/.env.template b/.env.template index e95c209..5830840 100644 --- a/.env.template +++ b/.env.template @@ -16,5 +16,14 @@ THEME="" # Enter a subreddit, e.g. "AskReddit" SUBREDDIT="" +# Filters the comments by range of lenght (min and max characters) +# Min has to be less or equal to max +# DO NOT INSERT ANY SPACES BETWEEN THE COMMA AND THE VALUES +COMMENT_LENGTH_RANGE = "min,max" + # Range is 0 -> 1 OPACITY="0.9" + +# The absolute path of the folder where you want to save the final video +# If empty or wrong, the path will be 'assets/' +FINAL_VIDEO_PATH="" \ No newline at end of file diff --git a/README.md b/README.md index 0e5a5df..0fbcf3a 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,11 @@ All done WITHOUT video editing or asset compiling. Just pure ✨programming magi Created by Lewis Menelaws & [TMRRW](https://tmrrwinc.ca) -[ - +[ -](https://tmrrwinc.ca) +](https://tmrrwinc.ca) ## Motivation 🤔 diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 6372efc..741d116 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -1,6 +1,6 @@ -#!/usr/bin/env python3 +from numpy import Infinity from rich.console import Console -from utils.console import print_step, print_substep +from utils.console import print_step, print_substep, print_markdown from dotenv import load_dotenv import os import random @@ -81,14 +81,18 @@ def get_subreddit_threads(): content["comments"] = [] 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, - } - ) + COMMENT_LENGTH_RANGE = [0, Infinity] + if os.getenv("COMMENT_LENGTH_RANGE"): + COMMENT_LENGTH_RANGE = [int(i) for i in os.getenv("COMMENT_LENGTH_RANGE").split(",")] + if COMMENT_LENGTH_RANGE[0] <= len(top_level_comment.body) <= COMMENT_LENGTH_RANGE[1]: + 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, + } + ) except AttributeError: pass diff --git a/video_creation/final_video.py b/video_creation/final_video.py index b3a0df6..58706d4 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -9,7 +9,7 @@ from moviepy.editor import ( ) import reddit.subreddit import re -from utils.console import print_step +from utils.console import print_step, print_substep from dotenv import load_dotenv import os from rich.console import Console @@ -92,5 +92,15 @@ def make_final_video(number_of_clips): final = CompositeVideoClip([background_clip, image_concat]) filename = (re.sub('[?\"%*:|<>]', '', ("assets/" + reddit.subreddit.submission.title + ".mp4"))) final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k") + final_video_path = "assets/" + if os.getenv("FINAL_VIDEO_PATH"): + final_video_path = os.getenv("FINAL_VIDEO_PATH") + filename = (re.sub('[?\"%*:|<>]', '', (final_video_path + reddit.subreddit.submission.title + ".mp4"))) + try: + final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k") + except: + print_substep("Something's wrong with the path you inserted, the video will be saved in the default path (assets/)", style="bold red") + 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 diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index c24f0a3..b763d20 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -40,6 +40,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): print_substep("Post is NSFW. You are spicy...") page.locator('[data-testid="content-gate"] button').click() + page.locator('[data-click-id="text"] button').click() # Remove "Click to see nsfw" Button in Screenshot page.locator('[data-test-id="post-content"]').screenshot( path="assets/png/title.png"