Skip to content

Commit

Permalink
artist: disallow artists such as 'the' or 'live'
Browse files Browse the repository at this point in the history
  • Loading branch information
snejus committed Dec 1, 2024
1 parent e96e438 commit 4335eed
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion beetsplug/bandcamp/metaguru.py
Original file line number Diff line number Diff line change
@@ -239,7 +239,7 @@ def country(self) -> str:
@cached_property
def tracks(self) -> Tracks:
"""Return parsed tracks."""
self._tracks.ensure_track_artists(self.preliminary_albumartist)
self._tracks.fix_track_artists(self.preliminary_albumartist)
return self._tracks

@cached_property
2 changes: 1 addition & 1 deletion beetsplug/bandcamp/track.py
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ def artist(self) -> str | None:

@dataclass
class Track:
DELIM_NOT_INSIDE_PARENS = re.compile(r"(?<!-) - (?!-|[^([]+\w[])])")
DELIM_NOT_INSIDE_PARENS = re.compile(r"(?<!-)(?<!^live) - (?!-|[^([]+\w[])])", re.I)
json_item: JSONDict = field(default_factory=dict, repr=False)
track_id: str = ""
index: int | None = None
15 changes: 12 additions & 3 deletions beetsplug/bandcamp/tracks.py
Original file line number Diff line number Diff line change
@@ -174,10 +174,13 @@ def handle_wild_track_alt(self) -> None:
t.title = t.json_item["name"]
t.track_alt = None

def ensure_track_artists(self, albumartist: str) -> None:
"""Set artist for tracks that do not have it.
def fix_track_artists(self, albumartist: str) -> None:
"""Adjust track artists in the context of the entire album.
Firstly, check how many tracks are missing artists. If there are 1-3 tracks
Firstly, check whether the artist is 'the'. If so, prepend it to the title and
reset the artist.
Then, check how many tracks are missing artists. If there are 1-3 tracks
which have it set, this is most likely because the titles had ' - ' separator
and our logic split it into artist. For each, ensure that
(1) Artist was not set in the JSON metadata
@@ -191,6 +194,12 @@ def ensure_track_artists(self, albumartist: str) -> None:
Otherwise, use the albumartist as the default.
"""
for t in (t for t in self if t.artist):
# the artist cannot be 'the', so it's most likely a part of the title
if t.artist.lower() == "the":
t.title = f"{t.artist} {t.title}"
t.artist = ""

if not self.tracks_without_artist:
return

1 change: 1 addition & 0 deletions tests/test_track.py
Original file line number Diff line number Diff line change
@@ -99,6 +99,7 @@
"Artist, & Other and Another - Title (Another Remix feat. Other)",
("", "Artist", "", "Title (Another Remix feat. Other)", "Title"),
),
("Live - 2020", ("", "", "", "Live - 2020", "Live - 2020")),
],
)
def test_parse_track_name(name, expected, json_track):

0 comments on commit 4335eed

Please sign in to comment.