From f0e5138857d3bc11a9ef0401e64197c08b57b244 Mon Sep 17 00:00:00 2001 From: electro199 Date: Sat, 12 Nov 2022 04:55:42 -0800 Subject: [PATCH] Fix:(Bug)empty string in story mode --- reddit/subreddit.py | 5 +++-- utils/imagenarator.py | 4 ++-- utils/posttextparser.py | 12 ++++++++---- video_creation/final_video.py | 2 ++ video_creation/screenshot_downloader.py | 3 +++ 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index fa10abc..6f7c3e9 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -41,8 +41,9 @@ def get_subreddit_threads(POST_ID: str): check_for_async=False, ) except ResponseException as e: - if e.response.status_code == 401: - print("Invalid credentials - please check them in config.toml") + match e.response.status_code: + case 401: + print("Invalid credentials - please check them in config.toml") except: print("Something went wrong...") diff --git a/utils/imagenarator.py b/utils/imagenarator.py index 9b81233..49a1e50 100644 --- a/utils/imagenarator.py +++ b/utils/imagenarator.py @@ -32,8 +32,8 @@ def imagemaker( theme, title=reddit_obj['thread_title'] texts=reddit_obj['thread_post'] id = re.sub(r"[^\w\s-]", "", reddit_obj["thread_id"]) - tfont=ImageFont.truetype("fonts\Roboto-Bold.ttf",27) # for title - font=ImageFont.truetype("fonts\Roboto-Regular.ttf", 20)# for despcription|comments + tfont=ImageFont.truetype("fonts\\Roboto-Bold.ttf",27) # for title + font=ImageFont.truetype("fonts\\Roboto-Regular.ttf", 20)# for despcription|comments size=(500,176) diff --git a/utils/posttextparser.py b/utils/posttextparser.py index 287e07f..8c9d0bf 100644 --- a/utils/posttextparser.py +++ b/utils/posttextparser.py @@ -1,5 +1,6 @@ import re import spacy +from utils.voice import sanitize_text #working good def posttextparser(obj): @@ -15,10 +16,13 @@ def posttextparser(obj): doc= nlp(text) - newtext=[] + newtext:list = [] + + # to check for space str for line in doc.sents: - newtext.append(line.text) - # print(line) - + if sanitize_text(line.text): + newtext.append(line.text) + # print(line) + return newtext \ No newline at end of file diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 3b28ce6..66cfa6b 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -179,6 +179,8 @@ def make_final_video( audio_bitrate="192k", verbose=False, threads=multiprocessing.cpu_count(), + # preset="ultrafast" #for testings + ) ffmpeg_extract_subclip( f"assets/temp/{id}/temp.mp4", diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 850aa32..fc8dd6d 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -26,8 +26,11 @@ def download_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: in reddit_object (Dict): Reddit object received from reddit/subreddit.py screenshot_num (int): Number of screenshots to download """ + print_step("Downloading screenshots of reddit posts...") + id = re.sub(r"[^\w\s-]", "", reddit_object["thread_id"]) + # ! Make sure the reddit screenshots folder exists Path(f"assets/temp/{id}/png").mkdir(parents=True, exist_ok=True) def download(cookie_file,num=None):