diff --git a/anicli/cli/player.py b/anicli/cli/player.py index 3cc3c30..a41fc1c 100644 --- a/anicli/cli/player.py +++ b/anicli/cli/player.py @@ -189,17 +189,24 @@ def play(self, video: "Video", title: Optional[str] = None, player: Optional[str subprocess.Popen(cmd, shell=True).wait() -def run_video(video: "Video", app_cfg: "Config", title: Optional[str] = None): +def run_video(thumbnail, name, episode, video: "Video", app_cfg: "Config", title: Optional[str] = None,): if app_cfg.USE_FFMPEG_ROUTE: if app_cfg.PLAYER == "mpv": + proc1 = subprocess.Popen(['python', 'anicli/rich_presence.py', "--name", name, "--episode", episode, "--episode_max", "255","--thumbnail", thumbnail]) FFMPEGRouter(app_cfg).play(video, title, player=app_cfg.PLAYER, title_arg='--title="{}"') + return proc1.kill() elif app_cfg.PLAYER in ("vlc", "cvlc"): + proc1 = subprocess.Popen(['python', 'anicli/rich_presence.py', "--name", name, "--episode", episode, "--episode_max", "255","--thumbnail", thumbnail]) FFMPEGRouter(app_cfg).play(video, title, player=app_cfg.PLAYER, title_arg='--meta-title "{}"') - return + return proc1.kill() elif app_cfg.PLAYER == "mpv": - return MpvPlayer(app_cfg).play(video, title) + proc1 = subprocess.Popen(['python', 'anicli/rich_presence.py', "--name", name, "--episode", episode, "--episode_max", "255", "--thumbnail", thumbnail]) + MpvPlayer(app_cfg).play(video, title) + return proc1.kill() elif app_cfg.PLAYER == "vlc": - return VLCPlayer(app_cfg).play(video, title) + proc1 = subprocess.Popen(['python', 'anicli/rich_presence.py', "--name", name, "--episode", episode, "--episode_max", "255","--thumbnail", thumbnail]) + VLCPlayer(app_cfg).play(video, title) + return proc1.kill() def run_m3u_playlist(videos: List["Video"], names: List[str], app_cfg: "Config"): diff --git a/anicli/cli/search.py b/anicli/cli/search.py index 365b5bb..8354b5d 100644 --- a/anicli/cli/search.py +++ b/anicli/cli/search.py @@ -30,6 +30,7 @@ class SearchStates(IntStateGroup): SOURCE_SLICE = 4 VIDEO_SLICE = 5 +chosen_episode = None app = AnicliApp("search") app.register_states(SearchStates) @@ -93,6 +94,8 @@ def choose_episode(): return app.fsm.set(SearchStates.SOURCE_SLICE) else: app.fsm["search"] = {"episode": choice_human_index(episodes, int(choose))} + global chosen_episode + chosen_episode = choose app.fsm.set(SearchStates.SOURCE) @@ -155,7 +158,7 @@ def choose_quality(): anime: BaseAnime = app.fsm["anime"] title = create_title(anime, episode, source) - run_video(video, app.CFG, title) + run_video(str(app.CTX["result"].thumbnail), str(app.CTX["result"]), str(chosen_episode), video, app.CFG, title) return app.fsm.set(SearchStates.EPISODE) diff --git a/anicli/rich_presence.py b/anicli/rich_presence.py new file mode 100644 index 0000000..a51f214 --- /dev/null +++ b/anicli/rich_presence.py @@ -0,0 +1,34 @@ +import argparse +import pypresence.exceptions + +def main(): + parser = argparse.ArgumentParser(description="Rich Presence Script") + + parser.add_argument("-n", "--name", type=str, help="", required=True) + parser.add_argument("-e", "--episode", type=str, help="", required=True) + parser.add_argument("-em", "--episode_max", type=str, help="", required=True) + parser.add_argument("-t", "--thumbnail", type=str, help="", required=True) + + args = parser.parse_args() + + from pypresence import Presence + import time + client_id = "1392818712511385652" + try: + RPC = Presence(client_id) + RPC.connect() + + while True: + RPC.update( + state=str(args.name), + large_image=str(args.thumbnail), + details="Смотрит Аниме", + party_size=[int(args.episode), int(args.episode)], + buttons=[{"label": "Github Repository", "url": "https://github.com"}], + ) + time.sleep(15) # minimum 15 seconds + except pypresence.exceptions.DiscordNotFound: + pass + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 428f1ad..9ae7890 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,6 +25,7 @@ dependencies = [ "anicli-api>=0.7.14", "eggella>=0.1.7", "tqdm>=4.67.1", + "pypresence>=4.3.0" ] [project.optional-dependencies]