update code structure and get session on each query
All checks were successful
Build Docker Image / build (push) Successful in 12m54s

This commit is contained in:
ksyasuda
2025-02-09 20:20:10 -08:00
parent 410a7c92d9
commit af0d958b89
14 changed files with 234 additions and 234 deletions

27
app/mpv.py Normal file
View File

@@ -0,0 +1,27 @@
import socket
import time
import logging
from app.config import Config
SOCKET_RETRY_DELAY = 5
MAX_RETRIES = 10
def send_to_mpv(command):
attempts = 0
while attempts < MAX_RETRIES:
try:
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client_socket:
client_socket.connect(Config.MPV_SOCKET)
client_socket.sendall(command.encode("utf-8"))
logging.info("Command sent to mpv successfully.")
return True
except socket.error as e:
attempts += 1
logging.error(
f"Failed to connect to socket (attempt {attempts}/{MAX_RETRIES}): {e}. Retrying in {SOCKET_RETRY_DELAY} seconds..."
)
time.sleep(SOCKET_RETRY_DELAY)
logging.error(f"Exceeded maximum retries ({MAX_RETRIES}). Ignoring the request.")
return False