How himandrobot/stremio-translate-subtitle-by-geanpn works
Main Components
• Stremio Integration / Add-on Server: Files such as index.js, connection.js, manifest.json, and package.json suggest that this is the entry point and configuration for integrating with Stremio via stremio-addon-sdk.
• Subtitle Management: Modules like subtitles.js and processfiles.js handle the parsing, chunking, and reassembling of subtitle files. The system also checks the filesystem cache to avoid redundant translations.
• Translation Providers & Handlers: Files such as translateProvider.js, languages.js, and the JSON files under langs indicate support for multiple translation providers and language configuration.
• Queue System: The queues/translationQueue.js file (using the better-queue library as noted in the README) is responsible for managing asynchronous translation tasks, retries, and provider rotation.
• External API Integrations: modules like opensubtitles.js manage communication with external subtitle services (i.e., OpenSubtitlesV3), while translation logic wraps various translation APIs (and web scraping methods for Google Translate Free).
• Configuration & Environment: The use of environment variables and the manifest.json file ensure that the add-on is configurable (e.g., server PORT, BASE_URL) and compatible with Stremio’s add-on architecture.
Architectural Patterns and Principles
• Modular Separation: Each major function – fetching, queuing, processing, and translating – is clearly separated into files and modules.
• Asynchronous Processing: The queue system (better-queue) signifies an asynchronous, decoupled architecture to handle translation tasks in parallel.
• Fallback & Resilience: The translation provider selection with fallback and rotation indicates robustness against API failures or rate limits.
• Caching: The filesystem-based caching mechanism ensures improved performance and reduced redundant API calls.