Commit b9908d4e authored by Lukáš Lalinský's avatar Lukáš Lalinský

Handle MBID redirects when importing submissions (not tested)

parent 3348c253
......@@ -139,3 +139,13 @@ def find_puid_mbids(conn, puid, min_duration, max_duration):
good_group = cluster_track_names(r['name'] + ' ' + r['artist'] for r in rows)
return [rows[i]['gid'] for i in good_group]
def resolve_mbid_redirect(conn, mbid):
src = schema.mb_recording
src = src.join(schema.mb_recording_gid_redirect, schema.mb_recording_gid_redirect.c.new_id == schema.mb_recording.c.id)
condition = schema.mb_recording_gid_redirect.c.gid == mbid
columns = [schema.mb_recording.c.gid]
query = sql.select(columns, condition, from_obj=src)
new_mbid = conn.execute(query).scalar()
return new_mbid or mbid
......@@ -5,7 +5,7 @@ import logging
from sqlalchemy import sql
from acoustid import tables as schema
from acoustid.data.fingerprint import lookup_fingerprint, insert_fingerprint
from acoustid.data.musicbrainz import find_puid_mbids
from acoustid.data.musicbrainz import find_puid_mbids, resolve_mbid_redirect
from acoustid.data.track import insert_track, insert_mbid, merge_tracks
logger = logging.getLogger(__name__)
......@@ -42,7 +42,7 @@ def import_submission(conn, submission):
with conn.begin():
mbids = []
if submission['mbid']:
mbids.append(submission['mbid'])
mbids.append(resolve_mbid_redirect(submission['mbid']))
if submission['puid']:
min_duration = submission['length'] - 15
max_duration = submission['length'] + 15
......
......@@ -131,6 +131,12 @@ mb_recording = Table('s_recording', metadata,
schema='musicbrainz',
)
mb_recording_gid_redirect = Table('recording_gid_redirect', metadata,
Column('gid', String, primary_key=True),
Column('new_id', Integer, ForeignKey('musicbrainz.s_recording.id')),
schema='musicbrainz',
)
mb_track = Table('s_track', metadata,
Column('id', Integer, primary_key=True),
Column('position', Integer),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment