Compare commits

..

No commits in common. "959a1d01d69d07f5109a52ce17ef9f0756885c75" and "f0a84c1f41064c666330cb5429d02432b97ce305" have entirely different histories.

6 changed files with 18 additions and 29 deletions

View File

@ -2,14 +2,16 @@
FROM python:3.10-slim FROM python:3.10-slim
# Set environment variables for the MPV socket and server host/port # Set environment variables for the MPV socket and server host/port
ENV LISTEN_ADDRESS="0.0.0.0" \ ENV MPV_SOCKET="/tmp/mpvsocket" \
LISTEN_PORT=8080 HOST_NAME="0.0.0.0" \
PORT_NUMBER=8080 \
LOGLEVEL="info"
# Set the working directory in the container # Set the working directory in the container
WORKDIR /app WORKDIR /app
# Copy the current directory contents into the container at /app # Copy the current directory contents into the container at /app
COPY server.py requirements.txt /app/ COPY server.py /app/server.py
# Install any needed packages specified in requirements.txt # Install any needed packages specified in requirements.txt
# If there are no external dependencies, you can skip this step # If there are no external dependencies, you can skip this step
@ -18,8 +20,7 @@ COPY server.py requirements.txt /app/
# Make port 8080 available to the world outside this container # Make port 8080 available to the world outside this container
EXPOSE "${PORT_NUMBER}" EXPOSE "${PORT_NUMBER}"
RUN pip3 install --no-cache-dir -r requirements.txt RUN pip3 install --no-cache-dir Flask mysql-connector-python
# Run server.py when the container launches # Run server.py when the container launches
# CMD ["python3", "server.py", "--host", "${LISTEN_ADDRESS}", "--port", "${LISTEN_PORT}", "--input-ipc-server", "${MPV_SOCKET}"] CMD ["python3", "server.py", "--host", "${HOST_NAME}", "--port", "${PORT_NUMBER}", "--input-ipc-server", "${MPV_SOCKET}"]
CMD gunicorn --bind "${LISTEN_ADDRESS}":"${LISTEN_PORT}" server:app

View File

@ -1 +1 @@
0.0.2 0.0.1

View File

@ -1,6 +1,7 @@
LISTEN_ADDRESS=0.0.0.0 # Lisen on all interfaces IP=0.0.0.0 # Lisen on all interfaces
LISTEN_PORT=8080 # Internal port number PORT_NUMBER=8080 # Internal port number
MPV_SOCKET=/tmp/mpvsocket # Path to mpv socket MPV_SOCKET=/tmp/mpvsocket # Path to mpv socket
LOGLEVEL=info
# MySQL connection info # MySQL connection info
MYSQL_HOST=localhost MYSQL_HOST=localhost
@ -9,4 +10,3 @@ MYSQL_PASSWORD=SecretPassword
MYSQL_DATABASE=mpv MYSQL_DATABASE=mpv
MYSQL_PORT=3306 MYSQL_PORT=3306
LOGLEVEL=info

View File

@ -8,8 +8,8 @@ WorkingDirectory=<PATH_TO_PYTHON_SCRIPT>
ExecStart=<PATH_TO_PYTHON> <PATH_TO_PYTHON_SCRIPT> ExecStart=<PATH_TO_PYTHON> <PATH_TO_PYTHON_SCRIPT>
Restart=on-failure Restart=on-failure
Environment="MPV_SOCKET=/tmp/mpvsocket" Environment="MPV_SOCKET=/tmp/mpvsocket"
Environment="LISTEN_ADDRESS=0.0.0.0" Environment="HOST_NAME=0.0.0.0"
Environment="LISTEN_PORT=42069" Environment="PORT_NUMBER=42069"
Environment="MYSQL_HOST=http://localhost" Environment="MYSQL_HOST=http://localhost"
Environment="MYSQL_USER=mpvuser" Environment="MYSQL_USER=mpvuser"
Environment="MYSQL_PASSWORD=SecretPassword" Environment="MYSQL_PASSWORD=SecretPassword"

View File

@ -1,10 +1,8 @@
blinker==1.8.2 blinker==1.8.2
click==8.1.7 click==8.1.7
Flask==3.0.3 Flask==3.0.3
gunicorn==23.0.0
itsdangerous==2.2.0 itsdangerous==2.2.0
Jinja2==3.1.4 Jinja2==3.1.4
MarkupSafe==2.1.5 MarkupSafe==2.1.5
mysql-connector-python==9.0.0 mysql-connector-python==9.0.0
packaging==24.1
Werkzeug==3.0.4 Werkzeug==3.0.4

View File

@ -15,17 +15,6 @@ logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
) )
# Ensure Flask doesn't duplicate log messages
log = logging.getLogger("werkzeug")
log.setLevel(logging.ERROR)
# Flask app
app = Flask(__name__)
# Flask logging configuration to use the same logger as the rest of the app
app.logger.handlers = logging.getLogger().handlers
app.logger.setLevel(logging.getLogger().level)
SOCKET_RETRY_DELAY = 5 # Time in seconds between retries to connect to the socket SOCKET_RETRY_DELAY = 5 # Time in seconds between retries to connect to the socket
MAX_RETRIES = 10 # Maximum number of retries to connect to the socket MAX_RETRIES = 10 # Maximum number of retries to connect to the socket
@ -40,7 +29,6 @@ MYSQL_USER: str = os.getenv("MYSQL_USER", "your_username")
MYSQL_PASSWORD: str = os.getenv("MYSQL_PASSWORD", "your_password") MYSQL_PASSWORD: str = os.getenv("MYSQL_PASSWORD", "your_password")
MYSQL_PORT: int = int(os.getenv("MYSQL_PORT", "3306")) MYSQL_PORT: int = int(os.getenv("MYSQL_PORT", "3306"))
LOGLEVEL = os.getenv("LOGLEVEL", "INFO").strip().upper() LOGLEVEL = os.getenv("LOGLEVEL", "INFO").strip().upper()
if LOGLEVEL == "DEBUG": if LOGLEVEL == "DEBUG":
logging.getLogger().setLevel(logging.DEBUG) logging.getLogger().setLevel(logging.DEBUG)
elif LOGLEVEL == "WARNING": elif LOGLEVEL == "WARNING":
@ -51,6 +39,9 @@ else:
logging.getLogger().setLevel(logging.INFO) logging.getLogger().setLevel(logging.INFO)
app = Flask(__name__)
def get_mysql_connection(): def get_mysql_connection():
"""Get a MySQL database connection.""" """Get a MySQL database connection."""
try: try:
@ -129,11 +120,10 @@ def add_video():
video_name: str = data.get("video_name") video_name: str = data.get("video_name")
channel_url: str = data.get("channel_url") channel_url: str = data.get("channel_url")
channel_name: str = data.get("channel_name") channel_name: str = data.get("channel_name")
watch_date: date = date.today().strftime("%Y-%m-%d") watch_date: date = data.get("watch_date")
if video_url and video_name and channel_url and channel_name and watch_date: if video_url and video_name and channel_url and channel_name and watch_date:
logging.debug(f"Received data: {data}") logging.info(f"Received data: {data}")
logging.debug(f"Watch date: {watch_date}")
# Insert the data into the MySQL database # Insert the data into the MySQL database
connection = get_mysql_connection() connection = get_mysql_connection()