This commit is contained in:
PapaTutuWawa 2025-01-12 22:12:53 +01:00
parent fcfe97ad89
commit 5c23c91867
5 changed files with 27 additions and 2 deletions

10
microkodi/cec.py Normal file
View File

@ -0,0 +1,10 @@
import cec
class CECHandler:
def __init__(self):
cec.init()
def power_on_if_needed(self):
tc = cec.Device(cec.CECDEVICE_TV)
if not tc.is_on():
tc.power_on()

View File

@ -37,6 +37,9 @@ class Config:
# The entire configuration file for use in user scripts
options: dict[str, Any]
# Enables the use of CEC
cec: bool
def load_config(config_path: Path | None) -> Config:
if config_path is None:
@ -64,4 +67,5 @@ def load_config(config_path: Path | None) -> Config:
config_data.get("players", {}),
),
options=config_data.get("options", {}),
cec=config_data.get("cec", False),
)

View File

@ -151,6 +151,11 @@ class PlayerRpcObject(JsonRpcObject):
@after(lambda: I.get("DataBridge").set_loading(False))
def open(self, params: dict[str, Any]) -> Any:
# Turn on the TV
config: Config = I.get("Config")
if config.cec:
I.get("CECHandler").power_of_if_needed()
I.get("DataBridge").set_loading(True)
url = urlparse(params["item"]["file"])
@ -161,7 +166,6 @@ class PlayerRpcObject(JsonRpcObject):
url = urlparse(url.query)
# Find out what player class to use
config: Config = I.get("Config")
scheme_configuration = config.players.get(url.scheme)
if scheme_configuration is None:
I.get("DataBridge").notification.emit(f"No player available for {url.scheme}")

View File

@ -13,6 +13,7 @@ from PySide6.QtQml import QQmlApplicationEngine
from microkodi.jsonrpc import JsonRpcHandler, GlobalMethodHandler
from microkodi.ui.bridge import DataBridge
from microkodi.config import Config, load_config
from microkodi.cec import CECHandler
from microkodi.repository import I
@ -23,6 +24,11 @@ def run_kodi_server():
method_handler = GlobalMethodHandler()
I.register("GlobalMethodHandler", method_handler)
# Setup CEC
if config.cec:
I.register("CECHandler", CECHandler())
logger.info("Enabling CEC support")
# Load extra plugins
if config.scripts:
logger.info("Loading scripts...")

View File

@ -4,7 +4,8 @@ version = "0.1.0"
dependencies = [
"pyside6",
"requests",
"yt-dlp"
"yt-dlp",
"cec"
]
[tools.build]