Add native support for multiple genres per album/track#6169
Add native support for multiple genres per album/track#6169dunkla wants to merge 24 commits intobeetbox:masterfrom
Conversation
There was a problem hiding this comment.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `beetsplug/beatport.py:236-242` </location>
<code_context>
if "genres" in data:
- self.genres = [str(x["name"]) for x in data["genres"]]
+ genre_list = [str(x["name"]) for x in data["genres"]]
+ if beets.config["multi_value_genres"]:
+ self.genres = genre_list
+ else:
+ # Even when disabled, populate with first genre for consistency
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Populating genres with all values may introduce duplicates if Beatport returns repeated genre names.
Consider removing duplicate genre names from genre_list before assigning it to self.genres.
```suggestion
if "genres" in data:
genre_list = [str(x["name"]) for x in data["genres"]]
# Remove duplicates while preserving order
genre_list = list(dict.fromkeys(genre_list))
if beets.config["multi_value_genres"]:
self.genres = genre_list
else:
# Even when disabled, populate with first genre for consistency
self.genres = [genre_list[0]] if genre_list else []
```
</issue_to_address>
### Comment 2
<location> `test/test_autotag.py:554-563` </location>
<code_context>
+ assert item.genres == ["Rock", "Alternative", "Indie"]
+ assert item.genre == "Rock, Alternative, Indie"
+
+ def test_sync_genres_priority_list_over_string(self):
+ """When both genre and genres exist, genres list takes priority."""
+ config["multi_value_genres"] = True
+
+ item = Item(genre="Jazz", genres=["Rock", "Alternative"])
+ correct_list_fields(item)
+
+ # genres list should take priority and update genre string
+ assert item.genres == ["Rock", "Alternative"]
+ assert item.genre == "Rock, Alternative"
+
+ def test_sync_genres_none_values(self):
</code_context>
<issue_to_address>
**suggestion (testing):** Consider testing the scenario where both genre and genres are set but have conflicting values and multi_value_genres is disabled.
Please add a test for the case where multi_value_genres is False and genre and genres have different values, to verify which field takes precedence and how synchronization is handled.
</issue_to_address>
### Comment 3
<location> `test/test_autotag.py:581-590` </location>
<code_context>
+ assert item.genre == "Jazz"
+ assert item.genres == ["Jazz"]
+
+ def test_sync_genres_disabled_empty_genres(self):
+ """Handle disabled config with empty genres list."""
+ config["multi_value_genres"] = False
+
+ item = Item(genres=[])
+ correct_list_fields(item)
+
+ # Should handle empty list without errors
+ assert item.genres == []
+ assert item.genre == ""
</code_context>
<issue_to_address>
**suggestion (testing):** Consider adding a test for genres=None when multi_value_genres is False.
Testing genres=None with multi_value_genres=False will help verify correct fallback behavior and error handling.
```suggestion
def test_sync_genres_disabled_empty_genres(self):
"""Handle disabled config with empty genres list."""
config["multi_value_genres"] = False
item = Item(genres=[])
correct_list_fields(item)
# Should handle empty list without errors
assert item.genres == []
assert item.genre == ""
def test_sync_genres_disabled_none_genres(self):
"""Handle disabled config with genres=None."""
config["multi_value_genres"] = False
item = Item(genres=None)
correct_list_fields(item)
# Should handle None without errors
assert item.genres == []
assert item.genre == ""
```
</issue_to_address>
### Comment 4
<location> `test/test_library.py:690-693` </location>
<code_context>
self._assert_dest(b"/base/not_played")
def test_first(self):
- self.i.genres = "Pop; Rock; Classical Crossover"
- self._setf("%first{$genres}")
+ self.i.genre = "Pop; Rock; Classical Crossover"
+ self._setf("%first{$genre}")
self._assert_dest(b"/base/Pop")
</code_context>
<issue_to_address>
**suggestion (testing):** Tests in test_library.py should be updated to cover the new genres field.
Add tests that assign genres as a list and check template functions like %first to ensure correct handling of the new field.
```suggestion
def test_first(self):
self.i.genre = "Pop; Rock; Classical Crossover"
self._setf("%first{$genre}")
self._assert_dest(b"/base/Pop")
def test_first_genres_list(self):
self.i.genres = ["Pop", "Rock", "Classical Crossover"]
self._setf("%first{$genres}")
self._assert_dest(b"/base/Pop")
def test_first_genres_list_skip(self):
self.i.genres = ["Pop", "Rock", "Classical Crossover"]
self._setf("%first{$genres,1,2}")
self._assert_dest(b"/base/Classical Crossover")
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #6169 +/- ##
==========================================
- Coverage 68.71% 68.61% -0.11%
==========================================
Files 138 138
Lines 18558 18605 +47
Branches 3062 3073 +11
==========================================
+ Hits 12753 12765 +12
- Misses 5154 5186 +32
- Partials 651 654 +3
🚀 New features to boost your workflow:
|
e347151 to
f6ee49a
Compare
snejus
left a comment
There was a problem hiding this comment.
Hi, thanks for your contribution!
The main bottleneck that we have with a multi-value genres field is that mediafile does not currently support it. We need to add it, and make it behave the same way as, say, artists field does. I can take care of this.
Otherwise, I reckon we should simplify this change by migrating to using genres field for good.
|
Hi @dunkla many many thanks for this contribution! It lately crosses my mind daily that I should probably finally start working on multi-genre support before continuing with my lastgenre masterplan ;-), so thanks again for your motivation to drive this forward. When I skimmed through it yesterday my first thoughts were that no user and no plugin should have to worry about population both Also @snejus do you think this PR should wait for #6165 to be finished or at least should be based on it (to let @dunkla continue workin on it). |
|
Also thanks for offering to implement the |
|
As soon as decisions have been made i'm more than happy to rebase and restructre the approach as wished. |
|
Good news, guys! Apparently, Additionally, I think, we should think of the best way to migrate joined genres from the existing |
Simplify multi-genre implementation based on maintainer feedback (PR beetbox#6169). Changes: - Remove multi_value_genres and genre_separator config options - Replace complex sync_genre_fields() with ensure_first_value('genre', 'genres') - Update all plugins (Beatport, MusicBrainz, LastGenre) to always write genres as lists - Add automatic migration for comma/semicolon/slash-separated genre strings - Add 'beet migrate genres' command for explicit batch migration with --pretend flag - Update all tests to reflect simplified approach (44 tests passing) - Update documentation Implementation aligns with maintainer vision of always using multi-value genres internally with automatic backward-compatible sync to the genre field via ensure_first_value(), eliminating configuration complexity. Migration strategy avoids problems from beetbox#5540: - Automatic lazy migration on item access (no reimport/mbsync needed) - Optional batch migration command for user control - No endless rewrite loops due to proper field synchronization
f6ee49a to
4e2f78d
Compare
Summary of ChangesAddressed PR Comments1. Simplify the architecture (snejus's main comment)
2. Update Beatport plugin (snejus's comment)
3. Update MusicBrainz plugin (snejus's comment)
4. Update LastGenre plugin (snejus's comment)
Addressed IssuesMigration concerns (referenced in PR discussion, relates to #5540)
Other ChangesTests
Documentation
Code Quality
Implementation PhilosophyThe simplified implementation aligns with the maintainer's vision:
all again with immense help of claude code |
4e2f78d to
cfa9f1a
Compare
Simplify multi-genre implementation based on maintainer feedback (PR beetbox#6169). Changes: - Remove multi_value_genres and genre_separator config options - Replace complex sync_genre_fields() with ensure_first_value('genre', 'genres') - Update all plugins (Beatport, MusicBrainz, LastGenre) to always write genres as lists - Add automatic migration for comma/semicolon/slash-separated genre strings - Add 'beet migrate genres' command for explicit batch migration with --pretend flag - Update all tests to reflect simplified approach (44 tests passing) - Update documentation Implementation aligns with maintainer vision of always using multi-value genres internally with automatic backward-compatible sync to the genre field via ensure_first_value(), eliminating configuration complexity. Migration strategy avoids problems from beetbox#5540: - Automatic lazy migration on item access (no reimport/mbsync needed) - Optional batch migration command for user control - No endless rewrite loops due to proper field synchronization
cfa9f1a to
32e47d2
Compare
Simplify multi-genre implementation based on maintainer feedback (PR beetbox#6169). Changes: - Remove multi_value_genres and genre_separator config options - Replace complex sync_genre_fields() with ensure_first_value('genre', 'genres') - Update all plugins (Beatport, MusicBrainz, LastGenre) to always write genres as lists - Add automatic migration for comma/semicolon/slash-separated genre strings - Add 'beet migrate genres' command for explicit batch migration with --pretend flag - Update all tests to reflect simplified approach (44 tests passing) - Update documentation Implementation aligns with maintainer vision of always using multi-value genres internally with automatic backward-compatible sync to the genre field via ensure_first_value(), eliminating configuration complexity. Migration strategy avoids problems from beetbox#5540: - Automatic lazy migration on item access (no reimport/mbsync needed) - Optional batch migration command for user control - No endless rewrite loops due to proper field synchronization
32e47d2 to
22cdda7
Compare
Simplify multi-genre implementation based on maintainer feedback (PR beetbox#6169). Changes: - Remove multi_value_genres and genre_separator config options - Replace complex sync_genre_fields() with ensure_first_value('genre', 'genres') - Update all plugins (Beatport, MusicBrainz, LastGenre) to always write genres as lists - Add automatic migration for comma/semicolon/slash-separated genre strings - Add 'beet migrate genres' command for explicit batch migration with --pretend flag - Update all tests to reflect simplified approach (44 tests passing) - Update documentation Implementation aligns with maintainer vision of always using multi-value genres internally with automatic backward-compatible sync to the genre field via ensure_first_value(), eliminating configuration complexity. Migration strategy avoids problems from beetbox#5540: - Automatic lazy migration on item access (no reimport/mbsync needed) - Optional batch migration command for user control - No endless rewrite loops due to proper field synchronization
fa98904 to
c3f8eac
Compare
Simplify multi-genre implementation based on maintainer feedback (PR beetbox#6169). Changes: - Remove multi_value_genres and genre_separator config options - Replace complex sync_genre_fields() with ensure_first_value('genre', 'genres') - Update all plugins (Beatport, MusicBrainz, LastGenre) to always write genres as lists - Add automatic migration for comma/semicolon/slash-separated genre strings - Add 'beet migrate genres' command for explicit batch migration with --pretend flag - Update all tests to reflect simplified approach (44 tests passing) - Update documentation Implementation aligns with maintainer vision of always using multi-value genres internally with automatic backward-compatible sync to the genre field via ensure_first_value(), eliminating configuration complexity. Migration strategy avoids problems from beetbox#5540: - Automatic lazy migration on item access (no reimport/mbsync needed) - Optional batch migration command for user control - No endless rewrite loops due to proper field synchronization
I love the amount of detail here @dunkla. I will review this shortly! |
snejus
left a comment
There was a problem hiding this comment.
See comments. Main points:
- We want to deprecate
genrefield and convert it togenresinsideInfo.__init__, and emit a deprecation warning - We should perform the migration immediately after the new
genresfield is created.
Addresses PR beetbox#6169 review comments at lines 414 and 587. Changes: - Simplified test setup logic (lines 584-590) - removed complicated conditional separator handling - Removed "separator" config parameter from test cases 9 and 10 - Removed obsolete test case 11 that tested deprecated separator behavior - Renumbered remaining test cases accordingly - Updated test case 9 comment to reflect actual test purpose The test logic is now much simpler and matches the source code complexity, with no conditional logic needed in tests.
Addresses PR beetbox#6169 review comment about separator configuration. Changes: - Updated "Multiple Genres" section in lastgenre docs to explain that genres are now stored as a list and written as individual tags - Added deprecation notice for the separator config option (deprecated in version 2.6) with explanation that it has no effect - Added changelog entry documenting the separator deprecation The separator option is now deprecated as genres are stored natively as lists in the genres field and written to files as separate genre tags rather than being joined with a separator. Note: Migration logic to handle existing separator-joined genre strings will be implemented as part of the database migration changes.
Addresses PR beetbox#6169 review comment about deprecating the genre parameter. Changes: - Added deprecation warning when 'genre' parameter is used in Info.__init__() - Warning is shown regardless of whether 'genres' is also provided, ensuring plugins are notified that genre will be removed in the future - When genres is not provided, automatically converts genre to genres list using the same separator splitting logic as migration (tries ", ", "; ", " / ") - Sets self.genre to None instead of storing the deprecated value - Updated Discogs plugin tests to check genres list instead of genre string The deprecation ensures plugins using the genre parameter are warned to migrate to the genres list, while maintaining backwards compatibility through automatic conversion.
Simplify multi-genre implementation based on maintainer feedback (PR beetbox#6169). Changes: - Remove multi_value_genres and genre_separator config options - Replace complex sync_genre_fields() with ensure_first_value('genre', 'genres') - Update all plugins (Beatport, MusicBrainz, LastGenre) to always write genres as lists - Add automatic migration for comma/semicolon/slash-separated genre strings - Add 'beet migrate genres' command for explicit batch migration with --pretend flag - Update all tests to reflect simplified approach (44 tests passing) - Update documentation Implementation aligns with maintainer vision of always using multi-value genres internally with automatic backward-compatible sync to the genre field via ensure_first_value(), eliminating configuration complexity. Migration strategy avoids problems from beetbox#5540: - Automatic lazy migration on item access (no reimport/mbsync needed) - Optional batch migration command for user control - No endless rewrite loops due to proper field synchronization
Co-authored-by: Šarūnas Nejus <snejus@protonmail.com>
Co-authored-by: Šarūnas Nejus <snejus@protonmail.com>
|
alright, thanks for your effort (going on) |
Simplify multi-genre implementation based on maintainer feedback (PR #6169). Changes: - Remove multi_value_genres and genre_separator config options - Replace complex sync_genre_fields() with ensure_first_value('genre', 'genres') - Update all plugins (Beatport, MusicBrainz, LastGenre) to always write genres as lists - Add automatic migration for comma/semicolon/slash-separated genre strings - Add 'beet migrate genres' command for explicit batch migration with --pretend flag - Update all tests to reflect simplified approach (44 tests passing) - Update documentation Implementation aligns with maintainer vision of always using multi-value genres internally with automatic backward-compatible sync to the genre field via ensure_first_value(), eliminating configuration complexity. Migration strategy avoids problems from #5540: - Automatic lazy migration on item access (no reimport/mbsync needed) - Optional batch migration command for user control - No endless rewrite loops due to proper field synchronization
Simplify multi-genre implementation based on maintainer feedback (PR #6169). Changes: - Remove multi_value_genres and genre_separator config options - Replace complex sync_genre_fields() with ensure_first_value('genre', 'genres') - Update all plugins (Beatport, MusicBrainz, LastGenre) to always write genres as lists - Add automatic migration for comma/semicolon/slash-separated genre strings - Add 'beet migrate genres' command for explicit batch migration with --pretend flag - Update all tests to reflect simplified approach (44 tests passing) - Update documentation Implementation aligns with maintainer vision of always using multi-value genres internally with automatic backward-compatible sync to the genre field via ensure_first_value(), eliminating configuration complexity. Migration strategy avoids problems from #5540: - Automatic lazy migration on item access (no reimport/mbsync needed) - Optional batch migration command for user control - No endless rewrite loops due to proper field synchronization
Simplify multi-genre implementation based on maintainer feedback (PR #6169). Changes: - Remove multi_value_genres and genre_separator config options - Replace complex sync_genre_fields() with ensure_first_value('genre', 'genres') - Update all plugins (Beatport, MusicBrainz, LastGenre) to always write genres as lists - Add automatic migration for comma/semicolon/slash-separated genre strings - Add 'beet migrate genres' command for explicit batch migration with --pretend flag - Update all tests to reflect simplified approach (44 tests passing) - Update documentation Implementation aligns with maintainer vision of always using multi-value genres internally with automatic backward-compatible sync to the genre field via ensure_first_value(), eliminating configuration complexity. Migration strategy avoids problems from #5540: - Automatic lazy migration on item access (no reimport/mbsync needed) - Optional batch migration command for user control - No endless rewrite loops due to proper field synchronization
Simplify multi-genre implementation based on maintainer feedback (PR #6169). Changes: - Remove multi_value_genres and genre_separator config options - Replace complex sync_genre_fields() with ensure_first_value('genre', 'genres') - Update all plugins (Beatport, MusicBrainz, LastGenre) to always write genres as lists - Add automatic migration for comma/semicolon/slash-separated genre strings - Add 'beet migrate genres' command for explicit batch migration with --pretend flag - Update all tests to reflect simplified approach (44 tests passing) - Update documentation Implementation aligns with maintainer vision of always using multi-value genres internally with automatic backward-compatible sync to the genre field via ensure_first_value(), eliminating configuration complexity. Migration strategy avoids problems from #5540: - Automatic lazy migration on item access (no reimport/mbsync needed) - Optional batch migration command for user control - No endless rewrite loops due to proper field synchronization
Simplify multi-genre implementation based on maintainer feedback (PR #6169). Changes: - Remove multi_value_genres and genre_separator config options - Replace complex sync_genre_fields() with ensure_first_value('genre', 'genres') - Update all plugins (Beatport, MusicBrainz, LastGenre) to always write genres as lists - Add automatic migration for comma/semicolon/slash-separated genre strings - Add 'beet migrate genres' command for explicit batch migration with --pretend flag - Update all tests to reflect simplified approach (44 tests passing) - Update documentation Implementation aligns with maintainer vision of always using multi-value genres internally with automatic backward-compatible sync to the genre field via ensure_first_value(), eliminating configuration complexity. Migration strategy avoids problems from #5540: - Automatic lazy migration on item access (no reimport/mbsync needed) - Optional batch migration command for user control - No endless rewrite loops due to proper field synchronization
Implements native multi-value genre support following the same pattern as multi-value artists. Adds a 'genres' field that stores genres as a list and writes them as multiple individual genre tags to files.
Features:
Backward Compatibility:
Migration:
Code Review Feedback Addressed: