This repository was archived by the owner on May 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
feat(player): add IINA player integration for macOS #203
Open
mlharouna
wants to merge
5
commits into
viu-media:master
Choose a base branch
from
mlharouna:feat/iina-player-integration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6f44047
feat(player): add initial skeleton for IINA player integration
mlharouna 2a8d4f4
feat(player): implement IINA player integration
mlharouna ff5c399
feat(player): improve IINA integration and config handling
mlharouna d399495
add: update README and add doc for iina integration
mlharouna d0a28bf
Merge branch 'viu-media:master' into feat/iina-player-integration
mlharouna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| """ | ||
| IINA player integration for Viu. | ||
|
|
||
| This module provides the IinaPlayer class, | ||
| which implements the BasePlayer interface for the IINA media player. | ||
| """ | ||
|
|
||
| import logging | ||
| import shutil | ||
| import subprocess | ||
| from pathlib import Path | ||
|
|
||
| from ....core.config import IinaConfig | ||
| from ....core.constants import PLATFORM | ||
| from ....core.exceptions import ViuError | ||
| from ....core.patterns import TORRENT_REGEX | ||
| from ....core.utils import detect | ||
| from ..base import BasePlayer | ||
| from ..params import PlayerParams | ||
| from ..types import PlayerResult | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| IINA_APP_EXECUTABLES = ( | ||
| Path("/Applications/IINA.app/Contents/MacOS/iina-cli"), | ||
| Path.home() / "Applications/IINA.app/Contents/MacOS/iina-cli", | ||
| ) | ||
|
|
||
|
|
||
| class IinaPlayer(BasePlayer): | ||
| """ | ||
| IINA player implementation for Viu. | ||
|
|
||
| Provides playback functionality using the IINA media player. | ||
| """ | ||
|
|
||
| def __init__(self, config: IinaConfig): | ||
| """ | ||
| Initialize the IINA player with the given configuration. | ||
|
|
||
| Args: | ||
| config: IinaConfig object containing IINA-specific configuration. | ||
| """ | ||
| self.config = config | ||
| self.executable = self._find_executable() | ||
|
|
||
| def play(self, params: PlayerParams) -> PlayerResult: | ||
| """ | ||
| Play the given media URL using IINA player. | ||
|
|
||
| Args: | ||
| params: PlayerParams object containing playback parameters. | ||
|
|
||
| Returns: | ||
| PlayerResult: Information about the playback session. | ||
|
|
||
| Raises: | ||
| ViuError: If IINA is not supported on the current platform, | ||
| if syncplay is requested, if URL is a torrent, | ||
| or if IINA executable is not found. | ||
| """ | ||
| if PLATFORM != "darwin": | ||
| raise ViuError("IINA is only supported on macOS.") | ||
|
|
||
| if params.syncplay: | ||
| raise ViuError("Viu's IINA integration does not support Syncplay.") | ||
|
|
||
| if TORRENT_REGEX.search(params.url): | ||
| raise ViuError("Unable to play torrents with IINA.") | ||
|
|
||
| if not self.executable: | ||
| raise ViuError( | ||
| "IINA executable not found. Install IINA or expose `iina-cli` in PATH." | ||
| ) | ||
|
|
||
| args = self._build_iina_command(params) | ||
|
|
||
| subprocess.run(args, check=False, env=detect.get_clean_env()) | ||
| return PlayerResult(episode=params.episode) | ||
|
|
||
| def play_with_ipc(self, params: PlayerParams, socket_path: str): | ||
| raise NotImplementedError("play_with_ipc is not implemented for IINA player.") | ||
|
|
||
| def _find_executable(self) -> str | None: | ||
| """ | ||
| Find the IINA executable path. | ||
|
|
||
| First checks if 'iina-cli' is in PATH, then checks common macOS application paths. | ||
|
|
||
| Returns: | ||
| str | None: The path to the IINA executable, or None if not found. | ||
| """ | ||
| executable = shutil.which("iina-cli") | ||
| if executable: | ||
| return executable | ||
|
|
||
| for app_executable in IINA_APP_EXECUTABLES: | ||
| if app_executable.exists(): | ||
| return str(app_executable) | ||
|
|
||
| return None | ||
|
|
||
| def _build_iina_command(self, params: PlayerParams) -> list[str]: | ||
| """ | ||
| Build the command line arguments for launching IINA. | ||
|
|
||
| Args: | ||
| params: PlayerParams object containing playback parameters. | ||
|
|
||
| Returns: | ||
| list[str]: The command line arguments for IINA. | ||
| """ | ||
| assert self.executable is not None | ||
| args = [self.executable] | ||
| args.append(params.url) | ||
|
|
||
| if mpv_args := self._create_iina_mpv_options(params): | ||
| args.append("--") | ||
| args.extend(mpv_args) | ||
|
|
||
| logger.debug("Starting IINA with args: %s", args) | ||
| return args | ||
|
|
||
| def _create_iina_mpv_options(self, params: PlayerParams) -> list[str]: | ||
| """ | ||
| Create MPV options for IINA based on the player parameters. | ||
|
|
||
| Args: | ||
| params: PlayerParams object containing playback parameters. | ||
|
|
||
| Returns: | ||
| list[str]: List of MPV command line options. | ||
| """ | ||
| mpv_args = [] | ||
|
|
||
| if params.title: | ||
| mpv_args.append(f"--force-media-title={params.title}") | ||
| if params.subtitles: | ||
| for sub in params.subtitles: | ||
| mpv_args.append(f"--sub-file={sub}") | ||
| if params.start_time: | ||
| mpv_args.append(f"--start={params.start_time}") | ||
| if params.headers: | ||
| header_str = ",".join(f"{k}:{v}" for k, v in params.headers.items()) | ||
| mpv_args.append(f"--http-header-fields={header_str}") | ||
| if self.config.args: | ||
| mpv_args.extend( | ||
| arg.strip() for arg in self.config.args.split(",") if arg.strip() | ||
| ) | ||
|
|
||
| return mpv_args | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| from ....core.constants import APP_ASCII_ART | ||
|
|
||
| print(APP_ASCII_ART) | ||
| url = input("Enter the url you would like to stream: ") | ||
| iina = IinaPlayer(IinaConfig()) | ||
| player_result = iina.play(PlayerParams(episode="", query="", url=url, title="")) | ||
| print(player_result) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |||||
| from ...core.config import AppConfig | ||||||
| from .base import BasePlayer | ||||||
|
|
||||||
| PLAYERS = ["mpv", "vlc", "syncplay"] | ||||||
| PLAYERS = ["mpv", "vlc", "iina", "syncplay"] | ||||||
|
||||||
| PLAYERS = ["mpv", "vlc", "iina", "syncplay"] | |
| PLAYERS = ["mpv", "vlc", "iina"] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
play_with_ipcoverride doesn’t match theBasePlayerinterface: it’s missing the-> subprocess.Popenreturn annotation and currently has an untyped signature. This can trigger pyright’s incompatible override checks and is inconsistent withVlcPlayer/MpvPlayer. Update the method signature to match the base class (and keep raisingNotImplementedErrorif IPC isn’t supported).