Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: album directory parsing with album versions #1683

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_album_dir(track_dir: str, album_name: str) -> str | None:
if compare_strings(album_name, dirname.split(" - ")[-1], False):
# account for ArtistName - AlbumName format in the directory name
return parentdir
if compare_strings(album_name, dirname.split("(")[0], False):
if compare_strings(album_name, dirname.split(" - ")[-1].split("(")[0], False):
# account for ArtistName - AlbumName (Version) format in the directory name
return parentdir
if compare_strings(album_name.split("(")[0], dirname, False):
Expand Down
58 changes: 58 additions & 0 deletions tests/server/providers/filesystem/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests for utility/helper functions."""

import pytest

from music_assistant.server.providers.filesystem_local import helpers

# ruff: noqa: S108
Expand Down Expand Up @@ -31,3 +33,59 @@ def test_get_artist_dir() -> None:
album_path = "/tmp/Antonin Dvorak/Album"
artist_name = "Antonín Dvořák"
assert helpers.get_artist_dir(artist_name, album_path) == "/tmp/Antonin Dvorak"


@pytest.mark.parametrize(
("album_name", "track_dir", "expected"),
[
# Test literal match
(
"Selected Ambient Works 85-92",
"/home/user/Music/Aphex Twin/Selected Ambient Works 85-92",
"/home/user/Music/Aphex Twin/Selected Ambient Works 85-92",
),
# Test artist - album format
(
"Selected Ambient Works 85-92",
"/home/user/Music/Aphex Twin - Selected Ambient Works 85-92",
"/home/user/Music/Aphex Twin - Selected Ambient Works 85-92",
),
# Test artist - album (version) format
(
"Selected Ambient Works 85-92",
"/home/user/Music/Aphex Twin - Selected Ambient Works 85-92 (Remastered)",
"/home/user/Music/Aphex Twin - Selected Ambient Works 85-92 (Remastered)",
),
# Test artist - album (version) format
(
"Selected Ambient Works 85-92",
"/home/user/Music/Aphex Twin - Selected Ambient Works 85-92 (Remastered) - WEB",
"/home/user/Music/Aphex Twin - Selected Ambient Works 85-92 (Remastered) - WEB",
),
# Test album (version) format
(
"Selected Ambient Works 85-92",
"/home/user/Music/Aphex Twin/Selected Ambient Works 85-92 (Remastered)",
"/home/user/Music/Aphex Twin/Selected Ambient Works 85-92 (Remastered)",
),
# Test album name in dir
(
"Selected Ambient Works 85-92",
"/home/user/Music/RandomDirWithSelected Ambient Works 85-92InIt",
"/home/user/Music/RandomDirWithSelected Ambient Works 85-92InIt",
),
# Test no match
(
"NonExistentAlbumName",
"/home/user/Music/Aphex Twin/Selected Ambient Works 85-92",
None,
),
# Test empty album name
("", "/home/user/Music/Aphex Twin/Selected Ambient Works 85-92", None),
# Test empty track dir
("Selected Ambient Works 85-92", "", None),
],
)
def test_get_album_dir(album_name: str, track_dir: str, expected: str) -> None:
"""Test the extraction of an album dir."""
assert helpers.get_album_dir(track_dir, album_name) == expected
Loading