Skip to content

nightly-2f3efaea-ls271

Pre-release
Pre-release

Choose a tag to compare

@LinuxServer-CI LinuxServer-CI released this 18 Apr 19:40
· 23 commits to nightly since this release
6adee69

CI Report:

https://ci-tests.linuxserver.io/linuxserver/beets/nightly-2f3efaea-ls271/index.html

LinuxServer Changes:

No changes

Remote Changes:

Refactor musicbrainz to reduce cognitive complexity (#6530)

Summary

A broad internal refactor of beetsplug/musicbrainz.py and its test
suite. No user-facing behaviour changes are intended. The goal is to
make parsing logic easier to understand, test, and maintain.

This PR halves the cognitive complexity in musicbrainz plugin:

Before

$ complexipy beetsplug/musicbrainz.py
🧠 Total Cognitive Complexity: 181
1 file analyzed in 0.0116 seconds

After

$ complexipy beetsplug/musicbrainz.py
🧠 Total Cognitive Complexity: 93
1 file analyzed in 0.0097 seconds

Production Code Changes

Parsing Decomposition

The monolithic album_info method is broken into focused
@staticmethod helpers, each returning a typed TypedDict:

Method Responsibility
_parse_artist_credits Replaces _flatten_artist_credit /
_multi_artist_credit
_parse_release_group albumtype, original_year, etc.
_parse_label_infos label, catalognum
_parse_genres Genre list
_parse_external_ids Third-party IDs from URL relations
_parse_work_relations Composer / lyricist credits
_parse_artist_relations Arranger / remixer credits
get_tracks_from_medium Per-medium track iteration

Each helper returns a typed TypedDict, making the data contract
explicit and the code easier to compose with **kwargs unpacking into
AlbumInfo / TrackInfo.

Other Simplifications

  • _set_date_str (mutable, side-effecting) is replaced by _get_date,
    a pure function returning (year, month, day).
  • _preferred_release_event and _preferred_alias are simplified.
  • Three @cached_property entries (ignored_media,
    ignore_data_tracks, ignore_video_tracks) are moved up to sit with
    other class-level properties.

Test Infrastructure Changes

Factory Layer (test/plugins/factories/musicbrainz.py)

factory-boy / pytest-factoryboy are added as test dependencies. A
new factory module introduces composable, deterministic factories:

  • AliasFactory, ArtistFactory, ArtistCreditFactory
  • RecordingFactory, TrackFactory, MediumFactory
  • ReleaseGroupFactory, ReleaseFactory

Factories use a shared _IdFactory base class that generates stable,
predictable UUIDs (00000000-0000-0000-0000-000000001001, etc.) based
on an id_base + index pair. This makes assertions on IDs readable
and deterministic without hard-coded magic strings.

Before:

recording = {
    "title": "foo",
    "id": "bar",
    "length": 42,
    "artist_credit": [{"artist": {"name": "some-artist", "id": "some-id", ...}, ...}],
    ...
}

After:

recording = recording_factory(title="foo", length=42)

Test Consolidation

Many small single-field assertion tests that each constructed an
identical release are collapsed into a single test_parse_release
snapshot assertion, covering all AlbumInfo fields at once. This
reduces redundant fixture setup and makes it immediately obvious what
the full output of album_info looks like for a default release.

The hand-rolled _make_release / _make_recording helpers are removed
entirely, replaced by composable factory calls using factory-boy's __
double-underscore traversal syntax:

# Before
release = self._make_release(date="1987-03-31")

# After
release = release_factory(release_group__first_release_date="1987-03-31")