mirror of
https://github.com/Benexl/FastAnime.git
synced 2026-01-06 17:53:40 -08:00
51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
"""
|
|
Player factory and registration logic for FastAnime media players.
|
|
|
|
This module provides a factory for instantiating the correct player implementation based on configuration.
|
|
"""
|
|
|
|
from ...core.config import AppConfig
|
|
from .base import BasePlayer
|
|
|
|
PLAYERS = ["mpv", "vlc", "syncplay"]
|
|
|
|
|
|
class PlayerFactory:
|
|
"""
|
|
Factory for creating player instances based on configuration.
|
|
"""
|
|
|
|
@staticmethod
|
|
def create(config: AppConfig) -> BasePlayer:
|
|
"""
|
|
Create a player instance based on the configured player name.
|
|
|
|
Args:
|
|
config: The full application configuration object.
|
|
|
|
Returns:
|
|
BasePlayer: An instance of a class that inherits from BasePlayer.
|
|
|
|
Raises:
|
|
ValueError: If the player_name is not supported.
|
|
NotImplementedError: If the player is recognized but not yet implemented.
|
|
"""
|
|
player_name = config.stream.player
|
|
|
|
if player_name not in PLAYERS:
|
|
raise ValueError(
|
|
f"Unsupported player: '{player_name}'. Supported players are: {PLAYERS}"
|
|
)
|
|
|
|
if player_name == "mpv":
|
|
from .mpv.player import MpvPlayer
|
|
|
|
return MpvPlayer(config.mpv)
|
|
raise NotImplementedError(
|
|
f"Configuration logic for player '{player_name}' not implemented in factory."
|
|
)
|
|
|
|
|
|
# Alias for convenient player creation
|
|
create_player = PlayerFactory.create
|