Refactor project into two standalone components
Split monorepo into separate units for future independent repositories: - media-server/: Standalone FastAPI server with own README, requirements, config example, and CLAUDE.md - haos-integration/: HACS-ready Home Assistant integration with hacs.json, own README, and CLAUDE.md Both components now have their own .gitignore files and can be easily extracted into separate repositories. Also adds custom icon support for scripts configuration. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
75
media-server/media_server/services/__init__.py
Normal file
75
media-server/media_server/services/__init__.py
Normal file
@@ -0,0 +1,75 @@
|
||||
"""Media controller services."""
|
||||
|
||||
import os
|
||||
import platform
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .media_controller import MediaController
|
||||
|
||||
_controller_instance: "MediaController | None" = None
|
||||
|
||||
|
||||
def _is_android() -> bool:
|
||||
"""Check if running on Android (e.g., via Termux)."""
|
||||
# Check for Android-specific paths and environment
|
||||
android_indicators = [
|
||||
Path("/system/build.prop").exists(),
|
||||
Path("/data/data/com.termux").exists(),
|
||||
"ANDROID_ROOT" in os.environ,
|
||||
"TERMUX_VERSION" in os.environ,
|
||||
]
|
||||
return any(android_indicators)
|
||||
|
||||
|
||||
def get_media_controller() -> "MediaController":
|
||||
"""Get the platform-specific media controller instance.
|
||||
|
||||
Returns:
|
||||
The media controller for the current platform
|
||||
|
||||
Raises:
|
||||
RuntimeError: If the platform is not supported
|
||||
"""
|
||||
global _controller_instance
|
||||
|
||||
if _controller_instance is not None:
|
||||
return _controller_instance
|
||||
|
||||
system = platform.system()
|
||||
|
||||
if system == "Windows":
|
||||
from .windows_media import WindowsMediaController
|
||||
|
||||
_controller_instance = WindowsMediaController()
|
||||
elif system == "Linux":
|
||||
# Check if running on Android
|
||||
if _is_android():
|
||||
from .android_media import AndroidMediaController
|
||||
|
||||
_controller_instance = AndroidMediaController()
|
||||
else:
|
||||
from .linux_media import LinuxMediaController
|
||||
|
||||
_controller_instance = LinuxMediaController()
|
||||
elif system == "Darwin": # macOS
|
||||
from .macos_media import MacOSMediaController
|
||||
|
||||
_controller_instance = MacOSMediaController()
|
||||
else:
|
||||
raise RuntimeError(f"Unsupported platform: {system}")
|
||||
|
||||
return _controller_instance
|
||||
|
||||
|
||||
def get_current_album_art() -> bytes | None:
|
||||
"""Get the current album art bytes (Windows only for now)."""
|
||||
system = platform.system()
|
||||
if system == "Windows":
|
||||
from .windows_media import get_current_album_art as _get_art
|
||||
return _get_art()
|
||||
return None
|
||||
|
||||
|
||||
__all__ = ["get_media_controller", "get_current_album_art"]
|
||||
Reference in New Issue
Block a user