28 lines
883 B
Python
28 lines
883 B
Python
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
|