Skip to content

Commit

Permalink
Merge pull request #98 from LuisMayo/add-safe-mode
Browse files Browse the repository at this point in the history
Added adult-only mode for aditional safety
  • Loading branch information
LuisMayo authored Nov 17, 2022
2 parents 0bc2bcf + 5634745 commit be2136a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
Comment(user_name = 'm', text_content='Hello OwO'),
Comment(user_name = 'n', text_content='Hello OwO'),
Comment(user_name = 'o', text_content='《长征》第1集 <red>The Long March</red> 01震惊世界的二万五千里长征<green>(唐国强/陈道明)</green>【CCTV电视剧】Highlights:毛泽东针对奔袭湘江的作战命令会给数万红军带来的严重损失,连夜找“三人团”请示复议作战计划,李德不耐烦地指责毛泽东是在危言耸听。'),
Comment(user_name = 'o', text_content='Hello OwO')
Comment(user_name = 'p', text_content='Hello OwO'),
Comment(user_name = 'q', text_content='Hello OwO'),
Comment(user_name = 'r', text_content='Hello OwO'),
Comment(user_name = 's', text_content='Hello OwO'),
Comment(user_name = 't', text_content='Hello OwO')
] * 1
render_comment_list(comments, f'output-{str(int(time()))}.mp4')
6 changes: 4 additions & 2 deletions objection_engine/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import requests


def render_comment_list(comment_list: List[Comment], output_filename: str = 'hello.mp4', music_code: str = 'PWR', resolution_scale: int = 1, assigned_characters: dict = None):
def render_comment_list(comment_list: List[Comment], output_filename: str = 'hello.mp4', music_code: str = 'PWR', resolution_scale: int = 1, assigned_characters: dict = None, adult_mode = False):
"""
Given a list of Comments, writes a resulting video to disk at the
location specified by `output_filename`.
Expand All @@ -30,6 +30,8 @@ def render_comment_list(comment_list: List[Comment], output_filename: str = 'hel
and Character values that manually assign a given user to be portrayed \
by a specific character. Any users who do not have a character \
assigned to them via this dictionary will have one assigned at random.
:param bool adult_mode: The video may contain adult themes and the engine should
take this into consideration. Example: When "True" Pearl won't appear on videos since she's a kid
"""
ensure_assets_are_available()
try:
Expand All @@ -44,7 +46,7 @@ def render_comment_list(comment_list: List[Comment], output_filename: str = 'hel
counter = Counter()
for comment in comment_list:
counter.update({comment.effective_user_id: 1})
characters = get_characters(counter, assigned_characters=assigned_characters)
characters = get_characters(counter, assigned_characters=assigned_characters, adult_mode=adult_mode)

# Construct the information about the sequence of "shots" in
# the finished video (e.g. the text spoken and which character
Expand Down
6 changes: 4 additions & 2 deletions objection_engine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def ensure_assets_are_available():
file.write(response.content)


def get_characters(common: Counter, assigned_characters: dict = None):
def get_characters(common: Counter, assigned_characters: dict = None, adult_mode: bool = False):
users_to_characters = {} if assigned_characters is None else assigned_characters.copy()
most_common = [t[0] for t in common.most_common()]
all_rnd_characters = [
Expand All @@ -42,7 +42,6 @@ def get_characters(common: Counter, assigned_characters: dict = None):
Character.KARMA,
Character.PAYNE,
Character.MAGGEY,
Character.PEARL,
Character.LOTTA,
Character.GUMSHOE,
Character.GROSSBERG,
Expand All @@ -54,6 +53,9 @@ def get_characters(common: Counter, assigned_characters: dict = None):
Character.REDD,
]

if not adult_mode:
all_rnd_characters.append(Character.PEARL)

# Confirm that all of the assigned characters are valid.
all_characters = all_rnd_characters + [Character.PHOENIX, Character.EDGEWORTH]
for character in users_to_characters.values():
Expand Down

0 comments on commit be2136a

Please sign in to comment.