How mathenz/goffy works
Main Components
• CLI/Entry Point: Represented by main.go, which handles command-line argument parsing and serves as the application’s entry point.
• Spotify URL Handler: With functionality likely encapsulated in spotify.go, this component parses Spotify URLs and determines whether a playlist, album, track, or multiple tracks (from a text file) are requested.
• YouTube Download Module: Found in youtube.go, this part is responsible for locating and downloading the actual music content from YouTube.
• Download Orchestration: The downloader.go and template.go files manage the download process. They likely coordinate between parsing, fetching media from YouTube, formatting outputs, and integrating metadata.
• Utility Functions: utils.go contains supportive routines and helper functions that facilitate processing across the modules.
• Configuration & Release Configurations: The presence of .goreleaser.yaml (along with go.mod and go.sum) indicates build/release procedures important for distribution, though these are more peripheral to runtime architecture.
Relationships and Interactions
• User Input flows into the CLI component (main.go) where the command-line arguments (like -p, -a, -t, -f, -m, and -d options) are parsed.
• The appropriate download flow is then triggered:
• For a track/album/playlist, the downloader logic (downloader.go) orchestrates the process.
• It calls the YouTube Download Module (youtube.go) to query for matching content on YouTube.
• Downloaded content is then processed (possibly involving metadata addition via FFmpeg) and saved:
• Either directly to a local directory (using the provided -d flag) or...
• Temporarily stored and compressed for mobile device transfer (triggered by the -m flag), with a temporary HTTP server hosting the files on port 8080.
• Utility functions (from utils.go) support parsing, error-handling, logging, or any repeated tasks throughout these components.
Architectural Patterns and Technologies
• Modular design: The project cleanly separates concerns by dividing tasks among distinct modules (CLI, URL parsing, downloading, utility functions).
• Command-line interface design: The tool’s design emphasizes handling several command-line options that dictate control flow.
• External dependencies: The README notes the need for FFmpeg (for metadata processing), indicating an external service integration.
• Lightweight, no-official API approach: Despite dealing with Spotify URLs, the project avoids official APIs, instead using its own “unofficial API” logic.
• Temporary Web Server: An interesting design element is the mobile mode, which temporarily serves the downloaded content via an HTTP endpoint to facilitate mobile device access.