Fixed Timeout error and improved return hinting
This commit is contained in:
1 parent
576e208eb7
commit
1f8ebf5eeb
4 files changed
+23
-7
No files matched your search
+6
-1
@@ -79,6 +79,8 @@ vocals: Final[tuple] = (
|
||||
class TikTok:
|
||||
"""TikTok Text-to-Speech Wrapper"""
|
||||
def __init__(self):
|
||||
if not settings.config['settings']['tts']['tiktok_sessionid']:
|
||||
raise TikTokTTSException(5)
|
||||
headers = {
|
||||
"User-Agent": "com.zhiliaoapp.musically/2022600030 (Linux; U; Android 7.1.2; es_ES; SM-G988N; "
|
||||
"Build/NRD90M;tt-ok/3.12.13.1)",
|
||||
@@ -140,7 +142,7 @@ class TikTok:
|
||||
return response.json()
|
||||
|
||||
@staticmethod
|
||||
def random_voice():
|
||||
def random_voice() -> str:
|
||||
return random.choice(eng_voices)
|
||||
|
||||
|
||||
@@ -158,5 +160,8 @@ class TikTokTTSException(Exception):
|
||||
|
||||
if self._code == 4:
|
||||
return f"Code: {self._code}, reason: the speaker doesn't exist, message: {self._message}"
|
||||
|
||||
if self._code == 5:
|
||||
return f"Would you mind add session id in config ??"
|
||||
|
||||
return f"Code: {self._message}, reason: unknown, message: {self._message}"
|
||||
@@ -6,7 +6,7 @@ from PIL import Image, ImageDraw, ImageFont
|
||||
from rich.progress import track
|
||||
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
|
||||
"""
|
||||
@@ -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
|
||||
def imagemaker(theme, reddit_obj: dict, txtclr, padding=5):
|
||||
def imagemaker(theme, reddit_obj: dict, txtclr, padding=5) -> None:
|
||||
"""
|
||||
Render Images for video
|
||||
"""
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@ if sys.version_info[0] >= 3:
|
||||
from datetime import timezone
|
||||
|
||||
|
||||
def check_ratelimit(response: Response):
|
||||
def check_ratelimit(response: Response) -> bool:
|
||||
"""
|
||||
Checks if the response is a ratelimit response.
|
||||
If it is, it sleeps for the time specified in the response.
|
||||
@@ -30,7 +30,7 @@ def check_ratelimit(response: Response):
|
||||
return True
|
||||
|
||||
|
||||
def sleep_until(time):
|
||||
def sleep_until(time) -> None:
|
||||
"""
|
||||
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)
|
||||
|
||||
@@ -11,6 +11,7 @@ from rich.progress import track
|
||||
from utils import settings
|
||||
from utils.console import print_step, print_substep
|
||||
from utils.imagenarator import imagemaker
|
||||
from utils.videos import save_data
|
||||
|
||||
|
||||
__all__ = ["download_screenshots_of_reddit_posts"]
|
||||
@@ -105,8 +106,18 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
|
||||
print_substep("Skipping translation...")
|
||||
|
||||
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 TimeoutError as e:
|
||||
print_step("unable to locate post It is possibly Due to a NSFW post or unstable internet")
|
||||
resp = input("Do you want to skip the post?(y/n)")
|
||||
if resp.startswith("y"):
|
||||
save_data("","","skiped",reddit_id,"")
|
||||
print("Now you can re run the program this post will skipped")
|
||||
exit()
|
||||
raise e
|
||||
|
||||
if storymode:
|
||||
page.locator('[data-click-id="text"]').first.screenshot(
|
||||
path=f"assets/temp/{reddit_id}/png/story_content.png"
|
||||
|
||||
Reference in new issue
Block a user