示例#1
0
    def test_fetch_without_stop_words(self, search):
        search.side_effect = typesense_response_1

        q = MBIDMappingQuery(remove_stop_words=True)
        resp = q.fetch(json_request_1)
        self.assertEqual(len(resp), 1)
        self.assertDictEqual(resp[0], json_response_1[0])
示例#2
0
    def test_fetch(self, search):
        search.side_effect = typesense_response_0

        q = MBIDMappingQuery()
        resp = q.fetch(json_request_0)
        self.assertEqual(len(resp), 3)
        self.assertDictEqual(resp[0], json_response_0[0])
        self.assertDictEqual(resp[1], json_response_0[1])
        self.assertDictEqual(resp[2], json_response_0[2])
示例#3
0
def lookup_listens(app, listens, stats, exact, debug):
    """ Attempt an exact string lookup on the passed in listens. Return the maches and the
        listens that were NOT matched. if exact == True, use an exact PG lookup otherwise
        use a typesense fuzzy lookup.
    """
    if len(listens) == 0:
        return ([], [], stats)

    if debug:
        app.logger.info(
            f"""Lookup (exact {exact}) '{listens[0]["data"]["artist_name"]}', '{listens[0]["data"]["track_name"]}'"""
        )

    if exact:
        q = ArtistCreditRecordingLookupQuery(debug=debug)
    else:
        q = MBIDMappingQuery(timeout=SEARCH_TIMEOUT,
                             remove_stop_words=True,
                             debug=debug)

    params = []
    for listen in listens:
        params.append({
            '[artist_credit_name]': listen["data"]["artist_name"],
            '[recording_name]': listen["data"]["track_name"]
        })

    rows = []
    hits = q.fetch(params)
    for hit in sorted(hits, key=itemgetter("index"), reverse=True):
        listen = listens[hit["index"]]

        if exact:
            hit["match_type"] = MATCH_TYPE_EXACT_MATCH
        stats[MATCH_TYPES[hit["match_type"]]] += 1
        rows.append((listen['recording_msid'], hit["recording_mbid"],
                     hit["release_mbid"], hit["release_name"],
                     str(hit["artist_mbids"]), hit["artist_credit_id"],
                     hit["artist_credit_name"], hit["recording_name"],
                     MATCH_TYPES[hit["match_type"]]))

        if debug:
            app.logger.info("\n".join(q.get_debug_log_lines()))

        listens.pop(hit["index"])
        if len(listens) == 0:
            break

    else:
        if debug:
            app.logger.info("No matches returned.")

    return rows, listens, stats
 def test_basics(self):
     q = MBIDMappingQuery()
     self.assertEqual(q.names()[0], "mbid-mapping")
     self.assertEqual(q.names()[1], "MusicBrainz ID Mapping lookup")
     self.assertNotEqual(q.introduction(), "")
     self.assertEqual(q.inputs(),
                      ['[artist_credit_name]', '[recording_name]'])
     self.assertEqual(q.outputs(), [
         'index', 'artist_credit_arg', 'recording_arg',
         'artist_credit_name', 'release_name', 'recording_name',
         'release_mbid', 'recording_mbid', 'artist_credit_id'
     ])
示例#5
0
#!/usr/bin/env python3

from datasethoster.main import create_app, init_sentry, register_query
from listenbrainz.labs_api.labs.api.artist_country_from_artist_mbid import ArtistCountryFromArtistMBIDQuery
from listenbrainz.labs_api.labs.api.artist_credit_from_artist_mbid import ArtistCreditIdFromArtistMBIDQuery
from listenbrainz.labs_api.labs.api.artist_credit_from_artist_msid import ArtistCreditIdFromArtistMSIDQuery
from listenbrainz.labs_api.labs.api.recording_from_recording_mbid import RecordingFromRecordingMBIDQuery
from listenbrainz.labs_api.labs.api.mbid_mapping import MBIDMappingQuery
from listenbrainz.labs_api.labs.api.year_from_artist_credit_recording import YearFromArtistCreditRecordingQuery
from listenbrainz.labs_api.labs.api.recording_search import RecordingSearchQuery
from listenbrainz.labs_api.labs.api.artist_credit_recording_lookup import ArtistCreditRecordingLookupQuery
from listenbrainz.webserver import load_config

register_query(ArtistCountryFromArtistMBIDQuery())
register_query(ArtistCreditIdFromArtistMBIDQuery())
register_query(ArtistCreditIdFromArtistMSIDQuery())
register_query(RecordingFromRecordingMBIDQuery())
register_query(MBIDMappingQuery())
register_query(YearFromArtistCreditRecordingQuery())
register_query(RecordingSearchQuery())
register_query(ArtistCreditRecordingLookupQuery())

app = create_app()
load_config(app)
init_sentry(app, "DATASETS_SENTRY_DSN")