mirror of
https://github.com/Benexl/FastAnime.git
synced 2026-02-04 19:11:55 -08:00
feat: mpv player syncplay
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user