Skip to content

player

Iina(player_path, extra_args=[], play_callback=None)

Bases: SubProcessPlayerBase

The iina subprocess player class.

For detailed documentation about the functions and arguments have a look at the base class.

Parameters:

Name Type Description Default
player_path str
required
extra_args List[str]
[]
play_callback Optional[PlayCallback]
None
Source code in api/src/anipy_api/player/players/iina.py
def __init__(
    self,
    player_path: str,
    extra_args: List[str] = [],
    play_callback: Optional[PlayCallback] = None,
):
    """__init__ of Iina

    Args:
        player_path:
        extra_args:
        play_callback:
    """
    self.player_args_template = [
        "{stream_url}",
        "--mpv-force-media-title={media_title}",
        "--sub-files={subtitles}",
        "--referrer={referrer}",
        *extra_args,
    ]

    super().__init__(
        player_path=player_path, extra_args=extra_args, play_callback=play_callback
    )

Mpv(player_path, extra_args=[], play_callback=None)

Bases: SubProcessPlayerBase

The mpv subprocess player class. For a controllable mpv look here.

Info

Not only mpv works but mpv forks like mpv.net also work.

For detailed documentation about the functions and arguments have a look at the base class.

Parameters:

Name Type Description Default
player_path str
required
extra_args List[str]
[]
play_callback Optional[PlayCallback]
None
Source code in api/src/anipy_api/player/players/mpv.py
def __init__(
    self,
    player_path: str,
    extra_args: List[str] = [],
    play_callback: Optional[PlayCallback] = None,
):
    """__init__ of Mpv

    Args:
        player_path:
        extra_args:
        play_callback:
    """
    self.player_args_template = [
        "{stream_url}",
        "--force-media-title={media_title}",
        "--sub-files={subtitles}",
        "--force-window=immediate",
        "--referrer={referrer}",
        *extra_args,
    ]

    super().__init__(
        player_path=player_path, extra_args=extra_args, play_callback=play_callback
    )

MpvControllable(play_callback=None, **mpv_args)

Bases: PlayerBase

This player can be controlled and it also does not close if the media is changed, the window stays open until kill_player is called. You need libmpv for this, check the python-mpv project's requirements to know where to get it.

For detailed documentation about the functions have a look at the base class.

If you want to use the extra features of the controllable player look here for documentation (or use your LSP), the python-mpv mpv instance lives in the mpv attribute.

Attributes:

Name Type Description
mpv

The python-mpv mpv instance

Parameters:

Name Type Description Default
play_callback Optional[PlayCallback]

Callback called upon starting to play a title with play_title

None
**mpv_args Optional[Any]

Arguments passed to the MPV instance check the python-mpv repo or check the official list of arguments. There are some default arguments set, if you specify any arguments here, all the defaults will be discarded and this will be used instead.

{}
Source code in api/src/anipy_api/player/players/mpv_control.py
def __init__(
    self, play_callback: Optional[PlayCallback] = None, **mpv_args: Optional[Any]
):
    """__init__ of MpvControllable

    Args:
        play_callback: Callback called upon starting to play a title with `play_title`
        **mpv_args: Arguments passed to the MPV instance check the [python-mpv repo](https://github.com/jaseg/python-mpv?tab=readme-ov-file#usage)
            or check the [official list of arguments](https://mpv.io/manual/master/#properties). There are some default arguments set, if you specify
            any arguments here, all the defaults will be discarded and this will be used instead.
    """
    super().__init__(play_callback=play_callback)

    # I know this is a crime, but pytohn-mpv loads the so/dll on import and this will break all the stuff for people that do not have that.
    from mpv import MPV

    if len(mpv_args) <= 1:
        mpv_args = {
            "input_default_bindings": True,
            "input_vo_keyboard": True,
            "force_window": "immediate",
            "title": "MPV - Receiving Links from anipy-cli",
            "osc": True,
        }

    self.mpv = MPV(**mpv_args)

