diff --git a/video_creation/final_video.py b/video_creation/final_video.py index c258cf9..29b6eb1 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -105,19 +105,19 @@ def make_final_video( audio_clips.insert(1, AudioFileClip(f"assets/temp/{id}/mp3/postaudio.mp3")) elif settings.config["settings"]["storymodemethod"] == 1: audio_clips = [ - AudioFileClip(f"assets/temp/{id}/mp3/postaudio-{i}.mp3") + AudioFileClip(f"assets/temp/{reddit_id}/mp3/postaudio-{i}.mp3") for i in track( range(number_of_clips + 1), "Collecting the audio files..." ) ] - audio_clips.insert(0, AudioFileClip(f"assets/temp/{id}/mp3/title.mp3")) + audio_clips.insert(0, AudioFileClip(f"assets/temp/{reddit_id}/mp3/title.mp3")) else: audio_clips = [ - AudioFileClip(f"assets/temp/{id}/mp3/{i}.mp3") + AudioFileClip(f"assets/temp/{reddit_id}/mp3/{i}.mp3") for i in range(number_of_clips) ] - audio_clips.insert(0, AudioFileClip(f"assets/temp/{id}/mp3/title.mp3")) + audio_clips.insert(0, AudioFileClip(f"assets/temp/{reddit_id}/mp3/title.mp3")) audio_concat = concatenate_audioclips(audio_clips) audio_composite = CompositeAudioClip([audio_concat]) @@ -129,12 +129,12 @@ def make_final_video( new_transition = ( 0 if transition is None or float(transition) > 2 else float(transition) ) - screenshow_width = int((W * 90) // 100) + screenshot_width = int((W * 90) // 100) image_clips.insert( 0, ImageClip(f"assets/temp/{reddit_id}/png/title.png") .set_duration(audio_clips[0].duration) - .resize(width=screenshow_width) + .resize(width=screenshot_width) .set_opacity(new_opacity) .crossfadein(new_transition) .crossfadeout(new_transition), @@ -143,10 +143,10 @@ def make_final_video( if settings.config["settings"]["storymodemethod"] == 0: image_clips.insert( 1, - ImageClip(f"assets/temp/{id}/png/story_content.png") + ImageClip(f"assets/temp/{reddit_id}/png/story_content.png") .set_duration(audio_clips[1].duration) .set_position("center") - .resize(width=W - 100) + .resize(width=screenshot_width) .set_opacity(float(opacity)), ) elif settings.config["settings"]["storymodemethod"] == 1: @@ -154,9 +154,9 @@ def make_final_video( range(0, number_of_clips + 1), "Collecting the image files..." ): image_clips.append( - ImageClip(f"assets/temp/{id}/png/img{i}.png") + ImageClip(f"assets/temp/{reddit_id}/png/img{i}.png") .set_duration(audio_clips[i + 1].duration) - .resize(width=W - 100) + .resize(width=screenshot_width) .set_opacity(new_opacity) # .crossfadein(new_transition) # .crossfadeout(new_transition) @@ -164,9 +164,9 @@ def make_final_video( else: for i in range(0, number_of_clips): image_clips.append( - ImageClip(f"assets/temp/{id}/png/comment_{i}.png") + ImageClip(f"assets/temp/{reddit_id}/png/comment_{i}.png") .set_duration(audio_clips[i + 1].duration) - .resize(width=W - 100) + .resize(width=screenshot_width) .set_opacity(new_opacity) .crossfadein(new_transition) .crossfadeout(new_transition) @@ -216,8 +216,8 @@ def make_final_video( thumbnail = Image.open(f"assets/backgrounds/{first_image}") width, height = thumbnail.size thumbnailSave = create_thumbnail(thumbnail, font_family, font_size, font_color, width, height, title_thumb) - thumbnailSave.save(f"./assets/temp/{id}/thumbnail.png") - print_substep(f"Thumbnail - Building Thumbnail in assets/temp/{id}/thumbnail.png") + thumbnailSave.save(f"./assets/temp/{reddit_id}/thumbnail.png") + print_substep(f"Thumbnail - Building Thumbnail in assets/temp/{reddit_id}/thumbnail.png") # create a tumbnail for the video settingsbackground = settings.config["settings"]["background"] @@ -246,8 +246,8 @@ def make_final_video( thumbnail = Image.open(f"assets/backgrounds/{first_image}") width, height = thumbnail.size thumbnailSave = create_thumbnail(thumbnail, font_family, font_size, font_color, width, height, title_thumb) - thumbnailSave.save(f"./assets/temp/{id}/thumbnail.png") - print_substep(f"Thumbnail - Building Thumbnail in assets/temp/{id}/thumbnail.png") + thumbnailSave.save(f"./assets/temp/{reddit_id}/thumbnail.png") + print_substep(f"Thumbnail - Building Thumbnail in assets/temp/{reddit_id}/thumbnail.png") # if settings.config["settings"]['background']["background_audio"] and exists(f"assets/backgrounds/background.mp3"): # audioclip = mpe.AudioFileClip(f"assets/backgrounds/background.mp3").set_duration(final.duration) @@ -269,6 +269,7 @@ def make_final_video( audio_bitrate="192k", verbose=False, threads=multiprocessing.cpu_count(), + preset="ultrafast", #TODO debug ) ffmpeg_extract_subclip( f"assets/temp/{reddit_id}/temp.mp4", diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 8e66d21..6a0a3b5 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -33,14 +33,12 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): # ! Make sure the reddit screenshots folder exists Path(f"assets/temp/{reddit_id}/png").mkdir(parents=True, exist_ok=True) - def download(cookie_file, num=None): - screenshot_num = num - with sync_playwright() as p: - print_substep("Launching Headless Browser...") - - browser = p.chromium.launch() # headless=False #to check for chrome view - context = browser.new_context() + screenshot_num: int + with sync_playwright() as p: + print_substep("Launching Headless Browser...") + browser = p.chromium.launch() # headless=False #to check for chrome view + context = browser.new_context() # Device scale factor (or dsf for short) allows us to increase the resolution of the screenshots # When the dsf is 1, the width of the screenshot is 600 pixels # so we need a dsf such that the width of the screenshot is greater than the final resolution of the video @@ -52,7 +50,11 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): viewport=ViewportSize(width=W, height=H), device_scale_factor=dsf, ) - + if settings.config["settings"]["storymodemethod"] == 1: + # for idx,item in enumerate(reddit_object["thread_post"]): + bgcolor = (255, 255, 255, 255) + txtcolor = (0, 0, 0) + imagemaker(theme=bgcolor, reddit_obj=reddit_object, txtclr=txtcolor) # set the theme and disable non-essential cookies if settings.config["settings"]["theme"] == "dark": cookie_file = open( @@ -104,15 +106,15 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): page.locator('[data-test-id="post-content"]').screenshot(path=postcontentpath) if storymode: - page.locator('[data-click-id="text"]').screenshot( + page.locator('[data-click-id="text"]').first.screenshot( path=f"assets/temp/{reddit_id}/png/story_content.png" ) else: for idx, comment in enumerate( - track( - reddit_object["comments"][:screenshot_num], - "Downloading screenshots...", - ) + track( + reddit_object["comments"][:screenshot_num], + "Downloading screenshots...", + ) ): # Stop if we have reached the screenshot_num if idx >= screenshot_num: @@ -147,4 +149,6 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): # close browser instance when we are done using it browser.close() + + print_substep("Screenshots downloaded Successfully.", style="bold green") \ No newline at end of file