Files
boys_streaming/app/utils.py
T
2026-05-03 16:48:18 +01:00

46 lines
1.2 KiB
Python

import logging
import os
from pathlib import Path
from dotenv import load_dotenv
load_dotenv()
# Path configuration
BASE_DIR = Path(__file__).resolve().parent.parent
CONFIG_DIR = Path(os.getenv("CONFIG_DIR", BASE_DIR / "config"))
VIDEOS_DIR = Path(os.getenv("VIDEOS_DIR", BASE_DIR / "videos"))
THUMBNAILS_DIR = CONFIG_DIR / "thumbnails"
# Ensure directories exist
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
THUMBNAILS_DIR.mkdir(parents=True, exist_ok=True)
VIDEOS_DIR.mkdir(parents=True, exist_ok=True)
# Logging configuration
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
handlers=[
logging.StreamHandler(),
logging.FileHandler(CONFIG_DIR / "app.log")
]
)
def get_logger(name: str):
return logging.getLogger(name)
def get_host_ip():
"""Returns the host IP to be used for Chromecast.
In host networking mode, we can use a socket to find the primary interface IP."""
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
# doesn't even have to be reachable
s.connect(('10.255.255.255', 1))
IP = s.getsockname()[0]
except Exception:
IP = '127.0.0.1'
finally:
s.close()
return IP