def test_find_puid_mbids(conn):
    mbids = find_puid_mbids(conn, "c12f1170-db63-4e85-931b-e46094b49085", 120, 530)
    assert_equals(["8d77b21e-2b41-4751-a88f-a2ab37cbd41c", "b81f83ee-4da4-11e0-9ed8-0025225356f3"], list(sorted(mbids)))
    mbids = find_puid_mbids(conn, "c12f1170-db63-4e85-931b-e46094b49085", 120, 130)
    assert_equals(["b81f83ee-4da4-11e0-9ed8-0025225356f3"], mbids)
    mbids = find_puid_mbids(conn, "c12f1170-db63-4e85-931b-e46094b49085", 160, 170)
    assert_equals([], mbids)
    mbids = find_puid_mbids(conn, "c12f1170-db63-4e85-931b-e46094123456", 120, 130)
    assert_equals([], mbids)
def test_find_puid_mbids(conn):
    mbids = find_puid_mbids(conn, 'c12f1170-db63-4e85-931b-e46094b49085', 120, 530)
    assert_equals(['b81f83ee-4da4-11e0-9ed8-0025225356f3', '6d885000-4dad-11e0-98ed-0025225356f3'], mbids)
    mbids = find_puid_mbids(conn, 'c12f1170-db63-4e85-931b-e46094b49085', 120, 130)
    assert_equals(['b81f83ee-4da4-11e0-9ed8-0025225356f3'], mbids)
    mbids = find_puid_mbids(conn, 'c12f1170-db63-4e85-931b-e46094b49085', 160, 170)
    assert_equals([], mbids)
    mbids = find_puid_mbids(conn, 'c12f1170-db63-4e85-931b-e46094123456', 120, 130)
    assert_equals([], mbids)
Beispiel #3
0
def import_submission(conn, submission):
    """
    Import the given submission into the main fingerprint database
    """
    with conn.begin():
        mbids = []
        if submission['mbid']:
            mbids.append(submission['mbid'])
        if submission['puid']:
            min_duration = submission['length'] - 15
            max_duration = submission['length'] + 15
            mbids.extend(
                find_puid_mbids(conn, submission['puid'], min_duration,
                                max_duration))
        logger.info("Importing submission %d with MBIDs %s", submission['id'],
                    ', '.join(mbids))
        matches = lookup_fingerprint(conn,
                                     submission['fingerprint'],
                                     submission['length'],
                                     TRACK_MERGE_TRESHOLD,
                                     FINGERPRINT_MERGE_TRESHOLD,
                                     fast=True)
        fingerprint = {
            'id': None,
            'track_id': None,
            'fingerprint': submission['fingerprint'],
            'length': submission['length'],
            'bitrate': submission['bitrate'],
            'source_id': submission['source_id'],
            'format_id': submission['format_id'],
        }
        if matches:
            match = matches[0]
            logger.debug(
                "Matches %d results, the top result (%s) is %d%% similar",
                len(matches), match['id'], match['score'] * 100)
            fingerprint['track_id'] = match['track_id']
            if match['score'] > FINGERPRINT_MERGE_TRESHOLD:
                fingerprint['id'] = match['id']
        if not fingerprint['track_id']:
            fingerprint['track_id'] = insert_track(conn)
            logger.info('Added new track %d', fingerprint['track_id'])
        if not fingerprint['id']:
            fingerprint['id'] = insert_fingerprint(conn, fingerprint)
            logger.info('Added new fingerprint %d', fingerprint['id'])
        for mbid in mbids:
            if insert_mbid(conn, fingerprint['track_id'], mbid):
                logger.info('Added MBID %s to track %d', mbid,
                            fingerprint['track_id'])
        update_stmt = schema.submission.update().where(
            schema.submission.c.id == submission['id'])
        conn.execute(update_stmt.values(handled=True))
        return fingerprint
