[music] Tracks can have multiple artists
This commit is contained in:
@ -15,12 +15,26 @@ def clean_artist_name(name: str) -> str:
|
||||
name = re.split(" w. ", name, flags=re.IGNORECASE)[0].strip()
|
||||
if " featuring " in name.lower():
|
||||
name = re.split(" featuring ", name, flags=re.IGNORECASE)[0].strip()
|
||||
# if " & " in name.lower() and "of the wand" not in name.lower():
|
||||
# name = re.split("&", name, flags=re.IGNORECASE)[0].strip()
|
||||
|
||||
return name
|
||||
|
||||
|
||||
def parse_artist_names(name: str) -> list[str]:
|
||||
"""Split a combined artist string (e.g. 'A & B') into individual names.
|
||||
|
||||
First strips feat./featuring/w. prefixes, then splits on ' & ' to
|
||||
support collaboration-style credits like 'Matt Sweeney & Bonnie Prince Billy'.
|
||||
"""
|
||||
name = clean_artist_name(name)
|
||||
if " & " in name.lower():
|
||||
return [
|
||||
part.strip()
|
||||
for part in re.split(r"\s+&\s+", name, flags=re.IGNORECASE)
|
||||
if part.strip()
|
||||
]
|
||||
return [name]
|
||||
|
||||
|
||||
def get_or_create_various_artists() -> "Artist":
|
||||
from music.models import Artist
|
||||
|
||||
@ -35,19 +49,19 @@ def deduplicate_tracks(commit=False) -> int:
|
||||
from music.models import Track
|
||||
|
||||
duplicates = (
|
||||
Track.objects.values("artist", "title")
|
||||
Track.objects.values("title")
|
||||
.annotate(dup_count=models.Count("id"))
|
||||
.filter(dup_count__gt=1)
|
||||
)
|
||||
|
||||
query = models.Q()
|
||||
for dup in duplicates:
|
||||
query |= models.Q(artist=dup["artist"], title=dup["title"])
|
||||
query |= models.Q(title=dup["title"])
|
||||
|
||||
duplicate_tracks = Track.objects.filter(query)
|
||||
|
||||
for b in duplicate_tracks:
|
||||
tracks = Track.objects.filter(artist=b.artist, title=b.title)
|
||||
tracks = Track.objects.filter(title=b.title)
|
||||
first = tracks.first()
|
||||
for other in tracks.exclude(id=first.id):
|
||||
print("Moving scrobbles for", other.id, " to ", first.id)
|
||||
@ -74,7 +88,7 @@ def condense_albums(commit: bool = False):
|
||||
for track in Track.objects.all():
|
||||
albums_to_add = []
|
||||
duplicates = (
|
||||
Track.objects.filter(title=track.title, artist=track.artist)
|
||||
Track.objects.filter(title=track.title)
|
||||
.exclude(id=track.id)
|
||||
.exclude(id__in=processed_ids)
|
||||
)
|
||||
@ -88,7 +102,7 @@ def condense_albums(commit: bool = False):
|
||||
track.albums.add(dup_track.album)
|
||||
|
||||
# Find out if this track appears more than once
|
||||
duplicates = Track.objects.filter(title=track.title, artist=track.artist)
|
||||
duplicates = Track.objects.filter(title=track.title)
|
||||
if duplicates.count() > 1:
|
||||
logger.info(f"Track appears more than once, condensing: {track}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user