Add looking tracks without MB IDs by looking them up
This commit is contained in:
@ -4,6 +4,7 @@ import re
|
|||||||
from scrobbles.musicbrainz import (
|
from scrobbles.musicbrainz import (
|
||||||
lookup_album_dict_from_mb,
|
lookup_album_dict_from_mb,
|
||||||
lookup_artist_from_mb,
|
lookup_artist_from_mb,
|
||||||
|
lookup_track_from_mb,
|
||||||
)
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -93,7 +94,11 @@ def get_or_create_track(
|
|||||||
title=title, artist=artist, album=album
|
title=title, artist=artist, album=album
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
# TODO Can we look up mbid for tracks?
|
if not mbid:
|
||||||
|
mbid = lookup_track_from_mb(
|
||||||
|
title, artist.musicbrainz_id, album.musicbrainz_id
|
||||||
|
)['id']
|
||||||
|
|
||||||
if not track:
|
if not track:
|
||||||
track = Track.objects.create(
|
track = Track.objects.create(
|
||||||
title=title,
|
title=title,
|
||||||
|
|||||||
@ -90,16 +90,18 @@ def lookup_artist_from_mb(artist_name: str) -> str:
|
|||||||
return top_result
|
return top_result
|
||||||
|
|
||||||
|
|
||||||
def lookup_track_from_mb(artist_name: str) -> str:
|
def lookup_track_from_mb(
|
||||||
|
track_name: str, artist_mbid: str, album_mbid: str
|
||||||
|
) -> str:
|
||||||
musicbrainzngs.set_useragent('vrobbler', '0.3.0')
|
musicbrainzngs.set_useragent('vrobbler', '0.3.0')
|
||||||
|
|
||||||
top_result = musicbrainzngs.search_recordings(artist=artist_name)[
|
top_result = musicbrainzngs.search_recordings(
|
||||||
'artist-list'
|
query=track_name, artist=artist_mbid, release=album_mbid
|
||||||
][0]
|
)['recording-list'][0]
|
||||||
score = int(top_result.get('ext:score'))
|
score = int(top_result.get('ext:score'))
|
||||||
if score < 85:
|
if score < 85:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Artist lookup score below 85 threshold",
|
"Track lookup score below 85 threshold",
|
||||||
extra={"result": top_result},
|
extra={"result": top_result},
|
||||||
)
|
)
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
Reference in New Issue
Block a user