Beispiel #4
0
def import_submission(conn, submission):
    """
    Import the given submission into the main fingerprint database
    """
    with conn.begin():
        mbids = []
        if submission['mbid']:
            mbids.append(submission['mbid'])
        if submission['puid']:
            min_duration = submission['length'] - 15
            max_duration = submission['length'] + 15
            mbids.extend(find_puid_mbids(conn, submission['puid'], min_duration, max_duration))
        logger.info("Importing submission %d with MBIDs %s",
            submission['id'], ', '.join(mbids))
        matches = lookup_fingerprint(conn,
            submission['fingerprint'], submission['length'],
            TRACK_MERGE_TRESHOLD, FINGERPRINT_MERGE_TRESHOLD, fast=True)
        fingerprint = {
            'id': None,
            'track_id': None,
            'fingerprint': submission['fingerprint'],
            'length': submission['length'],
            'bitrate': submission['bitrate'],
            'source_id': submission['source_id'],
            'format_id': submission['format_id'],
        }
        if matches:
            match = matches[0]
            logger.debug("Matches %d results, the top result (%s) is %d%% similar",
                len(matches), match['id'], match['score'] * 100)
            fingerprint['track_id'] = match['track_id']
            if match['score'] > FINGERPRINT_MERGE_TRESHOLD:
                fingerprint['id'] = match['id']
        if not fingerprint['track_id']:
            fingerprint['track_id'] = insert_track(conn)
            logger.info('Added new track %d', fingerprint['track_id'])
        if not fingerprint['id']:
            fingerprint['id'] = insert_fingerprint(conn, fingerprint)
            logger.info('Added new fingerprint %d', fingerprint['id'])
        for mbid in mbids:
            if insert_mbid(conn, fingerprint['track_id'], mbid):
                logger.info('Added MBID %s to track %d', mbid, fingerprint['track_id'])
        update_stmt = schema.submission.update().where(
            schema.submission.c.id == submission['id'])
        conn.execute(update_stmt.values(handled=True))
        return fingerprint
def import_submission(conn, submission, index=None):
    """
    Import the given submission into the main fingerprint database
    """
    with conn.begin():
        update_stmt = schema.submission.update().where(
            schema.submission.c.id == submission['id'])
        conn.execute(update_stmt.values(handled=True))
        mbids = []
        if submission['mbid']:
            mbids.append(resolve_mbid_redirect(conn, submission['mbid']))
        if submission['puid']:
            min_duration = submission['length'] - 15
            max_duration = submission['length'] + 15
            mbids.extend(find_puid_mbids(conn, submission['puid'], min_duration, max_duration))
        logger.info("Importing submission %d with MBIDs %s",
            submission['id'], ', '.join(mbids))
        num_unique_items = len(set(submission['fingerprint']))
        if num_unique_items < const.FINGERPRINT_MIN_UNIQUE_ITEMS:
            logger.info("Skipping, has only %d unique items", num_unique_items)
            return
        num_query_items = conn.execute("SELECT icount(acoustid_extract_query(%(fp)s))", dict(fp=submission['fingerprint']))
        if not num_query_items:
            logger.info("Skipping, no data to index")
            return
        searcher = FingerprintSearcher(conn, index, fast=False)
        searcher.min_score = const.TRACK_MERGE_THRESHOLD
        matches = searcher.search(submission['fingerprint'], submission['length'])
        fingerprint = {
            'id': None,
            'track_id': None,
            'fingerprint': submission['fingerprint'],
            'length': submission['length'],
            'bitrate': submission['bitrate'],
            'format_id': submission['format_id'],
        }
        if matches:
            match = matches[0]
            all_track_ids = set()
            possible_track_ids = set()
            for m in matches:
                if m['track_id'] in all_track_ids:
                    continue
                all_track_ids.add(m['track_id'])
                logger.debug("Fingerprint %d with track %d is %d%% similar", m['id'], m['track_id'], m['score'] * 100)
                if can_add_fp_to_track(conn, m['track_id'], submission['fingerprint'], submission['length']):
                    possible_track_ids.add(m['track_id'])
                    if not fingerprint['track_id']:
                        fingerprint['track_id'] = m['track_id']
                        if m['score'] > const.FINGERPRINT_MERGE_THRESHOLD:
                            fingerprint['id'] = m['id']
            if len(possible_track_ids) > 1:
                for group in can_merge_tracks(conn, possible_track_ids):
                    if fingerprint['track_id'] in group and len(group) > 1:
                        fingerprint['track_id'] = min(group)
                        group.remove(fingerprint['track_id'])
                        merge_tracks(conn, fingerprint['track_id'], list(group))
                        break
        if not fingerprint['track_id']:
            fingerprint['track_id'] = insert_track(conn)
        if not fingerprint['id']:
            fingerprint['id'] = insert_fingerprint(conn, fingerprint, submission['id'], submission['source_id'])
        else:
            inc_fingerprint_submission_count(conn, fingerprint['id'], submission['id'], submission['source_id'])
        for mbid in mbids:
            insert_mbid(conn, fingerprint['track_id'], mbid, submission['id'], submission['source_id'])
        if submission['puid'] and submission['puid'] != '00000000-0000-0000-0000-000000000000':
            insert_puid(conn, fingerprint['track_id'], submission['puid'], submission['id'], submission['source_id'])
        if submission['meta_id']:
            insert_track_meta(conn, fingerprint['track_id'], submission['meta_id'], submission['id'], submission['source_id'])
        if submission['foreignid_id']:
            insert_track_foreignid(conn, fingerprint['track_id'], submission['foreignid_id'], submission['id'], submission['source_id'])
        return fingerprint