Syncplay(player_path, extra_args=[], play_callback=None)

Bases: SubProcessPlayerBase

The syncplay subprocess player class.

For detailed documentation about the functions and arguments have a look at the base class.

Parameters:

Name Type Description Default
player_path str
required
extra_args List[str]
[]
play_callback Optional[PlayCallback]
None
Source code in api/src/anipy_api/player/players/syncplay.py
def __init__(
    self,
    player_path: str,
    extra_args: List[str] = [],
    play_callback: Optional[PlayCallback] = None,
):
    """__init__ of Syncplay

    Args:
        player_path:
        extra_args:
        play_callback:
    """
    self.player_args_template = [
        "--",
        "--meta-title='{media_title}'",
        "--sub-files={subtitles}",
        "--referrer={referrer}" "{stream_url}",
        *extra_args,
    ]

    super().__init__(
        player_path=player_path, extra_args=extra_args, play_callback=play_callback
    )

Vlc(player_path, extra_args=[], play_callback=None)

Bases: SubProcessPlayerBase

The vlc subprocess player class.

For detailed documentation about the functions and arguments have a look at the base class.

Parameters:

Name Type Description Default
player_path str
required
extra_args List[str]
[]
play_callback Optional[PlayCallback]
None
Source code in api/src/anipy_api/player/players/vlc.py
def __init__(
    self,
    player_path: str,
    extra_args: List[str] = [],
    play_callback: Optional[PlayCallback] = None,
):
    """__init__ of Vlc

    Args:
        player_path:
        extra_args:
        play_callback:
    """
    self.player_args_template = [
        "--meta-title='{media_title}'",
        "--http-referrer={referrer}",
        "--input-slave={subtitles}",
        "{stream_url}",
        *extra_args,
    ]

    super().__init__(
        player_path=player_path, extra_args=extra_args, play_callback=play_callback
    )

get_player(player, extra_args=[], play_callback=None)

Get a fitting player class based on a player path.

Parameters:

Name Type Description Default
player Path

Path to the player

required
extra_args List[str]

Extra arguments to pass to players that support it

[]
play_callback Optional[PlayCallback]

Callback called upon starting to play a title with play_title

None

Raises:

Type Description
PlayerError

If the player is not found

Returns:

Type Description
PlayerBase

The player class

Source code in api/src/anipy_api/player/player.py
def get_player(
    player: Path,
    extra_args: List[str] = [],
    play_callback: Optional["PlayCallback"] = None,
) -> "PlayerBase":
    """Get a fitting player class based on a player path.

    Args:
        player: Path to the player
        extra_args: Extra arguments to pass to players that support it
        play_callback: Callback called upon starting to play a title with `play_title`

    Raises:
        PlayerError: If the player is not found

    Returns:
        The player class
    """
    if Path(player.name).stem == "mpv-controlled":
        return MpvControllable(play_callback=play_callback)

    player_dict = {
        "mpv": Mpv,
        "mpvnet": Mpv,
        "vlc": Vlc,
        "syncplay": Syncplay,
        "iina": Iina,
    }

    player_class = player_dict.get(Path(player.name).stem, None)

    if player_class:
        return player_class(
            str(player), extra_args=extra_args, play_callback=play_callback
        )
    else:
        raise PlayerError(f"Specified player `{player}` is unknown")

list_players()

List all available players. Note that is not really useful as not all of them have the same __init__ signature, better use get_player or directly import the players you want to use.

Yields:

Type Description
Type[PlayerBase]

Player classes (that still need to be initialized)

Source code in api/src/anipy_api/player/player.py
def list_players() -> Iterator[Type["PlayerBase"]]:
    """List all available players. Note that is not really useful as not all of them have the same `__init__` signature, better use [get_player][anipy_api.player.player.get_player] or directly import the players you want to use.

    Yields:
        Player classes (that still need to be initialized)
    """
    for p in __all__:
        yield globals()[p]