[music] Add better track fetching
This commit is contained in:
@ -16,9 +16,11 @@ from imagekit.processors import ResizeToFit
|
||||
from music.allmusic import get_allmusic_slug, scrape_data_from_allmusic
|
||||
from music.bandcamp import get_bandcamp_slug
|
||||
from music.musicbrainz import (
|
||||
extract_featured_artists,
|
||||
get_album_metadata_with_artist,
|
||||
get_recording_mbid_exact,
|
||||
get_track_metadata_with_artist,
|
||||
resolve_track,
|
||||
)
|
||||
from music.theaudiodb import lookup_album_from_tadb, lookup_artist_from_tadb
|
||||
from music.utils import clean_artist_name
|
||||
@ -694,6 +696,7 @@ class Track(ScrobblableMixin):
|
||||
if mbid and run_time_seconds:
|
||||
track.base_run_time_seconds = run_time_seconds
|
||||
track.musicbrainz_id = mbid
|
||||
track.tags.add("musicbrainz-provider", "musicbrainz-enriched")
|
||||
else:
|
||||
artist_name_str = " & ".join(artist_names) if artist_names else ""
|
||||
logger.info(
|
||||
@ -704,15 +707,23 @@ class Track(ScrobblableMixin):
|
||||
"track_id": track.id,
|
||||
},
|
||||
)
|
||||
try:
|
||||
mbid, length = get_recording_mbid_exact(
|
||||
title, artist_name_str, album_name
|
||||
)
|
||||
except Exception:
|
||||
result, method = resolve_track(title, artist_name_str, album_name)
|
||||
if result and result.get("recording_mbid"):
|
||||
track.musicbrainz_id = result["recording_mbid"]
|
||||
length_ms = result.get("length_ms")
|
||||
if length_ms and not track.base_run_time_seconds:
|
||||
track.base_run_time_seconds = int(int(length_ms) / 1000)
|
||||
method_tag = f"musicbrainz-{method}" if method else ""
|
||||
track.tags.add(method_tag, "musicbrainz-enriched")
|
||||
cleaned_title, featured_names = extract_featured_artists(title)
|
||||
for feat_name in featured_names:
|
||||
artist = Artist.find_or_create(feat_name, track_name=title)
|
||||
if artist:
|
||||
track.artists.add(artist)
|
||||
else:
|
||||
print("No musicbrainz result found, cannot enrich")
|
||||
track.tags.add("musicbrainz-notfound")
|
||||
return track
|
||||
track.base_run_time_seconds = run_time_seconds or int(length / 1000)
|
||||
track.musicbrainz_id = mbid
|
||||
if commit:
|
||||
track.save()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user