diff --git a/reddit/askreddit.py b/reddit/askreddit.py index 7c7110a..ad9cfa0 100644 --- a/reddit/askreddit.py +++ b/reddit/askreddit.py @@ -24,7 +24,6 @@ def get_askreddit_threads(): askreddit = reddit.subreddit("askreddit") threads = askreddit.hot(limit=25) submission = list(threads)[random.randrange(0, 25)] - print_substep(f"Video will be: {submission.title} :thumbsup:") try: content["thread_url"] = submission.url diff --git a/reddit/subreddit.py b/reddit/subreddit.py index d78bbb3..ba9e97c 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -43,7 +43,6 @@ def get_subreddit_threads(): threads = subreddit.hot(limit=25) submission = list(threads)[random.randrange(0, 25)] os.environ["VIDEO_TITLE"] = str(ascifi(submission.title)) - print_substep(f"Video will be: {os.getenv('VIDEO_TITLE')} :thumbsup:") try: content["thread_url"] = submission.url diff --git a/utils/cleanup.py b/utils/cleanup.py index 1703e69..bdad1f3 100644 --- a/utils/cleanup.py +++ b/utils/cleanup.py @@ -1,8 +1,18 @@ import os -def cleanup(): +def cleanup() -> int: + count = 0 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) + for file in os.listdir('./assets/temp/mp4'): + count += 1 + os.remove('./assets/temp/mp4/' + file) + for file in os.listdir('./assets/temp/mp3'): + count += 1 + os.remove('./assets/temp/mp3/' + file) + return count + diff --git a/video_creation/background.py b/video_creation/background.py index c478124..600d31a 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -21,17 +21,17 @@ def download_background(): Shoutout to: bbswitzer (https://www.youtube.com/watch?v=n_Dv4JMiwK8) Shoutout to: Orbital Gameplay (https://www.youtube.com/watch?v=2X9QGY__0II) """ - Path("assets/backgronds/").mkdir(parents=True, exist_ok=True) + Path("./assets/backgrounds/").mkdir(parents=True, exist_ok=True) background_options = [ # uri , filename , credit ("https://www.youtube.com/watch?v=n_Dv4JMiwK8", "parkour.mp4", 'bbswitzer'), # note: make sure the file name doesn't include a - in it ("https://www.youtube.com/watch?v=2X9QGY__0II", "rocket_league.mp4", 'Orbital Gameplay'), ] - if listdir('assets/backgrounds/') != len(background_options): + if listdir('./assets/backgrounds') != len(background_options): print_step("We need to download the backgrounds videos. they are fairly large but it's only done once. 😎") print_substep("Downloading the backgrounds video... please be patient 🙏 ") for uri, filename, credit in track(background_options, description="Downloading..."): - print_step(f"Downloading {filename} from {uri}") + print_substep(f"Downloading {filename} from {uri}") YouTube(uri).streams.filter(res="720p").first().download("assets/backgrounds", filename=f"{credit}-{filename}") print_substep("Background videos downloaded successfully! 🎉", style="bold green") diff --git a/video_creation/final_video.py b/video_creation/final_video.py index c056218..877d66a 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -2,7 +2,9 @@ import os from moviepy.editor import (VideoFileClip, AudioFileClip, ImageClip, concatenate_videoclips, concatenate_audioclips, CompositeAudioClip, CompositeVideoClip) -from utils.console import print_step + +from utils.cleanup import cleanup +from utils.console import print_step, print_substep W, H = 1080, 1920 @@ -44,6 +46,8 @@ def make_final_video(number_of_clips): final.write_videofile(f"assets/{get_video_title()}.mp4", fps=30, audio_codec="aac", audio_bitrate="192k") - + print_step("Removing temporary files 🗑") + cleanups = cleanup() + print_substep(f"Removed {cleanups} temporary files 🗑") print_step(f"Reddit title: {os.getenv('VIDEO_TITLE')} | Background Credit {os.getenv('background_credit')}")