How killergerbah/asbplayer works
Project Type and Purpose
• asbplayer is primarily a browser-based PWA plus a browser extension.
• It lets language-learners load and control subtitles on streaming/local video, extract subtitles and media, and create Anki flashcards via AnkiConnect or an optional WebSocket proxy.
Main Components
A. Shared Library (common/)
• Contains hooks, services, UI components, subtitle readers/encoders, utilities.
• Published as an npm workspace, consumed by both client and extension.
B. Client Web App (client/)
• A React + Vite PWA served at https://killergerbah.github.io/asbplayer.
• Offers offline support (service worker), video + subtitle rendering, flashcard UI, settings UI.
C. Browser Extension (extension/)
• Manifest, content scripts (page.ts), background scripts (background.ts), controllers, handlers, services, popup/side-panel UI.
• Injects overlay UIs onto streaming sites, captures media/screenshot/audio, stores settings in chrome.storage, communicates with content scripts via chrome.runtime messaging.
D. Local WebSocket/HTTP Proxy (scripts/web-socket-server/)
• A small Go server that speaks the asbplayer WebSocket protocol and proxies commands to AnkiConnect (HTTP).
• Also exposes CLI scripts for load-subtitles and seek.
E. Localization Pipeline (loc/ + scripts/loc/)
• Crowdin integration, CSV/XLIFF conversion scripts to manage translations.
F. External Services
• AnkiConnect (HTTP API) for card creation/updating.
• Streaming video sites (Netflix, YouTube, etc.) — content scripts detect video elements and subtitle tracks.
• Optional dictionary extensions (Yomitan, VocabSieve) for in-app lookups.
Component Relationships & Data Flows
1. User → Browser Web App
• Drag-and-drop media/subtitles → client renders video, overlays UI.
• WebSocket (or HTTP POST) ↔ Proxy Server → Proxy → AnkiConnect.
2. User → Browser Extension
• Content Script injected into target video page ↔ Background Script (chrome.runtime messaging).
• Content Script ↔ Shared common/services for subtitle parsing, audio capture.
• Background Script → AnkiConnect (HTTP) or WebSocket proxy.
3. Shared Code
• common/ modules imported by both client and extension, ensuring consistency in subtitle parsing, UI components, i18n, etc.
4. Localization
• scripts/loc pipelines pull/push translations to Crowdin, generate JSON under loc/external and loc/untranslated.
5. Media & Subtitles
• Subtitle files are Base64-encoded (in client or extension) before loading.
• PGS parser worker for certain subtitle formats.
• UI components read subtitle collections and control video playback (auto-pause, condensed/fast-forward).
Architectural Patterns & Principles
• Monorepo with Yarn Workspaces for shared code.
• “Controller + Handler” pattern in extension: controllers hook into DOM/events, handlers process messages/commands.
• Pub/Sub via BroadcastChannel and frame-bridge for cross-frame communication.
• Modular, reusable React components for both extension UI and website.
• Extension leverages Chrome extension API (storage, tabs, messaging) as the “backend” within the browser.