4 files changed
+40
-19
No files matched your search
@@ -1,13 +1,12 @@
|
||||
import multiprocessing
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
from os.path import exists # Needs to be imported specifically
|
||||
from typing import Final
|
||||
from typing import Tuple, Any, Dict
|
||||
|
||||
import ffmpeg
|
||||
import translators as ts
|
||||
import translators
|
||||
from PIL import Image
|
||||
from rich.console import Console
|
||||
from rich.progress import track
|
||||
@@ -18,12 +17,12 @@ from utils.console import print_step, print_substep
|
||||
from utils.thumbnail import create_thumbnail
|
||||
from utils.videos import save_data
|
||||
|
||||
console = Console()
|
||||
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
|
||||
console = Console()
|
||||
|
||||
|
||||
class ProgressFfmpeg(threading.Thread):
|
||||
def __init__(self, vid_duration_seconds, progress_update_callback):
|
||||
@@ -73,7 +72,7 @@ def name_normalize(name: str) -> str:
|
||||
lang = settings.config["reddit"]["thread"]["post_lang"]
|
||||
if lang:
|
||||
print_substep("Translating filename...")
|
||||
translated_name = ts.google(name, to_language=lang)
|
||||
translated_name = translators.google(name, to_language=lang)
|
||||
return translated_name
|
||||
else:
|
||||
return name
|
||||
|
||||
@@ -3,7 +3,7 @@ import re
|
||||
from pathlib import Path
|
||||
from typing import Dict, Final
|
||||
|
||||
import translators as ts
|
||||
import translators
|
||||
from playwright.async_api import async_playwright # pylint: disable=unused-import
|
||||
from playwright.sync_api import ViewportSize, sync_playwright
|
||||
from rich.progress import track
|
||||
@@ -157,7 +157,7 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
|
||||
|
||||
if lang:
|
||||
print_substep("Translating post...")
|
||||
texts_in_tl = ts.google(
|
||||
texts_in_tl = translators.google(
|
||||
reddit_object["thread_title"],
|
||||
to_language=lang,
|
||||
)
|
||||
@@ -171,9 +171,20 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
|
||||
|
||||
postcontentpath = f"assets/temp/{reddit_id}/png/title.png"
|
||||
try:
|
||||
page.locator('[data-test-id="post-content"]').screenshot(
|
||||
path=postcontentpath
|
||||
)
|
||||
if settings.config["settings"]["zoom"] != 1:
|
||||
# store zoom settings
|
||||
zoom = settings.config["settings"]["zoom"]
|
||||
# zoom the body of the page
|
||||
page.evaluate("document.body.style.zoom="+str(zoom))
|
||||
# as zooming the body doesn't change the properties of the divs, we need to adjust for the zoom
|
||||
location = page.locator('[data-test-id="post-content"]').bounding_box()
|
||||
for i in location:
|
||||
location[i] = float("{:.2f}".format(location[i]*zoom))
|
||||
page.screenshot(clip=location, path=postcontentpath)
|
||||
else:
|
||||
page.locator('[data-test-id="post-content"]').screenshot(
|
||||
path=postcontentpath
|
||||
)
|
||||
except Exception as e:
|
||||
print_substep("Something went wrong!", style="red")
|
||||
resp = input(
|
||||
@@ -218,7 +229,7 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
|
||||
# translate code
|
||||
|
||||
if settings.config["reddit"]["thread"]["post_lang"]:
|
||||
comment_tl = ts.google(
|
||||
comment_tl = translators.google(
|
||||
comment["comment_body"],
|
||||
to_language=settings.config["reddit"]["thread"]["post_lang"],
|
||||
)
|
||||
@@ -227,9 +238,22 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
|
||||
[comment_tl, comment["comment_id"]],
|
||||
)
|
||||
try:
|
||||
page.locator(f"#t1_{comment['comment_id']}").screenshot(
|
||||
path=f"assets/temp/{reddit_id}/png/comment_{idx}.png"
|
||||
)
|
||||
if settings.config["settings"]["zoom"] != 1:
|
||||
# store zoom settings
|
||||
zoom = settings.config["settings"]["zoom"]
|
||||
# zoom the body of the page
|
||||
page.evaluate("document.body.style.zoom="+str(zoom))
|
||||
# scroll comment into view
|
||||
page.locator(f"#t1_{comment['comment_id']}").scroll_into_view_if_needed()
|
||||
# as zooming the body doesn't change the properties of the divs, we need to adjust for the zoom
|
||||
location = page.locator(f"#t1_{comment['comment_id']}").bounding_box()
|
||||
for i in location:
|
||||
location[i] = float("{:.2f}".format(location[i]*zoom))
|
||||
page.screenshot(clip=location, path=f"assets/temp/{reddit_id}/png/comment_{idx}.png")
|
||||
else:
|
||||
page.locator(f"#t1_{comment['comment_id']}").screenshot(
|
||||
path=f"assets/temp/{reddit_id}/png/comment_{idx}.png"
|
||||
)
|
||||
except TimeoutError:
|
||||
del reddit_object["comments"]
|
||||
screenshot_num += 1
|
||||
|
||||
Reference in new issue
Block a user