diff --git a/discord_embed/main.py b/discord_embed/main.py index 2188c33..6bbd481 100644 --- a/discord_embed/main.py +++ b/discord_embed/main.py @@ -61,10 +61,6 @@ async def upload_file(file: UploadFile = File(...)) -> Dict[str, str]: async def remove_illegal_chars(filename: str) -> str: """Remove illegal characters from the filename. - Space is replaced with a dot. - "*, ", <, >, △, 「, 」, {, }, |, ^, ;, /, ?, :, @, &, =, +, $, ,," are removed. - - Args: filename: The filename to remove illegal characters from. diff --git a/discord_embed/video.py b/discord_embed/video.py index 7ca8d8b..e6d2b4b 100644 --- a/discord_embed/video.py +++ b/discord_embed/video.py @@ -1,11 +1,24 @@ """Stuff that has to do with videos.""" -import ffmpeg import sys +from dataclasses import dataclass + +import ffmpeg from discord_embed import settings -def video_resolution(path_to_video: str) -> tuple[int, int]: +@dataclass +class Resolution: + """Video resolution. + + height: Height of video. + width: Width of video. + """ + height: int + width: int + + +def video_resolution(path_to_video: str) -> Resolution: """Find video resolution. Args: @@ -23,7 +36,7 @@ def video_resolution(path_to_video: str) -> tuple[int, int]: width = int(video_stream["width"]) height = int(video_stream["height"]) - return height, width + return Resolution(height, width) def make_thumbnail(path_video: str, file_filename: str) -> str: diff --git a/discord_embed/video_file_upload.py b/discord_embed/video_file_upload.py index a5053d2..0c64f1b 100644 --- a/discord_embed/video_file_upload.py +++ b/discord_embed/video_file_upload.py @@ -8,7 +8,7 @@ from fastapi import UploadFile from discord_embed import settings from discord_embed.generate_html import generate_html_for_videos -from discord_embed.video import make_thumbnail, video_resolution +from discord_embed.video import Resolution, make_thumbnail, video_resolution from discord_embed.webhook import send_webhook @@ -32,7 +32,7 @@ def save_to_disk(file: UploadFile) -> VideoFile: file: Our uploaded file. Returns: - VideoFile object with filename and location. + VideoFile object with the filename and location. """ # Create the folder where we should save the files folder_video = os.path.join(settings.upload_folder, "video") @@ -62,12 +62,12 @@ async def do_things(file: UploadFile) -> Dict[str, str]: video_file: VideoFile = save_to_disk(file) file_url = f"{settings.serve_domain}/video/{video_file.filename}" - height, width = video_resolution(video_file.location) + res: Resolution = video_resolution(video_file.location) screenshot_url = make_thumbnail(video_file.location, video_file.filename) html_url = generate_html_for_videos( url=file_url, - width=width, - height=height, + width=res.width, + height=res.height, screenshot=screenshot_url, filename=video_file.filename, ) diff --git a/tests/test_video.py b/tests/test_video.py index c7f8f66..ee8c32e 100644 --- a/tests/test_video.py +++ b/tests/test_video.py @@ -2,14 +2,14 @@ import imghdr import os from discord_embed import settings -from discord_embed.video import make_thumbnail, video_resolution +from discord_embed.video import Resolution, make_thumbnail, video_resolution TEST_FILE = "tests/test.mp4" def test_video_resolution(): """Test video_resolution() works.""" - assert video_resolution(TEST_FILE) == (422, 422) + assert video_resolution(TEST_FILE) == Resolution(height=422, width=422) def test_make_thumbnail():