From cea8d60099c26bf20fbac7cdf661b9963b754254 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= <tlovinator@gmail.com>
Date: Tue, 25 May 2021 23:32:01 +0200
Subject: [PATCH] Use environment variable for domain

---
 main.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/main.py b/main.py
index 54ec367..7fc6da6 100644
--- a/main.py
+++ b/main.py
@@ -1,6 +1,8 @@
 import json
+import os
 import shlex
 import subprocess
+import sys
 from datetime import datetime
 
 from flask import Flask, flash, redirect, render_template, request, url_for
@@ -8,9 +10,13 @@ from werkzeug.utils import secure_filename
 
 app = Flask(__name__)
 app.config["UPLOAD_FOLDER"] = "Uploads"
+try:
+    domain = os.environ["DOMAIN"]  # https://killyoy.lovinator.space/
+except KeyError:
+    sys.exit("Environment variable 'domanin' is missing!")
+print(f"{domain=}")
 
 
-# function to find the resolution of the input video file
 def find_video_resolution(path_to_video):
     cmd = "ffprobe -v quiet -print_format json -show_streams "
     args = shlex.split(cmd)
@@ -31,7 +37,7 @@ def generate_html(
 ):
     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">
@@ -42,9 +48,10 @@ def generate_html(
         <meta name="twitter:image" content="{video_screenshot}">
         <meta http-equiv="refresh" content="0;url={video_url}">
     </head>
+    </html>
     """
 
-    html_url = f"https://killyoy.lovinator.space/{video_filename}"
+    html_url = f"{domain}{video_filename}"
     video_filename += ".html"
 
     with open(f"Uploads/{video_filename}", "w") as file:
@@ -58,7 +65,7 @@ def get_first_frame(path_video, file_filename):
 
     subprocess.check_output(args).decode("utf-8")
 
-    return f"https://killyoy.lovinator.space/{file_filename}.jpg"
+    return f"{domain}{file_filename}.jpg"
 
 
 @app.route("/")
@@ -95,7 +102,7 @@ def upload_file():
             screenshot_url = get_first_frame(filepath, filename)
             print(f"{screenshot_url=}")
 
-            video_url = f"https://killyoy.lovinator.space/v/{filename}"
+            video_url = f"{domain}v/{filename}"
             print(f"{video_url=}")
 
             html_url = generate_html(