reformatted code
This commit is contained in:
1 parent
420bac9a5a
commit
4abf803170
6 files changed
+53
-19
No files matched your search
@@ -1,4 +1,3 @@
|
||||
|
||||
# Supported Background. Can add/remove background video here....
|
||||
# <key>-<value> : key -> used as keyword for TOML file. value -> background configuration
|
||||
# Format (value):
|
||||
|
||||
+14
-2
@@ -41,13 +41,25 @@ def get_subreddit_undone(submissions: list, subreddit, times_checked=0):
|
||||
continue
|
||||
return submission
|
||||
print("all submissions have been done going by top submission order")
|
||||
VALID_TIME_FILTERS = ["day", "hour", "month", "week", "year", 'all'] # set doesn't have __getitem__
|
||||
VALID_TIME_FILTERS = [
|
||||
"day",
|
||||
"hour",
|
||||
"month",
|
||||
"week",
|
||||
"year",
|
||||
"all",
|
||||
] # set doesn't have __getitem__
|
||||
index = times_checked + 1
|
||||
if index == len(VALID_TIME_FILTERS):
|
||||
print("all time filters have been checked you absolute madlad ")
|
||||
|
||||
return get_subreddit_undone(
|
||||
subreddit.top(time_filter=VALID_TIME_FILTERS[index], limit=(50 if int(index) == 0 else index+1 * 50)), subreddit, times_checked=index) # all the videos in hot have already been done
|
||||
subreddit.top(
|
||||
time_filter=VALID_TIME_FILTERS[index], limit=(50 if int(index) == 0 else index + 1 * 50)
|
||||
),
|
||||
subreddit,
|
||||
times_checked=index,
|
||||
) # all the videos in hot have already been done
|
||||
|
||||
|
||||
def already_done(done_videos: list, submission) -> bool:
|
||||
|
||||
+12
-5
@@ -34,14 +34,21 @@ class Video:
|
||||
im.save(path)
|
||||
return ImageClip(path)
|
||||
|
||||
def add_watermark(self, text, opacity=0.5, duration: int | float = 5, position: Tuple = (0.7, 0.9), fontsize=15):
|
||||
compensation = round((position[0] / ((len(text) * (fontsize / 5) / 1.5) / 100 + position[0] * position[0])), ndigits=2)
|
||||
def add_watermark(
|
||||
self, text, opacity=0.5, duration: int | float = 5, position: Tuple = (0.7, 0.9), fontsize=15
|
||||
):
|
||||
compensation = round(
|
||||
(position[0] / ((len(text) * (fontsize / 5) / 1.5) / 100 + position[0] * position[0])),
|
||||
ndigits=2,
|
||||
)
|
||||
position = (compensation, position[1])
|
||||
#print(f'{compensation=}')
|
||||
#print(f'{position=}')
|
||||
# print(f'{compensation=}')
|
||||
# print(f'{position=}')
|
||||
img_clip = self._create_watermark(text, opacity=opacity, fontsize=fontsize)
|
||||
img_clip = img_clip.set_opacity(opacity).set_duration(duration)
|
||||
img_clip = img_clip.set_position(position, relative=True) # todo get dara from utils/CONSTANTS.py and adapt position accordingly
|
||||
img_clip = img_clip.set_position(
|
||||
position, relative=True
|
||||
) # todo get dara from utils/CONSTANTS.py and adapt position accordingly
|
||||
|
||||
# Overlay the img clip on the first video clip
|
||||
self.video = CompositeVideoClip([self.video, img_clip])
|
||||
|
||||
@@ -13,6 +13,7 @@ from utils import settings
|
||||
from utils.CONSTANTS import background_options
|
||||
from utils.console import print_step, print_substep
|
||||
|
||||
|
||||
def get_start_and_end_times(video_length: int, length_of_clip: int) -> Tuple[int, int]:
|
||||
"""Generates a random interval of time to be used as the background of the video.
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ def name_normalize(name: str) -> str:
|
||||
lang = settings.config["reddit"]["thread"]["post_lang"]
|
||||
if lang:
|
||||
import translators as ts
|
||||
|
||||
print_substep("Translating filename...")
|
||||
translated_name = ts.google(name, to_language=lang)
|
||||
return translated_name
|
||||
|
||||
@@ -51,27 +51,36 @@ def download_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: in
|
||||
page.locator('[data-testid="content-gate"] button').click()
|
||||
|
||||
if page.locator('[data-click-id="text"] button').is_visible():
|
||||
page.locator('[data-click-id="text"] button').click() # Remove "Click to see nsfw" Button in Screenshot
|
||||
page.locator(
|
||||
'[data-click-id="text"] button'
|
||||
).click() # Remove "Click to see nsfw" Button in Screenshot
|
||||
|
||||
# translate code
|
||||
|
||||
if settings.config["reddit"]["thread"]["post_lang"]:
|
||||
print_substep("Translating post...")
|
||||
texts_in_tl = ts.google(reddit_object["thread_title"],
|
||||
to_language=settings.config["reddit"]["thread"]["post_lang"], )
|
||||
texts_in_tl = ts.google(
|
||||
reddit_object["thread_title"],
|
||||
to_language=settings.config["reddit"]["thread"]["post_lang"],
|
||||
)
|
||||
|
||||
page.evaluate(
|
||||
"tl_content => document.querySelector('[data-test-id=\"post-content\"] > div:nth-child(3) > div > div').textContent = tl_content",
|
||||
texts_in_tl, )
|
||||
texts_in_tl,
|
||||
)
|
||||
else:
|
||||
print_substep("Skipping translation...")
|
||||
|
||||
page.locator('[data-test-id="post-content"]').screenshot(path="assets/temp/png/title.png")
|
||||
|
||||
if storymode:
|
||||
page.locator('[data-click-id="text"]').screenshot(path="assets/temp/png/story_content.png")
|
||||
page.locator('[data-click-id="text"]').screenshot(
|
||||
path="assets/temp/png/story_content.png"
|
||||
)
|
||||
else:
|
||||
for idx, comment in enumerate(track(reddit_object["comments"], "Downloading screenshots...")):
|
||||
for idx, comment in enumerate(
|
||||
track(reddit_object["comments"], "Downloading screenshots...")
|
||||
):
|
||||
# Stop if we have reached the screenshot_num
|
||||
if idx >= screenshot_num:
|
||||
break
|
||||
@@ -84,16 +93,21 @@ def download_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: in
|
||||
# translate code
|
||||
|
||||
if settings.config["reddit"]["thread"]["post_lang"]:
|
||||
comment_tl = ts.google(comment["comment_body"],
|
||||
to_language=settings.config["reddit"]["thread"]["post_lang"], )
|
||||
comment_tl = ts.google(
|
||||
comment["comment_body"],
|
||||
to_language=settings.config["reddit"]["thread"]["post_lang"],
|
||||
)
|
||||
page.evaluate(
|
||||
'([tl_content, tl_id]) => document.querySelector(`#t1_${tl_id} > div:nth-child(2) > div > div[data-testid="comment"] > div`).textContent = tl_content',
|
||||
[comment_tl, comment["comment_id"]], )
|
||||
[comment_tl, comment["comment_id"]],
|
||||
)
|
||||
try:
|
||||
page.locator(f"#t1_{comment['comment_id']}").screenshot(path=f"assets/temp/png/comment_{idx}.png")
|
||||
page.locator(f"#t1_{comment['comment_id']}").screenshot(
|
||||
path=f"assets/temp/png/comment_{idx}.png"
|
||||
)
|
||||
except TimeoutError:
|
||||
del reddit_object["comments"]
|
||||
screenshot_num += 1
|
||||
print('TimeoutError: Skipping screenshot...')
|
||||
print("TimeoutError: Skipping screenshot...")
|
||||
continue
|
||||
print_substep("Screenshots downloaded Successfully.", style="bold green")
|
||||
Reference in new issue
Block a user