[PR #445] [CLOSED] feat: Add genre fetching and file metadata embedding via MusicBrainz API #1292

Closed
opened 2026-03-01 17:35:00 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/afkarxyz/SpotiFLAC/pull/445
Author: @Nox-code
Created: 2/3/2026
Status: Closed

Base: mainHead: feature/genre-fetching


📝 Commits (2)

  • af19d65 feat: Add genre fetching and file metadata embedding via MusicBrainz API
  • 5886ad3 Delete GEMINI.md

📊 Changes

14 files changed (+315 additions, -36 deletions)

View changed files

📝 app.go (+11 -9)
📝 backend/amazon.go (+4 -3)
📝 backend/metadata.go (+14 -0)
📝 backend/qobuz.go (+2 -1)
📝 backend/spotfetch.go (+34 -0)
📝 backend/spotify_metadata.go (+190 -8)
📝 backend/tidal.go (+6 -4)
📝 frontend/src/App.tsx (+1 -0)
📝 frontend/src/components/SettingsPage.tsx (+12 -0)
📝 frontend/src/hooks/useDownload.ts (+23 -7)
📝 frontend/src/hooks/useMetadata.ts (+5 -2)
📝 frontend/src/lib/api.ts (+2 -1)
📝 frontend/src/lib/settings.ts (+9 -1)
📝 frontend/src/types/api.ts (+2 -0)

📄 Description

Description

This PR adds the ability to automatically fetch and embed genre metadata for downloaded tracks. Since Spotify's internal API does not reliably provide genre information for individual tracks, this implementation integrates with the MusicBrainz API to perform accurate lookups.

Key Changes

Genre Fetching (MusicBrainz Integration)

  • Implemented a new fetchGenreFromMusicBrainz function in the backend.
  • Logic prioritizes finding tags/genres in the following order: Recording (Track) > Release Group (Album) > Artist.
  • Uses a combined search query (Artist - Track) for better accuracy.
  • Respects MusicBrainz API guidelines with appropriate user-agent and request spacing.

Metadata Embedding

  • Updated backend/metadata.go to support embedding the Genre tag across all supported formats:
    • FLAC: Uses standard GENRE Vorbis comment.
    • MP3: Uses ID3v2 TCON frame.
    • M4A: Uses genre atom via FFmpeg.
  • Added ExtractFullMetadataFromFile support for the genre field to ensure consistency.

User Settings

  • Added a "Embed Genre" toggle in the Settings page (defaults to false).

Codebase Updates

  • Updated DownloadRequest and TrackMetadata structures in both backend and frontend to carry the genre field.
  • Updated all downloader implementations (Tidal, Amazon, Qobuz) to accept and pass the genre to the metadata embedder.
  • Fixed fallback logic in FilterTrack to ensure artist IDs are correctly extracted when primary extraction is unavailable.

Testing

  • Verified that enabling the setting correctly triggers the MusicBrainz lookup.
  • Confirmed that fetched genres are successfully written to the file tags (visible in Windows Explorer/music players).
  • Verified that disabling the setting skips the lookup.
  • Ensured existing functionality (downloads, other metadata) remains unaffected.
  • Confirmed no regression in application stability by maintaining existing context patterns.
  • Verified that the Audio Converter preserves the genre tag.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/afkarxyz/SpotiFLAC/pull/445 **Author:** [@Nox-code](https://github.com/Nox-code) **Created:** 2/3/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feature/genre-fetching` --- ### 📝 Commits (2) - [`af19d65`](https://github.com/afkarxyz/SpotiFLAC/commit/af19d65ec8b5930107e87a4ed1ed2771f93b4dbf) feat: Add genre fetching and file metadata embedding via MusicBrainz API - [`5886ad3`](https://github.com/afkarxyz/SpotiFLAC/commit/5886ad3d51a6dd7a534cae645ef9ba3168c692c1) Delete GEMINI.md ### 📊 Changes **14 files changed** (+315 additions, -36 deletions) <details> <summary>View changed files</summary> 📝 `app.go` (+11 -9) 📝 `backend/amazon.go` (+4 -3) 📝 `backend/metadata.go` (+14 -0) 📝 `backend/qobuz.go` (+2 -1) 📝 `backend/spotfetch.go` (+34 -0) 📝 `backend/spotify_metadata.go` (+190 -8) 📝 `backend/tidal.go` (+6 -4) 📝 `frontend/src/App.tsx` (+1 -0) 📝 `frontend/src/components/SettingsPage.tsx` (+12 -0) 📝 `frontend/src/hooks/useDownload.ts` (+23 -7) 📝 `frontend/src/hooks/useMetadata.ts` (+5 -2) 📝 `frontend/src/lib/api.ts` (+2 -1) 📝 `frontend/src/lib/settings.ts` (+9 -1) 📝 `frontend/src/types/api.ts` (+2 -0) </details> ### 📄 Description ## Description This PR adds the ability to automatically fetch and embed genre metadata for downloaded tracks. Since Spotify's internal API does not reliably provide genre information for individual tracks, this implementation integrates with the **MusicBrainz API** to perform accurate lookups. ## Key Changes ### Genre Fetching (MusicBrainz Integration) - Implemented a new `fetchGenreFromMusicBrainz` function in the backend. - Logic prioritizes finding tags/genres in the following order: **Recording** (Track) > **Release Group** (Album) > **Artist**. - Uses a combined search query (`Artist - Track`) for better accuracy. - Respects MusicBrainz API guidelines with appropriate user-agent and request spacing. ### Metadata Embedding - Updated `backend/metadata.go` to support embedding the `Genre` tag across all supported formats: - **FLAC**: Uses standard `GENRE` Vorbis comment. - **MP3**: Uses ID3v2 `TCON` frame. - **M4A**: Uses `genre` atom via FFmpeg. - Added `ExtractFullMetadataFromFile` support for the genre field to ensure consistency. ### User Settings - Added a **"Embed Genre"** toggle in the Settings page (defaults to false). ### Codebase Updates - Updated `DownloadRequest` and `TrackMetadata` structures in both backend and frontend to carry the `genre` field. - Updated all downloader implementations (`Tidal`, `Amazon`, `Qobuz`) to accept and pass the genre to the metadata embedder. - Fixed fallback logic in `FilterTrack` to ensure artist IDs are correctly extracted when primary extraction is unavailable. ## Testing - Verified that enabling the setting correctly triggers the MusicBrainz lookup. - Confirmed that fetched genres are successfully written to the file tags (visible in Windows Explorer/music players). - Verified that disabling the setting skips the lookup. - Ensured existing functionality (downloads, other metadata) remains unaffected. - Confirmed no regression in application stability by maintaining existing context patterns. - Verified that the Audio Converter preserves the genre tag. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-01 17:35:00 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/SpotiFLAC#1292
No description provided.