How norinorin/anime_rpc works
Main Components
• Core Application Module: Represented by the anime_rpc directory, which contains the core modules:
– __main__.py: The entry point that bootstraps the application.
– cli.py: Handles command-line interactions and possibly initial configuration.
– config.py and formatting.py: Manage the reading and formatting of the configuration file (rpc.config).
– asyncio_helper.py and monkey_patch.py: Provide asynchronous utilities and runtime modifications.
– presence.py: Manages the communication with Discord (sending rich presence updates).
– scraper.py: Likely responsible for extracting metadata “on the fly” from media sources.
– states.py and ux.py: Maintain application state and user experience logic.
• Pollers: Located in the anime_rpc/pollers directory:
– base_poller.py: Defines a generic interface or common logic.
– mpc_poller.py and mpv_poller.py: Specialized modules to poll data from MPC and MPV media players.
– (Extended support for other platforms like bilibili.tv is hinted in the README and via the extension modules.)
• Web Server: The webserver.py module sets up a local server for providing a web interface or API endpoints.
• Browser Extension: The extension folder contains files (HTML, CSS, JS, and manifest) aimed at integrating with browsers for additional functionalities or notifications.
• Additional Scripts:
– launcher.py: Likely a helper or alternative entry point for starting the application.
– hook-anime_rpc.monkey_patch.py: Provides an entry for applying monkey patches on the fly, possibly for integration purposes.
Out Relationships and Interactions
• Entry Points: Start with the CLI or the Python module (__main__.py) that initializes the system.
• Configuration Flow: The config module reads a “rpc.config” file (or its proxy using example.rpc.config) from the media folder. This configuration is used by downstream components to determine behavior (e.g., what format to display, which poller to use).
• Polling Mechanism:
– Pollers (e.g., mpv and mpc pollers) continuously monitor their respective media players or sites, using distinctive protocols like native IPC sockets (for mpv) or web APIs (for MPC).
• Data Processing and State Management: Modules like scraper, states, and formatting process the polled data and prepare it in the expected format.
• Communication Path to Discord: The presence module takes the processed data and sends it to Discord as Rich Presence updates.
• Web Server & Browser Extension:
– The webserver acts as an interface or an intermediary to provide a REST API (or similar) for external tools.
– The browser extension (found under the extension folder) acts as another integration point that may interact with Anime RPC (especially for sites like bilibili.tv).
Architectural Patterns or Design Principles
• Extensibility: The presence of multiple poller modules and a browser extension indicates a plug-in style architecture where new integrations can be added without altering the core system drastically.