From 9f6a5e6a1f6d081a098da10c4930a583b53a8786 Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 31 May 2022 19:31:10 -0400 Subject: [PATCH] everything does indeed work! --- main.py | 9 ++++++++- utils/cleanup.py | 10 ++++++---- video_creation/background.py | 20 +++++++++++++------- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 0c03b56..72a2d6a 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +from utils.cleanup import cleanup from utils.console import print_markdown import time from reddit.subreddit import get_subreddit_threads @@ -12,6 +13,7 @@ print_markdown( time.sleep(2) + def main(): reddit_object = get_subreddit_threads() @@ -23,4 +25,9 @@ def main(): if __name__ == '__main__': - main() + try: + main() + except KeyboardInterrupt: + print_markdown("## Clearing temp files") + cleanup() + exit() diff --git a/utils/cleanup.py b/utils/cleanup.py index bdad1f3..c2f104f 100644 --- a/utils/cleanup.py +++ b/utils/cleanup.py @@ -7,10 +7,12 @@ def cleanup() -> int: 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) + try: + for file in os.listdir('./assets/temp/mp4'): + count += 1 + os.remove('./assets/temp/mp4/' + file) + except FileNotFoundError: + pass for file in os.listdir('./assets/temp/mp3'): count += 1 os.remove('./assets/temp/mp3/' + file) diff --git a/video_creation/background.py b/video_creation/background.py index 600d31a..e866c85 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -5,7 +5,7 @@ from random import randrange from pytube import YouTube from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip from moviepy.editor import VideoFileClip -from rich.progress import track +from rich.progress import track, Progress from utils.console import print_step, print_substep @@ -26,14 +26,20 @@ def download_background(): ("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'), ] + print(listdir('./assets/backgrounds'), 'podsods', 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 🙏 ") + print_step("We need to download the backgnrounds videos. they are fairly large but it's only done once. 😎") + print_substep("Downloading the backgrounds videos... please be patient 🙏 ") + with Progress() as progress: + + download_task = progress.add_task("[green]Downloading...", total=2) + + for uri, filename, credit in background_options: + print_substep(f"Downloading {filename} from {uri}") + YouTube(uri).streams.filter(res="720p").first().download("assets/backgrounds", + filename=f"{credit}-{filename}") + progress.update(download_task, advance=1) - for uri, filename, credit in track(background_options, description="Downloading..."): - 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")