Merge pull request #1476 from electro199/newtest

Fixed timeout error, add error for TikTok session ID if missing and improved return hinting
pull/1477/head
Simon 2 years ago committed by GitHub
commit 10d5571781
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -79,6 +79,8 @@ vocals: Final[tuple] = (
class TikTok: class TikTok:
"""TikTok Text-to-Speech Wrapper""" """TikTok Text-to-Speech Wrapper"""
def __init__(self): def __init__(self):
if not settings.config['settings']['tts']['tiktok_sessionid']:
raise TikTokTTSException(5)
headers = { headers = {
"User-Agent": "com.zhiliaoapp.musically/2022600030 (Linux; U; Android 7.1.2; es_ES; SM-G988N; " "User-Agent": "com.zhiliaoapp.musically/2022600030 (Linux; U; Android 7.1.2; es_ES; SM-G988N; "
"Build/NRD90M;tt-ok/3.12.13.1)", "Build/NRD90M;tt-ok/3.12.13.1)",
@ -140,7 +142,7 @@ class TikTok:
return response.json() return response.json()
@staticmethod @staticmethod
def random_voice(): def random_voice() -> str:
return random.choice(eng_voices) return random.choice(eng_voices)
@ -159,4 +161,7 @@ class TikTokTTSException(Exception):
if self._code == 4: if self._code == 4:
return f"Code: {self._code}, reason: the speaker doesn't exist, message: {self._message}" return f"Code: {self._code}, reason: the speaker doesn't exist, message: {self._message}"
if self._code == 5:
return f"You have to add session id in config to use titok TTS"
return f"Code: {self._message}, reason: unknown, message: {self._message}" return f"Code: {self._message}, reason: unknown, message: {self._message}"

@ -134,6 +134,7 @@ def get_subreddit_threads(POST_ID: str):
content["thread_url"] = threadurl content["thread_url"] = threadurl
content["thread_title"] = submission.title content["thread_title"] = submission.title
content["thread_id"] = submission.id content["thread_id"] = submission.id
content["is_nsfw"] = submission.over_18
content["comments"] = [] content["comments"] = []
if settings.config["settings"]["storymode"]: if settings.config["settings"]["storymode"]:
if settings.config["settings"]["storymodemethod"] == 1: if settings.config["settings"]["storymodemethod"] == 1:

@ -6,7 +6,7 @@ from PIL import Image, ImageDraw, ImageFont
from rich.progress import track from rich.progress import track
from TTS.engine_wrapper import process_text from TTS.engine_wrapper import process_text
def draw_multiple_line_text(image, text, font, text_color, padding, wrap=50): def draw_multiple_line_text(image, text, font, text_color, padding, wrap=50) -> None:
""" """
Draw multiline text over given image Draw multiline text over given image
""" """
@ -24,7 +24,7 @@ def draw_multiple_line_text(image, text, font, text_color, padding, wrap=50):
# theme=bgcolor,reddit_obj=reddit_object,txtclr=txtcolor # theme=bgcolor,reddit_obj=reddit_object,txtclr=txtcolor
def imagemaker(theme, reddit_obj: dict, txtclr, padding=5): def imagemaker(theme, reddit_obj: dict, txtclr, padding=5) -> None:
""" """
Render Images for video Render Images for video
""" """

@ -13,7 +13,7 @@ if sys.version_info[0] >= 3:
from datetime import timezone from datetime import timezone
def check_ratelimit(response: Response): def check_ratelimit(response: Response) -> bool:
""" """
Checks if the response is a ratelimit response. Checks if the response is a ratelimit response.
If it is, it sleeps for the time specified in the response. If it is, it sleeps for the time specified in the response.
@ -30,7 +30,7 @@ def check_ratelimit(response: Response):
return True return True
def sleep_until(time): def sleep_until(time) -> None:
""" """
Pause your program until a specific end time. Pause your program until a specific end time.
'time' is either a valid datetime object or unix timestamp in seconds (i.e. seconds since Unix epoch) 'time' is either a valid datetime object or unix timestamp in seconds (i.e. seconds since Unix epoch)

@ -11,6 +11,8 @@ from utils import settings
from utils.console import print_step, print_substep from utils.console import print_step, print_substep
from utils.imagenarator import imagemaker from utils.imagenarator import imagemaker
from utils.videos import save_data
__all__ = ["download_screenshots_of_reddit_posts"] __all__ = ["download_screenshots_of_reddit_posts"]
@ -118,7 +120,23 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
print_substep("Skipping translation...") print_substep("Skipping translation...")
postcontentpath = f"assets/temp/{reddit_id}/png/title.png" postcontentpath = f"assets/temp/{reddit_id}/png/title.png"
page.locator('[data-test-id="post-content"]').screenshot(path=postcontentpath) try:
page.locator('[data-test-id="post-content"]').screenshot(path=postcontentpath)
except Exception as e:
OKGREEN = '\033[92m'
WARNING = '\033[93m'
ENDC = '\033[0m'
print_step(f"{WARNING}Something went wrong!{ENDC}")
resp = input("Something went wrong with making the screenshots! Do you want to skip the post? (y/n) ")
if resp.casefold().startswith("y"):
save_data("", "", "skipped", reddit_id, "")
print(f"{OKGREEN}The post is successfully skipped! You can now restart the program and this post will skipped.{ENDC}")
resp = input("Do you want the error traceback for debugging purposes? (y/n)")
if resp.casefold().startswith("y"):
print(e)
exit()
else:
exit()
if storymode: if storymode:
page.locator('[data-click-id="text"]').first.screenshot( page.locator('[data-click-id="text"]').first.screenshot(

Loading…
Cancel
Save