diff --git a/microkodi/helpers.py b/microkodi/helpers.py index 639622f..3aa8889 100644 --- a/microkodi/helpers.py +++ b/microkodi/helpers.py @@ -1,6 +1,5 @@ from dataclasses import dataclass from typing import TypeVar, ParamSpec, Callable -from functools import wraps P = ParamSpec("P") T = TypeVar("T") @@ -43,13 +42,6 @@ def seconds_to_kodi_format(seconds: int) -> KodiTime: ) -def find(l: list[T], pred: Callable[[T], bool]) -> T | None: - for i in l: - if pred(i): - return i - return None - - def recursive_dict_merge(base: dict, update: dict) -> dict: unique_keys = set([*base.keys(), *update.keys()]) out = {} diff --git a/microkodi/jsonrpc.py b/microkodi/jsonrpc.py index 20029c3..c23ded8 100644 --- a/microkodi/jsonrpc.py +++ b/microkodi/jsonrpc.py @@ -1,16 +1,17 @@ import json -from typing import Any, Callable -from dataclasses import dataclass +from typing import Any from urllib.parse import urlparse import logging import base64 import sys +import importlib from http.server import BaseHTTPRequestHandler from microkodi.repository import I from microkodi.programs import Program, PlayerInfo from microkodi.helpers import KodiTime, seconds_to_kodi_format, after +from microkodi.config import Config def jsonrpc_response(id: int, payload: dict[str, Any]) -> dict[str, Any]: @@ -193,7 +194,7 @@ class PlayerRpcObject(JsonRpcObject): self.logger.debug( "Trying to import %s to get class %s", module_name, class_name ) - spec = importlib.util.find_spec(module) + spec = importlib.util.find_spec(module_name) module = importlib.util.module_from_spec(spec) sys.modules[module_name] = module spec.loader.exec_module(module) @@ -371,7 +372,7 @@ class JsonRpcHandler(BaseHTTPRequestHandler): auth: str | None = self.headers.get("Authorization") if auth is None: logger.warn( - "Client provided no Authorization header. Method: %s", method + "Client provided no Authorization header. Method: %s", method_name ) self.send_error(401) return @@ -379,14 +380,14 @@ class JsonRpcHandler(BaseHTTPRequestHandler): auth_type, auth_payload = auth.split(" ") if auth_type != "Basic": logger.warn( - "Client provided no Basic authorization. Method: %s", method + "Client provided no Basic authorization. Method: %s", method_name ) self.send_error(401) return credentials = base64.b64decode(auth_payload).decode("utf-8") if credentials != "kodi:1234": logger.warn( - "Rejecting request due to wrong credentials. Method: %s", method + "Rejecting request due to wrong credentials. Method: %s", method_name ) self.send_error(403) return diff --git a/microkodi/main.py b/microkodi/main.py index a39b9f5..ef4f2b3 100644 --- a/microkodi/main.py +++ b/microkodi/main.py @@ -5,7 +5,6 @@ import threading import argparse from pathlib import Path import importlib.util -import time from PySide6.QtGui import QGuiApplication from PySide6.QtQml import QQmlApplicationEngine @@ -51,7 +50,6 @@ def run_kodi_server(): init_method = getattr(module, "init") init_method() - server = HTTPServer httpd = HTTPServer( ( config.host, @@ -71,7 +69,6 @@ def main(): options = parser.parse_args() logging.basicConfig(level=logging.DEBUG if options.debug else logging.INFO) - logger = logging.getLogger("ui") # Load the config config = load_config(options.config) diff --git a/microkodi/programs/mpv.py b/microkodi/programs/mpv.py index d61891d..7b56238 100644 --- a/microkodi/programs/mpv.py +++ b/microkodi/programs/mpv.py @@ -1,8 +1,7 @@ import subprocess from typing import Any, Callable -from urllib.parse import ParseResult, urlunparse, urldefrag, unquote +from urllib.parse import ParseResult, urlunparse import logging -from dataclasses import dataclass import os import json import socket diff --git a/microkodi/programs/vlc.py b/microkodi/programs/vlc.py index f15aea4..159b3b5 100644 --- a/microkodi/programs/vlc.py +++ b/microkodi/programs/vlc.py @@ -160,7 +160,7 @@ class VlcProgram(Program): ) -> str | None: try: req = requests.get( - f"http://127.0.0.1:9090/requests/status.xml", + "http://127.0.0.1:9090/requests/status.xml", auth=("", self._vlc_password), params={ "command": command, diff --git a/microkodi/repository.py b/microkodi/repository.py index d2bd0e1..deca7bb 100644 --- a/microkodi/repository.py +++ b/microkodi/repository.py @@ -14,4 +14,4 @@ class _Repository: return self._data.get(key) -I = _Repository() +I = _Repository() # noqa:E741 diff --git a/microkodi/tv.py b/microkodi/tv.py index 32d2192..9222209 100644 --- a/microkodi/tv.py +++ b/microkodi/tv.py @@ -25,7 +25,7 @@ class TVHandler: try: requests.put(config.tv_power_webhook) self.logger.debug("Triggered webhook to enable power to the TV") - except Exception as ex: + except Exception: self.logger.warn("Failed to enable power to the TV") return config.tv_power_webhook is not None