Replace resolution tuple with dataclass
This commit is contained in:
@ -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.
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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,
|
||||
)
|
||||
|
@ -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():
|
||||
|
Reference in New Issue
Block a user