def read(self, inputs):
        self.debug("read for %s/%s" % (self.metric, self.mbid))

        url = self.SERVER_URL + self.metric + "/" + self.mbid
        self.debug(f"url: {url}")
        r = requests.get(url, params={'remove_dups': 'true'})
        if r.status_code != 200:
            raise PipelineError("Cannot fetch annoy similarities from AcousticBrainz: HTTP code %d" % r.status_code)

        try:
            results = ujson.loads(r.text)
        except ValueError as err:
            raise PipelineError("Cannot fetch annoy similarities from AcousticBrainz: Invalid JSON returned: " + str(err))

        entities = []
        for row in results:
            r = Recording(mbid=row['recording_mbid'], 
                          acousticbrainz={
                              'metric': self.metric,
                              'similarity_from': self.mbid,
                              'similarity': row['distance'], 
                              'offset': row['offset']
                          }
                          )
            r.add_note("Related to %s with metric %s" % (self.mbid, self.metric))
            entities.append(r)

        self.debug("read %d recordings" % len(entities))

        return entities
Beispiel #2
0
    def read(self, inputs):
        print("  annoy: read for %s/%s" % (self.metric, self.mbid))

        url = self.SERVER_URL + self.metric + "/" + self.mbid
        r = requests.get(url)
        if r.status_code != 200:
            r.raise_for_status()

        try:
            results = ujson.loads(r.text)
        except Exception as err:
            raise RuntimeError(str(err))

        entities = []
        for row in results:
            r = Recording(mbid=row['recording_mbid'],
                          acousticbrainz={
                              'similarity': row['distance'],
                              'offset': row['offset']
                          })
            r.add_note("Related to %s" % self.mbid)
            entities.append(r)

        print("  annoy: read %d recordings" % len(entities))

        return entities