A Go utility that identifies top Last.fm albums missing from your Subsonic library.
My reasoning: I’ve been shifting away from Spotify because the platform feels increasingly cluttered with AI-generated content, pays artists poorly, and aligns with business practices I no longer wish to support. Instead, I’ve returned to purchasing downloadable music. Thanks to my past scrobbling history, I can now identify gaps in my offline collection—essentially pinpointing which albums I streamed on Spotify but haven’t yet acquired. Put simply: it’s a way to systematically decide, “What should I buy next based on my listening habits?”
- Last.fm Integration: Fetches your top 500 albums from the last year
- Subsonic Compatibility: Checks against your Subsonic music library
- Smart Recommendations: Identifies up to 5 missing albums
- Retry Logic: Robust error handling with 3 retry attempts
- Error Diagnostics: Comprehensive error categorization and reporting
- Modular Architecture: Clean separation between HTTP clients and API logic
- Progress Indicators: Visual feedback with spinners and progress bars
- Comprehensive Testing: 73.9% test coverage with unit and integration tests
Requires Go 1.21+
git clone https://github.com/syeo66/album2buy.git
cd album2buy
go build -o album2buy *.goInstall dotenvx for environment management
curl -fsS https://dotenvx.sh | shCreate .env file:
LASTFM_API_KEY=your_api_key_here
LASTFM_USER=your_lastfm_username
SUBSONIC_SERVER=https://your.subsonic.server
SUBSONIC_USER=your_subsonic_user
SUBSONIC_PASSWORD=your_subsonic_password# Basic usage
./run.sh # Uses dotenvx to load environment variables
# Verbose mode for detailed error reporting
VERBOSE=true ./run.shSample output:
RECOMMENDED ALBUMS
================================================================================
1. Dream Theater - Parasomnia (24-bit HD audio)
Last.fm URL: https://www.last.fm/music/Dream+Theater/Parasomnia+(24-bit+HD+audio)
--------------------------------------------------------------------------------
2. Chris Haigh - Massive Rocktronica - Gothic Storm
Last.fm URL: https://www.last.fm/music/Chris+Haigh/Massive+Rocktronica+-+Gothic+Storm
--------------------------------------------------------------------------------
3. Jeremy Soule - The Elder Scrolls V: Skyrim (Original Game Soundtrack)
Last.fm URL: https://www.last.fm/music/Jeremy+Soule/The+Elder+Scrolls+V:+Skyrim+(Original+Game+Soundtrack)
--------------------------------------------------------------------------------
4. Poppy - New Way Out
Last.fm URL: https://www.last.fm/music/Poppy/New+Way+Out
--------------------------------------------------------------------------------
5. Blue Stahli - Obsidian
Last.fm URL: https://www.last.fm/music/Blue+Stahli/Obsidian
--------------------------------------------------------------------------------
| Variable | Description |
|---|---|
LASTFM_API_KEY |
Last.fm API key |
LASTFM_USER |
Last.fm username |
SUBSONIC_SERVER |
Subsonic server URL (include protocol) |
SUBSONIC_USER |
Subsonic account username |
SUBSONIC_PASSWORD |
Subsonic account password |
IGNORE_FILE |
Path to a list of ignored Last.fm URL's (optional) |
VERBOSE |
Set to "true" for detailed error reporting (optional) |
INSECURE_SKIP_VERIFY |
Set to "true" to skip TLS verification (optional) |
The application is built with a modular architecture for maintainability and testability:
HTTPClient: Centralized HTTP client with configurable retry logic and TLS settingsLastFMClient: Dedicated client for Last.fm API operationsSubsonicClient: Dedicated client for Subsonic API operations with authenticationProgressIndicator: Visual feedback system with spinners and progress barsErrorStats: Error tracking and categorization system for diagnostics
- Separation of Concerns: Each client handles its specific API responsibilities
- Error Handling: Consistent retry logic and detailed error messages
- Testability: Modular design enables easy unit testing and mocking
- Security: Secure credential handling and optional TLS verification
- Go 1.21+
- dotenvx (
go install github.com/dotenvx/dotenvx@latest) - Valid Last.fm API credentials
- Subsonic server (1.16.1+ recommended)
main.go # Main application logic (580 lines)
main_test.go # Unit tests for all components
integration_test.go # End-to-end integration tests
├── HTTPClient # Core HTTP client with retry logic
├── LastFMClient # Last.fm API operations
├── SubsonicClient # Subsonic API operations
├── ProgressIndicator # Visual progress feedback
├── ErrorStats # Error tracking and categorization
└── Utility functions # String cleaning, configuration, etc.
The project includes comprehensive test coverage with both unit and integration tests:
# Run all tests
go test ./...
# Run tests with verbose output
go test -v ./...
# Run tests with coverage report
go test -cover ./...
# Generate detailed coverage report
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
# Run specific test files
go test -run TestHTTPClient
go test -run TestLastFMClient
go test -run TestSubsonicClient
go test -run TestCategorizeError- 73.9% overall coverage across all components
- 36 test cases covering critical functionality
- Unit tests for individual components (HTTPClient, LastFMClient, SubsonicClient)
- Integration tests for end-to-end workflows
- Mock servers for external API testing
- Environment variable testing for configuration
main_test.go: Unit tests for all major componentsintegration_test.go: End-to-end workflow tests
go build -o album2buy *.go # Build application
gofmt -w . # Format code
go doc -all . # View code documentation
go vet ./... # Static analysisAll major types and functions include comprehensive Go documentation comments following standard conventions. Use go doc to explore the API documentation locally.
For detailed testing information, see TESTING.md.
MIT © Red Ochsenbein 2025