diff --git a/main.py b/main.py old mode 100644 new mode 100755 index fd7a139..10be90b --- a/main.py +++ b/main.py @@ -20,10 +20,8 @@ def main(): def get_obj(): reddit_obj = get_subreddit_threads() for comment in (reddit_obj["comments"]): - if len(comment) > 250: - print(comment) + if len(comment["comment_body"]) > 250: reddit_obj["comments"].remove(comment) - print(reddit_obj["comments"]) return reddit_obj reddit_object = get_obj() @@ -31,7 +29,7 @@ def main(): download_screenshots_of_reddit_posts(reddit_object, number_of_comments) download_background() chop_background_video(length) - final_video = make_final_video(number_of_comments) + final_video = make_final_video(number_of_comments, length) if __name__ == '__main__': diff --git a/reddit/subreddit.py b/reddit/subreddit.py old mode 100644 new mode 100755 index 9a19c55..ff19334 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -43,6 +43,8 @@ def get_subreddit_threads(): threads = subreddit.hot(limit=25) submission = list(threads)[random.randrange(0, 25)] submission = check_done(submission) + if submission == None: + return get_subreddit_threads() print_substep( f'subreddit thread is: {submission.title}\n(if you dont like this, you can change it by exiting and rerunning the program)') diff --git a/utils/videos.py b/utils/videos.py old mode 100644 new mode 100755 index 66b9a75..3af5015 --- a/utils/videos.py +++ b/utils/videos.py @@ -17,6 +17,5 @@ def check_done(redditobj): # don't set this to be run anyplace that isn't subre for video in done_videos: if video['id'] == str(redditobj): print_step('Getting new post as the current one has already been done') - from reddit.subreddit import get_subreddit_threads - return get_subreddit_threads() # recursive func + return None return redditobj diff --git a/video_creation/background.py b/video_creation/background.py old mode 100644 new mode 100755 index f146ade..10f142d --- a/video_creation/background.py +++ b/video_creation/background.py @@ -36,7 +36,7 @@ def download_background(): for uri, filename, credit in background_options: print_substep(f"Downloading {filename} from {uri}") - YouTube(uri).streams.filter(res="720p").first().download("assets/backgrounds", + YouTube(uri).streams.filter(res="1080p").first().download("assets/backgrounds", filename=f"{credit}-{filename}") progress.update(download_task, advance=1) diff --git a/video_creation/data/videos.json b/video_creation/data/videos.json index fe51488..d89118e 100644 --- a/video_creation/data/videos.json +++ b/video_creation/data/videos.json @@ -1 +1,9 @@ -[] +[ + { + "id": "v581n3", + "time": "1654440078", + "background_credit": "Orbital Gameplay", + "reddit_title": "Who is the most evil person alive today", + "filename": "Who is the most evil person al....mp4" + } +] \ No newline at end of file diff --git a/video_creation/final_video.py b/video_creation/final_video.py old mode 100644 new mode 100755 index d5fd528..157b94b --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -3,8 +3,8 @@ import os import time from os.path import exists -from moviepy.editor import (VideoFileClip, AudioFileClip, ImageClip, concatenate_videoclips, concatenate_audioclips, - CompositeAudioClip, CompositeVideoClip) +from moviepy.editor import VideoFileClip, AudioFileClip, ImageClip, concatenate_videoclips, concatenate_audioclips, CompositeAudioClip, CompositeVideoClip +from moviepy.video import io from utils.cleanup import cleanup from utils.console import print_step, print_substep @@ -12,7 +12,7 @@ from utils.console import print_step, print_substep W, H = 1080, 1920 -def make_final_video(number_of_clips): +def make_final_video(number_of_clips, length): print_step("Creating the final video 🎥") VideoFileClip.reW = lambda clip: clip.resize(width=W) VideoFileClip.reH = lambda clip: clip.resize(width=H) @@ -65,7 +65,11 @@ def make_final_video(number_of_clips): if not exists('./results'): print_substep('the results folder didn\'t exist so I made it') os.mkdir("./results") - final.write_videofile(f"results/{filename}", fps=30, audio_codec="aac", audio_bitrate="192k") + + final.write_videofile("temp.mp4", fps=30, audio_codec="aac", audio_bitrate="192k") + io.ffmpeg_tools.ffmpeg_extract_subclip("temp.mp4", 0, length, targetname=f"results/{filename}") + os.remove("temp.mp4") + print_step("Removing temporary files 🗑") cleanups = cleanup() print_substep(f"Removed {cleanups} temporary files 🗑")