How furey/fetchtv works
Project Type and Purpose
• fetchtv is a Node.js-based command-line interface (CLI) tool for discovering a Fetch TV server on the local network and downloading its recordings.
• It is not a web-app or microservice; it’s a single process CLI with network-I/O (UPnP/SSDP discovery + HTTP download) and file-system persistence.
High-Level File/Directory Analysis
– fetchtv.js: the single entrypoint that parses commands, invokes services, and displays or saves results.
– package.json + package-lock.json: defines runtime dependencies (e.g., commander or yargs for CLI parsing, SSDP/UPnP modules, HTTP clients, template engines, logging).
– Dockerfile + .dockerignore: containerizes the CLI for reproducible execution.
– .github/workflows: CI/CD pipelines for publishing to NPM and Docker Hub.
– repomix.config.json: project metadata and packaging.
Key Components
a. User & Shell Layer
• User’s Terminal → invokes fetchtv command
b. Process & CLI Layer
• Node.js Runtime → loads fetchtv.js
• Command Parser (commander/yargs) → identifies sub-commands (info, shows, recordings) and options (–ip, –port, –save, –template, –json, –debug)
c. Application Logic Layer
• Controller/Handler per Command → orchestrates discovery, fetch, filtering, formatting, and saving
• Discovery Service → uses UPnP/SSDP to locate Fetch TV device (or takes IP/port override)
• Fetch Service → issues HTTP requests to the device’s API to list shows/recordings or stream TS files
• Template Engine → formats file paths and names (${show_title}, ${recording_title}, ${ext}, etc.)
d. Persistence & I/O Layer
• Local File System Adapter → writes downloaded media to disk, respects overwrite flags
• Console Output Formatter → plain text or JSON, depending on flags
e. External System
• Fetch TV Server on LAN → UPnP discovery endpoint and HTTP API
f. Deployment & CI/CD
• Docker Build Context → runs the CLI in containers
• GitHub Actions → triggers on push to publish package and Docker image
Relationships and Data Flow
– User → Shell/Node.js process → Command Parser
– Parser → Controllers → Discovery Service → Fetch TV (network)
– Controllers → Fetch Service → Fetch TV (network)
– Fetch Service → File System Adapter → Disk
– Controllers → Console Formatter → Terminal
• Data flows from the Fetch TV server back through services into either the console or files.
Architectural Patterns & Principles
• Single-process, layered CLI architecture
• Separation of concerns: parsing, discovery, fetch, formatting, persistence
• Configurable via flags (injects IP/port, templates, output format)
• Containerized deployment for consistency
Essential Elements
• CLI components (parsers/controllers)
• Network services
• Persistence layers
• External systems