Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert badge image to rgba in-memory, also chunk out the stacktrace #576

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions charts/agimus/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: v2
name: agimus
description: A helm chart for a discord bot that also runs a mysql db
type: application
version: v2.12.8
appVersion: v2.12.8
version: v2.12.11
appVersion: v2.12.11
21 changes: 19 additions & 2 deletions tasks/wrapped_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

from utils.thread_utils import to_thread

import io
import textwrap
from moviepy import *
from moviepy.video.fx.FadeIn import FadeIn
from moviepy.video.fx.FadeOut import FadeOut
from moviepy.video.fx.Resize import Resize


wrapped_year = datetime.utcnow().year - 1

def wrapped_generation_task(bot):
Expand Down Expand Up @@ -45,6 +48,11 @@ async def wrapped_generation():
stacktrace = traceback.format_exc()
error_message = str(e)
await maintainer_user.send(f"Error processing Wrapped video for {user.display_name}:")
# Split the stacktrace into chunks of 1994 characters
stacktrace_chunks = textwrap.wrap(stacktrace, width=1994)

for chunk in stacktrace_chunks:
await maintainer_user.send(f"```{chunk}```")
await maintainer_user.send(f"```{stacktrace}```")
await db_update_wrapped_job_status(job['job_id'], 'error', error_message=error_message)

Expand Down Expand Up @@ -311,8 +319,17 @@ def _generate_wrapped_mp4(user_discord_id, user_display_name, wrapped_data):
if not os.path.exists(rarest_badge_filepath):
raise FileNotFoundError(f"Rarest Badge file not found at {rarest_badge_filepath}")

rarest_badge_image = ImageClip(rarest_badge_filepath)
rarest_badge_image = ImageClip(rarest_badge_filepath)
rarest_badge_image = Image.open(io.BytesIO(rarest_badge_filepath))

# Convert to RGBA in memory
rarest_badge_image = rarest_badge_image.convert("RGBA")

# Convert the PIL image to a format MoviePy can use
rarest_badge_image_buffer = io.BytesIO()
rarest_badge_image.save(rarest_badge_image_buffer, format="PNG")
rarest_badge_image_buffer.seek(0)

rarest_badge_image = ImageClip(rarest_badge_image_buffer, format="PNG")

if rarest_badge_image:
rarest_badge_image = rarest_badge_image.with_effects([Resize(width=500)])
Expand Down
Loading