Move everything to own file

This commit is contained in:
2022-04-13 02:36:39 +02:00
parent a2af09075f
commit d85f23740d
6 changed files with 236 additions and 192 deletions

View File

@ -0,0 +1,59 @@
"""Generate the HTML that makes this program useful.
This is what we will send to other people on Discord.
You can remove the .html with your web server so the link will look normal.
For example, with nginx, you can do this(note the $uri.html):
location / {
try_files $uri $uri/ $uri.html;
}
"""
import os
from datetime import datetime
from discord_embed import settings
def generate_html_for_videos(
url: str,
width: int,
height: int,
screenshot: str,
filename: str,
) -> str:
"""Generate HTML for video files.
Args:
url (str): URL for the video. This is accessible from the browser.
width (int): This is the width of the video.
height (int): This is the height of the video.
screenshot (str): URL for screenshot.
filename (str): Original video filename.
Returns:
str: Returns HTML for video.
"""
video_html = f"""
<!DOCTYPE html>
<html>
<!-- Generated at {datetime.now().strftime('%Y-%m-%d %H:%M:%S')} -->
<head>
<meta property="og:type" content="video.other">
<meta property="twitter:player" content="{url}">
<meta property="og:video:type" content="text/html">
<meta property="og:video:width" content="{width}">
<meta property="og:video:height" content="{height}">
<meta name="twitter:image" content="{screenshot}">
<meta http-equiv="refresh" content="0;url={url}">
</head>
</html>
"""
html_url = os.path.join(settings.domain, filename)
# Take the filename and append .html to it.
filename += ".html"
file_path = os.path.join(settings.upload_folder, filename)
with open(file_path, "w", encoding="utf-8") as f:
f.write(video_html)
return html_url