From c46ee59d9049164aeab3f2baa7665d892618e120 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Jul 2022 23:45:46 +0000 Subject: [PATCH 1/9] Bump botocore from 1.27.12 to 1.27.22 Bumps [botocore](https://github.com/boto/botocore) from 1.27.12 to 1.27.22. - [Release notes](https://github.com/boto/botocore/releases) - [Changelog](https://github.com/boto/botocore/blob/develop/CHANGELOG.rst) - [Commits](https://github.com/boto/botocore/compare/1.27.12...1.27.22) --- updated-dependencies: - dependency-name: botocore dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4cc217c..e01abce 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ boto3==1.24.12 -botocore==1.27.12 +botocore==1.27.22 gTTS==2.2.4 moviepy==1.0.3 mutagen==1.45.1 From 237eaa4789fda3641279b32d09a05107325d69b7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Jul 2022 23:45:48 +0000 Subject: [PATCH 2/9] Bump translators from 5.2.2 to 5.3.1 Bumps [translators](https://github.com/uliontse/translators) from 5.2.2 to 5.3.1. - [Release notes](https://github.com/uliontse/translators/releases) - [Commits](https://github.com/uliontse/translators/commits) --- updated-dependencies: - dependency-name: translators dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4cc217c..c33fd05 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,4 @@ python-dotenv==0.20.0 pytube==12.1.0 requests==2.28.1 rich==12.4.4 -translators==5.2.2 +translators==5.3.1 From 2e30c2e735e0e53ef880c2f705bd28603b507e79 Mon Sep 17 00:00:00 2001 From: Jarno Reynaert Date: Sun, 3 Jul 2022 02:27:25 +0200 Subject: [PATCH 3/9] Script uses removeprefix() which was only added in python 3.9 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bffbc8c..d863e7f 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ The only original thing being done is the editing and gathering of all materials ## Requirements -- Python 3.7+ +- Python 3.9+ - Playwright (this should install automatically in installation) ## Installation 👩‍💻 From 31b09dca38193af5f9217cabdec90e14c3b1ba74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Mustafa=20Ak=C5=9Fam?= Date: Sun, 3 Jul 2022 12:20:14 +0300 Subject: [PATCH 4/9] Update .env.template updated .env.template to match the regex --- .env.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.template b/.env.template index 7cf7cc2..77f2acf 100644 --- a/.env.template +++ b/.env.template @@ -14,7 +14,7 @@ REDDIT_CLIENT_SECRET="" #fFAGRNJru1FTz70BzhT3Zg REDDIT_USERNAME="" #asdfghjkl #EXPLANATION the username of your reddit account #RANGE 3:20 -#MATCH_REGEX [_0-9a-zA-Z]+$ +#MATCH_REGEX [-_0-9a-zA-Z]+$ #OOB_ERROR A username HAS to be between 3 and 20 characters REDDIT_PASSWORD="" #fFAGRNJru1FTz70BzhT3Zg From 7ee2297983175782d509760c2bb1782607349153 Mon Sep 17 00:00:00 2001 From: CordlessCoder <42666308+CordlessCoder@users.noreply.github.com> Date: Sun, 3 Jul 2022 14:09:55 +0300 Subject: [PATCH 5/9] Fix installation guide --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bffbc8c..6e97228 100644 --- a/README.md +++ b/README.md @@ -38,15 +38,13 @@ The only original thing being done is the editing and gathering of all materials ## Installation 👩‍💻 1. Clone this repository -2. **Automatic Install**: Run `python main.py` and type 'yes' to activate the setup assistant. +2. Run `pip install -r requirements.txt` -3. Run `pip install -r requirements.txt` +3. Run `playwright install` and `playwright install-deps`. (if this fails try adding python -m to the front of the command) -4. Run `playwright install` and `playwright install-deps`. (if this fails try adding python -m to the front of the command) - -5. Run `python main.py` (unless you chose automatic install, then the installer will automatically run main.py) +4. Run `python main.py` required\*\*), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". -6. Enjoy 😎 +5. Enjoy 😎 (Note if you got an error installing or running the bot try first rerunning the command with a three after the name e.g. python3 or pip3) From 90be9e09b3dc5027f11ebdd83e6a149f5f256e80 Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 3 Jul 2022 12:43:44 -0400 Subject: [PATCH 6/9] fixed the typehiting that @HallowedDust5 broke for py versions < 3.9 --- utils/videos.py | 7 ++++--- video_creation/final_video.py | 4 +++- video_creation/screenshot_downloader.py | 5 +++-- video_creation/voices.py | 3 ++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/utils/videos.py b/utils/videos.py index f675ecf..3a456cd 100755 --- a/utils/videos.py +++ b/utils/videos.py @@ -2,6 +2,7 @@ import json import os import time from os import getenv +from typing import Dict from praw.models import Submission @@ -9,16 +10,16 @@ from utils.console import print_step def check_done( - redditobj: dict[str], + redditobj: Dict[str], ) -> Submission: # don't set this to be run anyplace that isn't subreddit.py bc of inspect stack """Checks if the chosen post has already been generated Args: - redditobj (dict[str]): Reddit object gotten from reddit/subreddit.py + redditobj (Dict[str]): Reddit object gotten from reddit/subreddit.py Returns: - dict[str]|None: Reddit object in args + Dict[str]|None: Reddit object in args """ with open("./video_creation/data/videos.json", "r", encoding="utf-8") as done_vids_raw: diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 852c4b2..e429dbc 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -3,6 +3,7 @@ import multiprocessing import os import re from os.path import exists +from typing import Dict from moviepy.editor import ( VideoFileClip, @@ -25,12 +26,13 @@ console = Console() W, H = 1080, 1920 -def make_final_video(number_of_clips: int, length: int, reddit_obj: dict[str]): +def make_final_video(number_of_clips: int, length: int, reddit_obj: Dict[str]): """Gathers audio clips, gathers all screenshots, stitches them together and saves the final video to assets/temp Args: number_of_clips (int): Index to end at when going through the screenshots length (int): Length of the video + reddit_obj (Dict[str]): The reddit object that contains the posts to read. """ print_step("Creating the final video 🎥") VideoFileClip.reW = lambda clip: clip.resize(width=W) diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index aa1c9d9..670a472 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -2,6 +2,7 @@ import json import os from os import getenv from pathlib import Path +from typing import Dict from playwright.async_api import async_playwright # pylint: disable=unused-import @@ -16,11 +17,11 @@ from utils.console import print_step, print_substep storymode = False -def download_screenshots_of_reddit_posts(reddit_object: dict[str], screenshot_num: int): +def download_screenshots_of_reddit_posts(reddit_object: Dict[str], screenshot_num: int): """Downloads screenshots of reddit posts as seen on the web. Downloads to assets/temp/png Args: - reddit_object (dict[str]): Reddit object received from reddit/subreddit.py + reddit_object (Dict[str]): Reddit object received from reddit/subreddit.py screenshot_num (int): Number of screenshots to downlaod """ diff --git a/video_creation/voices.py b/video_creation/voices.py index 240c851..d02a14e 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import os +from typing import Dict, Tuple from rich.console import Console @@ -23,7 +24,7 @@ TTSProviders = { } -def save_text_to_mp3(reddit_obj: dict[str]) -> tuple[int, int]: +def save_text_to_mp3(reddit_obj: Dict[str]) -> Tuple[int, int]: """Saves text to MP3 files. Args: From 65e42f286d5505f1af42d69612e8909c7cf418e9 Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 3 Jul 2022 12:52:51 -0400 Subject: [PATCH 7/9] style: improved typehinting --- utils/videos.py | 3 +-- video_creation/final_video.py | 4 ++-- video_creation/screenshot_downloader.py | 3 +-- video_creation/voices.py | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/utils/videos.py b/utils/videos.py index 3a456cd..07659f6 100755 --- a/utils/videos.py +++ b/utils/videos.py @@ -10,7 +10,7 @@ from utils.console import print_step def check_done( - redditobj: Dict[str], + redditobj: Submission, ) -> Submission: # don't set this to be run anyplace that isn't subreddit.py bc of inspect stack """Checks if the chosen post has already been generated @@ -21,7 +21,6 @@ def check_done( Returns: Dict[str]|None: Reddit object in args """ - with open("./video_creation/data/videos.json", "r", encoding="utf-8") as done_vids_raw: done_videos = json.load(done_vids_raw) for video in done_videos: diff --git a/video_creation/final_video.py b/video_creation/final_video.py index e429dbc..81b9b98 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -26,13 +26,13 @@ console = Console() W, H = 1080, 1920 -def make_final_video(number_of_clips: int, length: int, reddit_obj: Dict[str]): +def make_final_video(number_of_clips: int, length: int, reddit_obj: dict): """Gathers audio clips, gathers all screenshots, stitches them together and saves the final video to assets/temp Args: number_of_clips (int): Index to end at when going through the screenshots length (int): Length of the video - reddit_obj (Dict[str]): The reddit object that contains the posts to read. + reddit_obj (dict): The reddit object that contains the posts to read. """ print_step("Creating the final video 🎥") VideoFileClip.reW = lambda clip: clip.resize(width=W) diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 670a472..e8afc44 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -17,14 +17,13 @@ from utils.console import print_step, print_substep storymode = False -def download_screenshots_of_reddit_posts(reddit_object: Dict[str], screenshot_num: int): +def download_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): """Downloads screenshots of reddit posts as seen on the web. Downloads to assets/temp/png Args: reddit_object (Dict[str]): Reddit object received from reddit/subreddit.py screenshot_num (int): Number of screenshots to downlaod """ - print_step("Downloading screenshots of reddit posts...") # ! Make sure the reddit screenshots folder exists diff --git a/video_creation/voices.py b/video_creation/voices.py index d02a14e..5105a10 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -24,7 +24,7 @@ TTSProviders = { } -def save_text_to_mp3(reddit_obj: Dict[str]) -> Tuple[int, int]: +def save_text_to_mp3(reddit_obj) -> Tuple[int, int]: """Saves text to MP3 files. Args: From 1c883e5ccd44771c42ad87b1fc87c65ead652079 Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 3 Jul 2022 12:55:27 -0400 Subject: [PATCH 8/9] fix: maybe fixed mutagen error using callums method --- TTS/engine_wrapper.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/TTS/engine_wrapper.py b/TTS/engine_wrapper.py index a06b4b9..ffabd35 100644 --- a/TTS/engine_wrapper.py +++ b/TTS/engine_wrapper.py @@ -95,9 +95,13 @@ class TTSEngine: def call_tts(self, filename: str, text: str): self.tts_module.run(text=process_text(text), filepath=f"{self.path}/{filename}.mp3") try: - self.length += MP3(f"{self.path}/{filename}.mp3").info.length - except (MutagenError, HeaderNotFoundError): - self.length += sox.file_info.duration(f"{self.path}/{filename}.mp3") + try: + self.length += MP3(f"{self.path}/{filename}.mp3").info.length + except (MutagenError, HeaderNotFoundError): + self.length += sox.file_info.duration(f"{self.path}/{filename}.mp3") + except Exception: # last resort backup + clip = AudioFileClip(f"{self.path}/{filename}.mp3") + self.length += clip.duration def process_text(text: str): lang = getenv("POSTLANG", "") From edf981ac399763a5e1d34ca5642bc7af5c9bedd5 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sun, 3 Jul 2022 18:12:11 +0100 Subject: [PATCH 9/9] chore: reduce code duplication --- video_creation/final_video.py | 49 ++++++++++++----------------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 81b9b98..23876ed 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -61,40 +61,25 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict): # add title to video image_clips = [] # Gather all images - if opacity is None or float(opacity) >= 1: # opacity not set or is set to one OR MORE - image_clips.insert( - 0, - ImageClip("assets/temp/png/title.png") - .set_duration(audio_clips[0].duration) - .set_position("center") - .resize(width=W - 100), - ) - else: - image_clips.insert( - 0, - ImageClip("assets/temp/png/title.png") - .set_duration(audio_clips[0].duration) - .set_position("center") - .resize(width=W - 100) - .set_opacity(float(opacity)), - ) + new_opacity = 1 if opacity is None or float(opacity) >= 1 else opacity + + image_clips.insert( + 0, + ImageClip("assets/temp/png/title.png") + .set_duration(audio_clips[0].duration) + .set_position("center") + .resize(width=W - 100) + .set_opacity(new_opacity) + ) for i in range(0, number_of_clips): - if opacity is None or float(opacity) >= 1: # opacity not set or is set to one OR MORE - image_clips.append( - ImageClip(f"assets/temp/png/comment_{i}.png") - .set_duration(audio_clips[i + 1].duration) - .set_position("center") - .resize(width=W - 100), - ) - else: - image_clips.append( - ImageClip(f"assets/temp/png/comment_{i}.png") - .set_duration(audio_clips[i + 1].duration) - .set_position("center") - .resize(width=W - 100) - .set_opacity(float(opacity)), - ) + image_clips.append( + ImageClip(f"assets/temp/png/comment_{i}.png") + .set_duration(audio_clips[i + 1].duration) + .set_position("center") + .resize(width=W - 100) + .set_opacity(new_opacity) + ) # if os.path.exists("assets/mp3/posttext.mp3"): # image_clips.insert(