Skip to content

Commit

Permalink
artist: recover several wrongly split titles
Browse files Browse the repository at this point in the history
  • Loading branch information
snejus committed Dec 10, 2024
1 parent f129c4d commit 4818788
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions beetsplug/bandcamp/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from collections import Counter
from dataclasses import dataclass
from functools import cached_property
from os.path import commonprefix
from typing import TYPE_CHECKING, Any

from .names import Names
Expand Down Expand Up @@ -57,7 +58,7 @@ def from_names(cls, names: Names) -> Tracks:

obj = cls(list(map(Track.make, tracks)), names)
obj.handle_wild_track_alt()
obj.fix_remix_artists()
obj.fix_title_split()
return obj

@property
Expand Down Expand Up @@ -142,7 +143,7 @@ def discard_collaborators(self, artists: list[str]) -> list[str]:
if any(sa not in collaborators for sa in a.lower().split(" & "))
]

def fix_remix_artists(self) -> None:
def fix_title_split(self) -> None:
if 1 <= len(tracks := self.tracks_without_artist) < len(self) / 2:
for t in (t for t in tracks if t.remix):
# reset the artist if it got removed because it's in the remix text
Expand All @@ -151,6 +152,22 @@ def fix_remix_artists(self) -> None:
else:
t.artist = t.json_artist

# identify a track where artist was incorrectly parsed from the title
# while a llegitimate artist was available in the JSON data.
not_json_artist_tracks = [
t
for t in self.tracks
if t.artist
and "," not in t.json_artist
and not commonprefix([t.json_artist, t.artist])
and not commonprefix([t.json_artist, t.remix.remixer if t.remix else ""])
and t.json_artist.lower() not in t.name.lower()
]
if len(not_json_artist_tracks) == 1 and len(self) > 2:
for t in not_json_artist_tracks:
t.title = f"{t.artist} - {t.title}"
t.artist = t.json_artist

def handle_wild_track_alt(self) -> None:
"""Handle tracks that have incorrectly parsed `track_alt` field.
Expand Down

0 comments on commit 4818788

Please # to comment.