diff --git a/main.py b/main.py index d0d21b9..1e76442 100755 --- a/main.py +++ b/main.py @@ -37,9 +37,7 @@ print_markdown( print_step(f"You are using v{__VERSION__} of the bot") -async def main( - POST_ID=None -): +async def main(POST_ID=None): cleanup() reddit_object = get_subreddit_threads(POST_ID) comments_created = save_text_to_mp3(reddit_object) @@ -84,7 +82,7 @@ if __name__ == "__main__": Popen("cls" if name == "nt" else "clear", shell=True).wait() else: main() - except KeyboardInterrupt: + except KeyboardInterrupt: # TODO wont work with async code shutdown() except ResponseException: # error for invalid credentials diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 50c1fb9..486447f 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -10,9 +10,7 @@ from utils.videos import check_done from utils.voice import sanitize_text -def get_subreddit_threads( - POST_ID: str -): +def get_subreddit_threads(POST_ID: str): """ Returns a list of threads from the AskReddit subreddit. """ diff --git a/utils/settings.py b/utils/settings.py index 53d83a4..43796bd 100755 --- a/utils/settings.py +++ b/utils/settings.py @@ -3,13 +3,13 @@ import toml from rich.console import Console import re -from typing import Tuple, Dict +from typing import Tuple, Dict, Optional from utils.console import handle_input console = Console() -config = dict() # calling instance of a dict to calm lint down (dict[any] will work as well) +config: Optional[dict] = None # autocomplete def crawl(obj: dict, func=lambda x, y: print(x, y, end="\n"), path=None): diff --git a/utils/subreddit.py b/utils/subreddit.py index 0a6b1e6..3253099 100644 --- a/utils/subreddit.py +++ b/utils/subreddit.py @@ -57,7 +57,7 @@ def get_subreddit_undone(submissions: list, subreddit, times_checked=0): return get_subreddit_undone( subreddit.top( - time_filter=VALID_TIME_FILTERS[index], limit=100 + time_filter=VALID_TIME_FILTERS[index], limit=(50 if int(index) == 0 else index + 1 * 50) ), subreddit, times_checked=index, diff --git a/utils/video.py b/utils/video.py index 0d65e68..556693e 100644 --- a/utils/video.py +++ b/utils/video.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Tuple from PIL import ImageFont, Image, ImageDraw, ImageEnhance @@ -26,7 +28,7 @@ class Video: draw = ImageDraw.Draw(wm) w, h = draw.textsize(text, font) draw.text(((width - w) / 2, (height - h) / 2), text, white, font) - en = ImageEnhance.Brightness(wm) # TODO allow it to use the fontsize + en = ImageEnhance.Brightness(wm) # todo allow it to use the fontsize mask = en.enhance(1 - opacity) im.paste(wm, (25, 25), mask) im.save(path) @@ -40,11 +42,13 @@ class Video: ndigits=2, ) position = (compensation, position[1]) + # print(f'{compensation=}') + # print(f'{position=}') img_clip = self._create_watermark(text, opacity=opacity, fontsize=fontsize) img_clip = img_clip.set_opacity(opacity).set_duration(duration) img_clip = img_clip.set_position( position, relative=True - ) # TODO get data from utils/CONSTANTS.py and adapt position accordingly + ) # todo get data from utils/CONSTANTS.py and adapt position accordingly # Overlay the img clip on the first video clip self.video = CompositeVideoClip([self.video, img_clip]) diff --git a/utils/voice.py b/utils/voice.py index 3113227..a0709fa 100644 --- a/utils/voice.py +++ b/utils/voice.py @@ -10,9 +10,7 @@ if sys.version_info[0] >= 3: from datetime import timezone -def check_ratelimit( - response: Response, -): +def check_ratelimit(response: Response): """ Checks if the response is a ratelimit response. If it is, it sleeps for the time specified in the response. diff --git a/video_creation/background.py b/video_creation/background.py index 73f4251..6e656fa 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -38,7 +38,7 @@ def get_background_config(): # Handle default / not supported background using default option. # Default : pick random from supported background. - if choice not in background_options: + if not choice or choice not in background_options: choice = random.choice(list(background_options.keys())) return background_options[choice] diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 2063bf0..88ea499 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -57,7 +57,7 @@ class FinalVideo: name = re.sub(r"(\d+)\s?/\s?(\d+)", r"\1 of \2", name) name = re.sub(r"(\w+)\s?/\s?(\w+)", r"\1 or \2", name) name = re.sub(r"/", "", name) - # name[:30] # the hell this little guy does? commented until explained + # name[:30] # does nothing lang = settings.config["reddit"]["thread"]["post_lang"] if lang: diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 0ec7e4e..62e4df1 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -89,6 +89,7 @@ class Browser: default_Viewport: dict = attrib( validator=instance_of(dict), default={ + # 9x21 to see long posts "defaultViewport": { "width": 500, "height": 1200, diff --git a/video_creation/voices.py b/video_creation/voices.py index b372042..1e5a1a5 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -3,7 +3,6 @@ from TTS.GTTS import GTTS from TTS.streamlabs_polly import StreamlabsPolly from TTS.aws_polly import AWSPolly from TTS.TikTok import TikTok - from utils import settings from utils.console import print_table, print_step @@ -41,11 +40,7 @@ def save_text_to_mp3( return engine_instance.run() -def get_case_insensitive_key_value( - input_dict, - key, -) -> object: - # TODO add a factory later +def get_case_insensitive_key_value(input_dict, key): return next( (value for dict_key, value in input_dict.items() if dict_key.lower() == key.lower()), None,