Skip to content

Commit

Permalink
get_album_dir: more robust handling
Browse files Browse the repository at this point in the history
  • Loading branch information
skrobul committed Sep 30, 2024
1 parent 756757f commit 62c06bb
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
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(" - ")[1].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

0 comments on commit 62c06bb

Please sign in to comment.