diff --git a/fastanime/libs/players/mpv/player.py b/fastanime/libs/players/mpv/player.py index d243284..2f8abaf 100644 --- a/fastanime/libs/players/mpv/player.py +++ b/fastanime/libs/players/mpv/player.py @@ -24,6 +24,8 @@ class MpvPlayer(BasePlayer): def play(self, params): if TORRENT_REGEX.match(params.url) and detect.is_running_in_termux(): raise FastAnimeError("Unable to play torrents on termux") + elif params.syncplay and detect.is_running_in_termux(): + raise FastAnimeError("Unable to play torrents on termux") elif detect.is_running_in_termux(): return self._play_on_mobile(params) else: @@ -69,6 +71,8 @@ class MpvPlayer(BasePlayer): if TORRENT_REGEX.search(params.url): return self._stream_on_desktop_with_webtorrent_cli(params) + elif params.syncplay: + return self._stream_on_desktop_with_syncplay(params) elif self.config.use_python_mpv: return self._stream_on_desktop_with_python_mpv(params) else: @@ -120,6 +124,21 @@ class MpvPlayer(BasePlayer): subprocess.run(args) return PlayerResult() + # TODO: Get people with real friends to do this lol + def _stream_on_desktop_with_syncplay(self, params: PlayerParams) -> PlayerResult: + SYNCPLAY_EXECUTABLE = shutil.which("syncplay") + if not SYNCPLAY_EXECUTABLE: + raise FastAnimeError( + "Please install syncplay to be able to stream with your friends" + ) + args = [SYNCPLAY_EXECUTABLE, params.url] + if mpv_args := self._create_mpv_cli_options(params): + args.append("--") + args.extend(mpv_args) + subprocess.run(args) + + return PlayerResult() + def _create_mpv_cli_options(self, params: PlayerParams) -> list[str]: mpv_args = [] if params.headers: diff --git a/fastanime/libs/players/params.py b/fastanime/libs/players/params.py index 9b69af1..2952721 100644 --- a/fastanime/libs/players/params.py +++ b/fastanime/libs/players/params.py @@ -11,6 +11,7 @@ class Subtitle: class PlayerParams: url: str title: str + syncplay: bool = False subtitles: list[Subtitle] | None = None headers: dict[str, str] | None = None start_time: str | None = None