pull/1671/head
Simon 2 years ago
parent 0a1ba17d0e
commit 280b125505

@ -6,7 +6,6 @@ from pathlib import Path
from subprocess import Popen from subprocess import Popen
from typing import NoReturn from typing import NoReturn
import ffmpeg
from prawcore import ResponseException from prawcore import ResponseException
from utils.console import print_substep from utils.console import print_substep
from reddit.subreddit import get_subreddit_threads from reddit.subreddit import get_subreddit_threads
@ -62,7 +61,6 @@ def main(POST_ID=None) -> None:
make_final_video(number_of_comments, length, reddit_object, bg_config) make_final_video(number_of_comments, length, reddit_object, bg_config)
def run_many(times) -> None: def run_many(times) -> None:
for x in range(1, times + 1): for x in range(1, times + 1):
print_step( print_step(
@ -73,30 +71,24 @@ def run_many(times) -> None:
def shutdown() -> NoReturn: def shutdown() -> NoReturn:
if "redditid" in globals():
if "redditid" in globals() :
print_markdown("## Clearing temp files") print_markdown("## Clearing temp files")
cleanup(redditid) cleanup(redditid)
print("Exiting...")
sys.exit()
print("Exiting...") print("Exiting...")
sys.exit() sys.exit()
if __name__ == "__main__": if __name__ == "__main__":
if sys.version_info.major != 3 or sys.version_info.minor != 10: if sys.version_info.major != 3 or sys.version_info.minor != 10:
print("Hey! Congratulations, you've made it so far (which is pretty rare with no Python 3.10). Unfortunately, this program only works on Python 3.10. Please install Python 3.10 and try again.") print("Hey! Congratulations, you've made it so far (which is pretty rare with no Python 3.10). Unfortunately, this program only works on Python 3.10. Please install Python 3.10 and try again.")
sys.exit() sys.exit()
ffmpeg_install() # install ffmpeg if not installed ffmpeg_install()
directory = Path().absolute() directory = Path().absolute()
config = settings.check_toml( config = settings.check_toml(
f"{directory}/utils/.config.template.toml", f"{directory}/config.toml" f"{directory}/utils/.config.template.toml", f"{directory}/config.toml"
) )
if not config : config is False and sys.exit()
sys.exit()
if ( if (
not settings.config["settings"]["tts"]["tiktok_sessionid"] not settings.config["settings"]["tts"]["tiktok_sessionid"]
@ -125,10 +117,8 @@ if __name__ == "__main__":
except KeyboardInterrupt: except KeyboardInterrupt:
shutdown() shutdown()
except ResponseException: except ResponseException:
# error for invalid credentials
print_markdown("## Invalid credentials") print_markdown("## Invalid credentials")
print_markdown("Please check your credentials in the config.toml file") print_markdown("Please check your credentials in the config.toml file")
shutdown() shutdown()
except Exception as err: except Exception as err:
config["settings"]["tts"]["tiktok_sessionid"] = "REDACTED" config["settings"]["tts"]["tiktok_sessionid"] = "REDACTED"

@ -6,6 +6,9 @@ if exist "%VENV_DIR%" (
call "%VENV_DIR%\Scripts\activate.bat" call "%VENV_DIR%\Scripts\activate.bat"
) )
echo Installing dependencies...
pip install -r requirements.txt
echo Running Python script... echo Running Python script...
python main.py python main.py
@ -13,8 +16,3 @@ if errorlevel 1 (
echo An error occurred. Press any key to exit. echo An error occurred. Press any key to exit.
pause >nul pause >nul
) )
if exist "%VENV_DIR%" (
echo Deactivating virtual environment...
call "%VENV_DIR%\Scripts\deactivate.bat"
)

@ -22,13 +22,11 @@ def ffmpeg_install_windows():
for file in os.listdir("ffmpeg/doc"): for file in os.listdir("ffmpeg/doc"):
os.remove(f"ffmpeg/doc/{file}") os.remove(f"ffmpeg/doc/{file}")
os.rmdir("ffmpeg/doc") os.rmdir("ffmpeg/doc")
os.remove("ffmpeg/LICENSE.txt")
os.rmdir("ffmpeg/LICENSE.txt")
os.rmdir("ffmpeg/") os.rmdir("ffmpeg/")
print("FFmpeg installed successfully! Please restart your computer and then re-run the program.") print("FFmpeg installed successfully! Please restart your computer and then re-run the program.")
except Exception as e: except Exception as e:
print( print(
"An error occurred while trying to install FFmpeg. Please try again. Otherwise, please install FFmpeg manually and try again." "An error occurred while trying to install FFmpeg. Please try again. Otherwise, please install FFmpeg manually and try again."
@ -77,10 +75,13 @@ def ffmpeg_install():
# Try to run the FFmpeg command # Try to run the FFmpeg command
subprocess.run(['ffmpeg', '-version'], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) subprocess.run(['ffmpeg', '-version'], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except FileNotFoundError as e: except FileNotFoundError as e:
if not os.path.exists("./results") : # Check if there's ffmpeg.exe in the current directory
if os.path.exists("./ffmpeg.exe"):
print('FFmpeg is installed on this system! If you are seeing this error for the second time, restart your computer.') print('FFmpeg is installed on this system! If you are seeing this error for the second time, restart your computer.')
print('FFmpeg is not installed on this system.') print('FFmpeg is not installed on this system.')
resp = input(
"We can try to automatically install it for you. Would you like to do that? (y/n): "
)
if resp.lower() == "y": if resp.lower() == "y":
print("Installing FFmpeg...") print("Installing FFmpeg...")
if os.name == "nt": if os.name == "nt":

@ -1,5 +1,6 @@
import os import os
import re import re
import time
from typing import List from typing import List
import spacy import spacy
@ -9,19 +10,19 @@ from utils.voice import sanitize_text
# working good # working good
def posttextparser(obj,*,tried:bool=False) -> List[str]: def posttextparser(obj, *, tried: bool = False) -> List[str]:
text:str = re.sub("\n", " ", obj) text: str = re.sub("\n", " ", obj)
try: try:
nlp = spacy.load("en_core_web_sm") nlp = spacy.load("en_core_web_sm")
except OSError as e: except OSError as e:
if not tried: if not tried:
os.system("python -m spacy download en_core_web_sm") os.system("python -m spacy download en_core_web_sm")
return posttextparser(obj,tried=True) time.sleep(5)
return posttextparser(obj, tried=True)
print_step(" The spacy model can't load. You need to install it with the command \npython -m spacy download en_core_web_sm ") print_step(
"The spacy model can't load. You need to install it with the command \npython -m spacy download en_core_web_sm ")
raise e raise e
doc = nlp(text) doc = nlp(text)
newtext: list = [] newtext: list = []

@ -1,20 +0,0 @@
import sys
from typing import NoReturn
from utils import settings
from utils.console import print_substep
def validat_env(obj) -> NoReturn | None:
"""
check for wrong
"""
if (
settings.config["settings"]["tts"]["tiktok_sessionid"] == ""
and settings.config["settings"]["tts"]["voice_choice"] == "tiktok"
):
print_substep(
"TikTok voice requires a sessionid! Check our documentation on how to obtain one.",
"bold red",
)
sys.exit()
Loading…
Cancel
Save