From eeeaff0a0497cbd1ec3ab4461667741ffb1fb791 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Tue, 7 Jun 2022 01:50:30 +0200 Subject: [PATCH 01/10] gives user thread stats --- reddit/subreddit.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index c560293..d4c2cc9 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -57,7 +57,14 @@ def get_subreddit_threads(): threads = subreddit.hot(limit=25) submission = list(threads)[random.randrange(0, 25)] - print_substep(f"Video will be: {submission.title} :thumbsup:") + upvotes=submission.score + ratio=submission.upvote_ratio * 100 + num_comments=submission.num_comments + + console.log(f"[bold green] Video will be: {submission.title} :thumbsup:") + console.log(f"[bold blue] Thread has " + str(upvotes) + " upvotes") + console.log(f"[bold blue] Thread has a upvote ratio of " + str(ratio) + "%") + console.log(f"[bold blue] Thread has " + str(num_comments) + " comments") console.log("Getting video comments...") try: content["thread_url"] = submission.url From 232b4442510e6a88e4591c41e06ea6b8a1bf2d17 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Tue, 7 Jun 2022 01:52:02 +0200 Subject: [PATCH 02/10] Update final_video.py --- video_creation/final_video.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 93bac6f..8e1c5de 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -12,6 +12,9 @@ import re from utils.console import print_step from dotenv import load_dotenv import os +from rich.console import Console +console = Console() + W, H = 1080, 1920 @@ -47,6 +50,11 @@ def make_final_video(number_of_clips): audio_concat = concatenate_audioclips(audio_clips) audio_composite = CompositeAudioClip([audio_concat]) + #Get sum of all clip lengths + total_length = sum([clip.duration for clip in audio_clips]) + #Output Length + console.log("[bold green] Video Will Be: " + str(total_length) + " Seconds Long") + # Gather all images image_clips = [] for i in range(0, number_of_clips): From bafe8c3616d003076943d69db99d9ef7ff3b3f6e Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Tue, 7 Jun 2022 01:52:21 +0200 Subject: [PATCH 03/10] Update screenshot_downloader.py --- video_creation/screenshot_downloader.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index d3d32ef..1e1ae21 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -3,6 +3,8 @@ from pathlib import Path from rich.progress import track from utils.console import print_step, print_substep import json +from rich.console import Console +console = Console() def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): @@ -43,9 +45,12 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): ) for idx, comment in track( - enumerate(reddit_object["comments"]), "Downloading screenshots..." + enumerate(reddit_object["comments"]) ): + #allow user to see what comment is being saved + print_substep(f"Downloading screenshot {idx + 1}") + # Stop if we have reached the screenshot_num if idx >= screenshot_num: break @@ -57,6 +62,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): page.locator(f"#t1_{comment['comment_id']}").screenshot( path=f"assets/png/comment_{idx}.png" ) - - print_substep("Screenshots downloaded Successfully.", - style="bold green") + + #let user know that the screenshots are done + console.log(f"[bold green]Saved {idx + 1} screenshots.") + From 9b25603bba6b5d4b3b426655b2f583bd8fc1d705 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Tue, 7 Jun 2022 01:52:44 +0200 Subject: [PATCH 04/10] Update voices.py --- video_creation/voices.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/video_creation/voices.py b/video_creation/voices.py index c0df8b7..9ac6aac 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -3,7 +3,8 @@ from pathlib import Path from mutagen.mp3 import MP3 from utils.console import print_step, print_substep from rich.progress import track - +from rich.console import Console +console = Console() def save_text_to_mp3(reddit_obj): """Saves Text to MP3 files. @@ -31,7 +32,11 @@ def save_text_to_mp3(reddit_obj): tts.save(f"assets/mp3/posttext.mp3") length += MP3(f"assets/mp3/posttext.mp3").info.length - for idx, comment in track(enumerate(reddit_obj["comments"]), "Saving..."): + for idx, comment in track(enumerate(reddit_obj["comments"])): + + #allow user to see what comment is being saved + print_substep(f"Saving MP3 {idx + 1} ") + # ! Stop creating mp3 files if the length is greater than 50 seconds. This can be longer, but this is just a good starting point if length > 50: break @@ -39,6 +44,7 @@ def save_text_to_mp3(reddit_obj): tts.save(f"assets/mp3/{idx}.mp3") length += MP3(f"assets/mp3/{idx}.mp3").info.length - print_substep("Saved Text to MP3 files successfully.", style="bold green") + #let user know that the MP3 files are saved + console.log(f"[bold green]Saved {idx + 1} MP3 Files.") # ! Return the index so we know how many screenshots of comments we need to make. return length, idx From c24234aa5362f129382e38adbd1a50f591ef1d56 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Tue, 7 Jun 2022 01:53:19 +0200 Subject: [PATCH 05/10] Update main.py --- main.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 9aabe78..5d701d3 100644 --- a/main.py +++ b/main.py @@ -25,6 +25,27 @@ REQUIRED_VALUES = [ "OPACITY", ] +#create an giant banner +banner = ''' + +██████╗░███████╗██████╗░██████╗░██╗████████╗  ██╗░░░██╗██╗██████╗░███████╗░█████╗░ +██╔══██╗██╔════╝██╔══██╗██╔══██╗██║╚══██╔══╝  ██║░░░██║██║██╔══██╗██╔════╝██╔══██╗ +██████╔╝█████╗░░██║░░██║██║░░██║██║░░░██║░░░  ╚██╗░██╔╝██║██║░░██║█████╗░░██║░░██║ +██╔══██╗██╔══╝░░██║░░██║██║░░██║██║░░░██║░░░  ░╚████╔╝░██║██║░░██║██╔══╝░░██║░░██║ +██║░░██║███████╗██████╔╝██████╔╝██║░░░██║░░░  ░░╚██╔╝░░██║██████╔╝███████╗╚█████╔╝ +╚═╝░░╚═╝╚══════╝╚═════╝░╚═════╝░╚═╝░░░╚═╝░░░  ░░░╚═╝░░░╚═╝╚═════╝░╚══════╝░╚════╝░ + +███╗░░░███╗░█████╗░██╗░░██╗███████╗██████╗░ +████╗░████║██╔══██╗██║░██╔╝██╔════╝██╔══██╗ +██╔████╔██║███████║█████═╝░█████╗░░██████╔╝ +██║╚██╔╝██║██╔══██║██╔═██╗░██╔══╝░░██╔══██╗ +██║░╚═╝░██║██║░░██║██║░╚██╗███████╗██║░░██║ +╚═╝░░░░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚══════╝╚═╝░░╚═╝ + +''' +print(banner) + +time.sleep(.5) print_markdown( "### Thanks for using this tool! [Feel free to contribute to this project on GitHub!](https://lewismenelaws.com) If you have any questions, feel free to reach out to me on Twitter or submit a GitHub issue." @@ -46,7 +67,7 @@ reddit2fa = os.getenv("REDDIT_2FA") load_dotenv() console.log("[bold green]Checking environment variables...") -time.sleep(1) +time.sleep(.5) if not os.path.exists(".env"): From 5fb9b1a6c35fb835b0815c6971bfdc4ba5dba1a7 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Tue, 7 Jun 2022 02:14:21 +0200 Subject: [PATCH 06/10] Added Disclaimer "Banner may look bad or wrong in IDE/Text Editor, but looks perfect in CMD, BASH or ZSH" The banner may look bad or wrong in IDE/Text Editor but looks perfect in CMD, BASH, or ZSH. Don't worry looks great when in actual use! --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index e10aa67..8ae743d 100644 --- a/main.py +++ b/main.py @@ -22,7 +22,7 @@ REQUIRED_VALUES = [ "OPACITY", ] -#create an giant banner +#Banner may look bad or wrong in IDE/Text Editor, but looks perfect in CMD, BASH or ZSH banner = ''' ██████╗░███████╗██████╗░██████╗░██╗████████╗  ██╗░░░██╗██╗██████╗░███████╗░█████╗░ @@ -42,6 +42,8 @@ banner = ''' ''' print(banner) +#Banner may look bad or wrong in IDE/Text Editor, but looks perfect in CMD, BASH or ZSH + time.sleep(.5) print_markdown( From abbb496012e52e2396ed1d5b45d2b3a685535215 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Wed, 8 Jun 2022 17:16:35 +0200 Subject: [PATCH 07/10] round video length turns 'total_length' into an int, instead of float. --- video_creation/final_video.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 9b96f3c..b3a0df6 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 from moviepy.editor import ( VideoFileClip, AudioFileClip, @@ -8,7 +7,7 @@ from moviepy.editor import ( CompositeAudioClip, CompositeVideoClip, ) -import reddit.subreddit +import reddit.subreddit import re from utils.console import print_step from dotenv import load_dotenv @@ -20,12 +19,13 @@ console = Console() W, H = 1080, 1920 -def make_final_video(number_of_clips): +def make_final_video(number_of_clips): + # Calls opacity from the .env load_dotenv() - opacity = os.getenv("OPACITY") - + opacity = os.getenv('OPACITY') + print_step("Creating the final video...") VideoFileClip.reW = lambda clip: clip.resize(width=W) @@ -42,9 +42,9 @@ def make_final_video(number_of_clips): audio_clips = [] for i in range(0, number_of_clips): audio_clips.append(AudioFileClip(f"assets/mp3/{i}.mp3")) - audio_clips.insert(0, AudioFileClip("assets/mp3/title.mp3")) + audio_clips.insert(0, AudioFileClip(f"assets/mp3/title.mp3")) try: - audio_clips.insert(1, AudioFileClip("assets/mp3/posttext.mp3")) + audio_clips.insert(1, AudioFileClip(f"assets/mp3/posttext.mp3")) except: OSError() audio_concat = concatenate_audioclips(audio_clips) @@ -52,8 +52,10 @@ def make_final_video(number_of_clips): #Get sum of all clip lengths total_length = sum([clip.duration for clip in audio_clips]) + #round total_length to an integer + int_total_length=round(total_length) #Output Length - console.log("[bold green] Video Will Be: " + str(total_length) + " Seconds Long") + console.log(f"[bold green] Video Will Be: {int_total_length} Seconds Long") # Gather all images image_clips = [] @@ -65,32 +67,30 @@ def make_final_video(number_of_clips): .resize(width=W - 100) .set_opacity(float(opacity)), ) - if os.path.exists("assets/mp3/posttext.mp3"): + if os.path.exists(f"assets/mp3/posttext.mp3"): image_clips.insert( 0, - ImageClip("assets/png/title.png") + ImageClip(f"assets/png/title.png") .set_duration(audio_clips[0].duration + audio_clips[1].duration) .set_position("center") .resize(width=W - 100) .set_opacity(float(opacity)), - ) + ) else: image_clips.insert( 0, - ImageClip("assets/png/title.png") + ImageClip(f"assets/png/title.png") .set_duration(audio_clips[0].duration) .set_position("center") .resize(width=W - 100) .set_opacity(float(opacity)), - ) + ) image_concat = concatenate_videoclips(image_clips).set_position( ("center", "center") ) image_concat.audio = audio_composite final = CompositeVideoClip([background_clip, image_concat]) - filename = re.sub( - '[?"%*:|<>]', "", ("assets/" + reddit.subreddit.submission.title + ".mp4") - ) + 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 From 31a4e825f1e45988f4f33e5927fbe6198130cab5 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Wed, 8 Jun 2022 17:22:19 +0200 Subject: [PATCH 08/10] fixed merge issues --- video_creation/final_video.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 58706d4..b3a0df6 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, print_substep +from utils.console import print_step from dotenv import load_dotenv import os from rich.console import Console @@ -92,15 +92,5 @@ 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 From 2004f7c0a5129524e4f4c0a585c23e5e1c7bd4e4 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Wed, 8 Jun 2022 17:25:31 +0200 Subject: [PATCH 09/10] fixed merge errors --- video_creation/final_video.py | 46 ++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index b3a0df6..a1ad0e1 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from moviepy.editor import ( VideoFileClip, AudioFileClip, @@ -7,25 +8,21 @@ from moviepy.editor import ( CompositeAudioClip, CompositeVideoClip, ) -import reddit.subreddit +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 -console = Console() - W, H = 1080, 1920 - def make_final_video(number_of_clips): - + # Calls opacity from the .env load_dotenv() - opacity = os.getenv('OPACITY') - + opacity = os.getenv("OPACITY") + print_step("Creating the final video...") VideoFileClip.reW = lambda clip: clip.resize(width=W) @@ -42,20 +39,21 @@ def make_final_video(number_of_clips): audio_clips = [] for i in range(0, number_of_clips): audio_clips.append(AudioFileClip(f"assets/mp3/{i}.mp3")) - audio_clips.insert(0, AudioFileClip(f"assets/mp3/title.mp3")) + audio_clips.insert(0, AudioFileClip("assets/mp3/title.mp3")) try: - audio_clips.insert(1, AudioFileClip(f"assets/mp3/posttext.mp3")) + audio_clips.insert(1, AudioFileClip("assets/mp3/posttext.mp3")) except: OSError() audio_concat = concatenate_audioclips(audio_clips) audio_composite = CompositeAudioClip([audio_concat]) - - #Get sum of all clip lengths + + #Get sum of all clip lengths total_length = sum([clip.duration for clip in audio_clips]) #round total_length to an integer int_total_length=round(total_length) #Output Length console.log(f"[bold green] Video Will Be: {int_total_length} Seconds Long") + # Gather all images image_clips = [] @@ -67,30 +65,38 @@ def make_final_video(number_of_clips): .resize(width=W - 100) .set_opacity(float(opacity)), ) - if os.path.exists(f"assets/mp3/posttext.mp3"): + if os.path.exists("assets/mp3/posttext.mp3"): image_clips.insert( 0, - ImageClip(f"assets/png/title.png") + ImageClip("assets/png/title.png") .set_duration(audio_clips[0].duration + audio_clips[1].duration) .set_position("center") .resize(width=W - 100) .set_opacity(float(opacity)), - ) + ) else: image_clips.insert( 0, - ImageClip(f"assets/png/title.png") + ImageClip("assets/png/title.png") .set_duration(audio_clips[0].duration) .set_position("center") .resize(width=W - 100) .set_opacity(float(opacity)), - ) + ) image_concat = concatenate_videoclips(image_clips).set_position( ("center", "center") ) image_concat.audio = audio_composite 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 From 6af6b4136b4bf2552bf580092ac4bbf12dca38a9 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Wed, 8 Jun 2022 22:51:40 +0200 Subject: [PATCH 10/10] fixed merge errors --- reddit/subreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 3f3b24f..249f902 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -65,7 +65,7 @@ def get_subreddit_threads(): threads = subreddit.hot(limit=25) submission = list(threads)[random.randrange(0, 25)] - upvotes=submission.score + upvotes=submission.score ratio=submission.upvote_ratio * 100 num_comments=submission.num_comments