mirror of
https://github.com/Benexl/FastAnime.git
synced 2025-12-12 15:50:01 -08:00
feat: add syncplay intergration
This commit is contained in:
@@ -141,6 +141,7 @@ signal.signal(signal.SIGINT, handle_exit)
|
||||
@click.option(
|
||||
"--use-mpv-mod/--use-default-player", help="Whether to use python-mpv", type=bool
|
||||
)
|
||||
@click.option("--sync-play", "-sp", help="Use sync play", is_flag=True)
|
||||
@click.pass_context
|
||||
def run_cli(
|
||||
ctx: click.Context,
|
||||
@@ -171,6 +172,7 @@ def run_cli(
|
||||
rofi_theme_confirm,
|
||||
rofi_theme_input,
|
||||
use_mpv_mod,
|
||||
sync_play,
|
||||
):
|
||||
from .config import Config
|
||||
|
||||
@@ -205,6 +207,8 @@ def run_cli(
|
||||
|
||||
install()
|
||||
|
||||
if sync_play:
|
||||
ctx.obj.sync_play = sync_play
|
||||
if provider:
|
||||
ctx.obj.provider = provider
|
||||
if server:
|
||||
|
||||
@@ -207,7 +207,12 @@ def search(config: Config, anime_titles: str, episode_range: str):
|
||||
episode_title = servers[server]["episode_title"]
|
||||
print(f"[purple]Now Playing:[/] {search_result} Episode {episode}")
|
||||
|
||||
run_mpv(link, episode_title)
|
||||
if config.sync_play:
|
||||
from ..utils.syncplay import SyncPlayer
|
||||
|
||||
SyncPlayer(link, episode_title)
|
||||
else:
|
||||
run_mpv(link, episode_title)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
input("Enter to continue")
|
||||
|
||||
@@ -55,6 +55,7 @@ class Config(object):
|
||||
user: [TODO:attribute]
|
||||
"""
|
||||
|
||||
sync_play = False
|
||||
anime_list: list
|
||||
watch_history: dict
|
||||
fastanime_anilist_app_login_url = (
|
||||
|
||||
@@ -113,7 +113,13 @@ def media_player_controls(
|
||||
current_episode_number,
|
||||
):
|
||||
custom_args.extend(args)
|
||||
if config.use_mpv_mod:
|
||||
if config.sync_play:
|
||||
from ..utils.syncplay import SyncPlayer
|
||||
|
||||
stop_time, total_time = SyncPlayer(
|
||||
current_episode_stream_link, selected_server["episode_title"]
|
||||
)
|
||||
elif config.use_mpv_mod:
|
||||
from ..utils.player import player
|
||||
|
||||
mpv = player.create_player(
|
||||
@@ -499,7 +505,13 @@ def provider_anime_episode_servers_menu(
|
||||
current_episode_number,
|
||||
):
|
||||
custom_args.extend(args)
|
||||
if config.use_mpv_mod:
|
||||
if config.sync_play:
|
||||
from ..utils.syncplay import SyncPlayer
|
||||
|
||||
stop_time, total_time = SyncPlayer(
|
||||
current_stream_link, selected_server["episode_title"]
|
||||
)
|
||||
elif config.use_mpv_mod:
|
||||
from ..utils.player import player
|
||||
|
||||
mpv = player.create_player(
|
||||
|
||||
21
fastanime/cli/utils/syncplay.py
Normal file
21
fastanime/cli/utils/syncplay.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
from .tools import exit_app
|
||||
|
||||
|
||||
def SyncPlayer(url: str, anime_title, *args):
|
||||
# TODO: handle m3u8 multi quality streams
|
||||
#
|
||||
# check for SyncPlay
|
||||
SYNCPLAY_EXECUTABLE = shutil.which("syncplay")
|
||||
if not SYNCPLAY_EXECUTABLE:
|
||||
print("Syncplay not found")
|
||||
exit_app(1)
|
||||
return "0", "0"
|
||||
# start SyncPlayer
|
||||
subprocess.run(
|
||||
[SYNCPLAY_EXECUTABLE, url, "--", f"--force-media-title={anime_title}"]
|
||||
)
|
||||
# for compatability
|
||||
return "0", "0"
|
||||
Reference in New Issue
Block a user