Skip to content

Commit 5cb955f

Browse files
committed
[tags-report] Add unit tests, fix some issue
* update README
1 parent 523a612 commit 5cb955f

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Currently I have these services at home:
1616
## id3-checker
1717
From a directory, finds songs recursively and shows artist, title and album, alerting on discrepancies
1818

19+
## tags-report
20+
From a directory, finds songs recursively and shows discrepancies or misses in ID3 tags
21+
1922
## minecraft_ctl
2023
Script to disable or enable running Minecraft (by changing permissions, closing the firewall and killing processes).
2124
Currently supports (Mac only):
@@ -25,6 +28,9 @@ Currently supports (Mac only):
2528
* Diablo III
2629
* Docker
2730

31+
## qsm
32+
Quick service map: reads keepalived conf, report services location based on active IPs
33+
2834
## service-map
2935
* show running, active services
3036
* reads KeepAlived config (basic)

src/tools/bin/music_tags_report.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,29 @@ class Song:
4444

4545
def __post_init__(self):
4646
self.indexes = {"album": -2, "title": -1, "artist": -3}
47+
norm_path = "_".join(filter(None, re.split("[-_\s]", self.path)))
4748
try:
48-
self._year, self._album = self.path.split("/")[self.indexes["album"]].split("-", maxsplit=1)
49+
self._year, self._album = norm_path.split("/")[self.indexes["album"]].split("_", maxsplit=1)
4950
except Exception as e:
5051
# There could be "CDx" sub-dir
5152
try:
5253
self.indexes["album"] -= 1
5354
self.indexes["artist"] -= 1
54-
self._year, self._album = self.path.split("/")[self.indexes["album"]].split("-", maxsplit=1)
55+
self._year, self._album = norm_path.split("/")[self.indexes["album"]].split("_", maxsplit=1)
5556
except Exception as e_sub:
5657
click.echo(f"Error splitting {self.path} for album/year: {e}; {e_sub}")
5758
self._album = self._album.replace("_", " ")
5859
try:
59-
self._name = re.sub("^[0-9]+([^0-9 ])* (- )?", "", self.path.split("/")[self.indexes["title"]][:-4]).replace("_", " ")
60+
# self._name = re.sub("^[0-9]+([^0-9 ])* (- )?", "", norm_path.split("/")[self.indexes["title"]][:-4]).replace("_", " ")
61+
self._name = re.sub("^[0-9]+[-_.\s]*", "", self.path.split("/")[self.indexes["title"]][:-4]).replace("_", " ")
6062
except Exception as e:
6163
click.echo(f"Error searching name from {self.path}: {e}")
6264
try:
63-
self._track = re.sub("[^0-9].*$", "", self.path.split("/")[self.indexes["title"]])
65+
self._track = re.sub("[^0-9].*$", "", norm_path.split("/")[self.indexes["title"]])
6466
except Exception as e:
6567
click.echo(f"Error searching track from {self.path}: {e}")
6668
try:
67-
self._artist = self.path.split("/")[self.indexes["artist"]].replace("_", " ")
69+
self._artist = norm_path.split("/")[self.indexes["artist"]].replace("_", " ")
6870
except Exception as e:
6971
click.echo(f"Error splitting {self.path} for artist: {e}")
7072

@@ -81,11 +83,11 @@ def name(self) -> str:
8183
return self._name
8284

8385
@property
84-
def track(self) -> str:
86+
def track(self) -> int:
8587
return int(self._track or "0")
8688

8789
@property
88-
def year(self) -> str:
90+
def year(self) -> int:
8991
return int(self._year)
9092

9193

test/test_music_tags_report.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import pytest
2+
3+
from tools.bin.music_tags_report import Song
4+
5+
6+
@pytest.mark.parametrize(
7+
"full_path,expected_year,expected_album,expected_artist,expected_n,expected_title",
8+
(
9+
("yaddayadda/artist/1974-album/5 - My Title.mp3", 1974, "album", "artist", 5, "My Title"),
10+
("yaddayadda/artist/1974- album/3. My Title, jet-set.mp3", 1974, "album", "artist", 3, "My Title, jet-set"),
11+
("yaddayadda/Artist_Name/1974 - album/disc/01-My title è.mp3", 1974, "album", "Artist Name", 1, "My title è"),
12+
),
13+
)
14+
def test_song_class(full_path, expected_year, expected_album, expected_artist, expected_n, expected_title):
15+
song = Song(full_path)
16+
assert song.year == expected_year
17+
assert song.album == expected_album
18+
assert song.artist == expected_artist
19+
assert song.name == expected_title
20+
assert song.track == expected_n

0 commit comments

Comments
 (0)