Пример #1
0
def main(script, opts, args):
    conn = script.engine.connect()
    min_id, max_id = conn.execute("SELECT min(id), max(id) FROM fingerprint").fetchone()
    print min_id, max_id
    while True:
        id = random.randint(min_id, max_id)
        row = conn.execute("SELECT fingerprint, length FROM fingerprint WHERE id = %s", (id,)).fetchone()
        if row is None:
            continue
        fingerprint, length = row
        for i in range(1):
            t0 = time.time()
            for i in range(len(fingerprint)):
                fingerprint[i] ^= random.getrandbits(2) << random.randint(0, 20)
            searcher = FingerprintSearcher(script.engine, script.index)
            matches = searcher.search(fingerprint, length + random.randint(-8, 8))
            track_ids = [r[1] for r in matches]
            track_mbid_map = lookup_mbids(conn, track_ids)
            mbids = set()
            for track_id, track_mbids in track_mbid_map.iteritems():
                for mbid, sources in track_mbids:
                    mbids.add(mbid)
            metadata = lookup_metadata(conn, mbids, load_releases=True, load_release_groups=True)
            print "Searching for ID", id, len(matches), time.time() - t0
        time.sleep(1)
Пример #2
0
def main(script, opts, args):
    conn = script.engine.connect()
    min_id, max_id = conn.execute(
        "SELECT min(id), max(id) FROM fingerprint").fetchone()
    print min_id, max_id
    while True:
        id = random.randint(min_id, max_id)
        row = conn.execute(
            "SELECT fingerprint, length FROM fingerprint WHERE id = %s",
            (id, )).fetchone()
        if row is None:
            continue
        fingerprint, length = row
        for i in range(1):
            t0 = time.time()
            for i in range(len(fingerprint)):
                fingerprint[i] ^= random.getrandbits(2) << random.randint(
                    0, 20)
            searcher = FingerprintSearcher(script.engine, script.index)
            matches = searcher.search(fingerprint,
                                      length + random.randint(-8, 8))
            track_ids = [r[1] for r in matches]
            track_mbid_map = lookup_mbids(conn, track_ids)
            mbids = set()
            for track_id, track_mbids in track_mbid_map.iteritems():
                for mbid, sources in track_mbids:
                    mbids.add(mbid)
            metadata = lookup_metadata(conn,
                                       mbids,
                                       load_releases=True,
                                       load_release_groups=True)
            print "Searching for ID", id, len(matches), time.time() - t0
        time.sleep(1)
Пример #3
0
 def _inject_recording_ids_internal(self, add=True):
     el_recording = {}
     track_mbid_map = lookup_mbids(self.conn, self.el_result.keys())
     for track_id, mbids in track_mbid_map.iteritems():
         for mbid in mbids:
             if add:
                 for result_el in self.el_result[track_id]:
                     recording = {'id': mbid}
                     result_el.setdefault(self.recordings_name, []).append(recording)
                     el_recording.setdefault(mbid, []).append(recording)
             else:
                 el_recording.setdefault(mbid, []).extend(self.el_result[track_id])
     return el_recording, track_mbid_map
Пример #4
0
 def _inject_recording_ids_internal(self, add=True, add_sources=False):
     el_recording = {}
     res_map = {}
     track_mbid_map = lookup_mbids(self.conn, self.el_result.keys())
     for track_id, mbids in track_mbid_map.iteritems():
         res_map[track_id] = []
         for mbid, sources in mbids:
             res_map[track_id].append(mbid)
             if add:
                 for result_el in self.el_result[track_id]:
                     recording = {'id': mbid}
                     if add_sources:
                         recording['sources'] = sources
                     result_el.setdefault(self.recordings_name, []).append(recording)
                     el_recording.setdefault(mbid, []).append(recording)
             else:
                 el_recording.setdefault(mbid, []).extend(self.el_result[track_id])
     return el_recording, res_map
Пример #5
0
 def _inject_recording_ids_internal(self, add=True, add_sources=False):
     el_recording = {}
     res_map = {}
     track_mbid_map = lookup_mbids(self.conn, self.el_result.keys())
     for track_id, mbids in track_mbid_map.iteritems():
         res_map[track_id] = []
         for mbid, sources in mbids:
             res_map[track_id].append(mbid)
             if add:
                 for result_el in self.el_result[track_id]:
                     recording = {'id': mbid}
                     if add_sources:
                         recording['sources'] = sources
                     result_el.setdefault(self.recordings_name,
                                          []).append(recording)
                     el_recording.setdefault(mbid, []).append(recording)
             else:
                 el_recording.setdefault(mbid, []).extend(
                     self.el_result[track_id])
     return el_recording, res_map
Пример #6
0
 def _inject_metadata(self, meta, result_map):
     track_mbid_map = lookup_mbids(self.conn, result_map.keys())
     if meta > 1:
         all_mbids = []
         for track_id, mbids in track_mbid_map.iteritems():
             all_mbids.extend(mbids)
         track_meta_map = lookup_metadata(self.conn, all_mbids)
     for track_id, mbids in track_mbid_map.iteritems():
         result = result_map[track_id]
         result[self.recordings_name] = tracks = []
         for mbid in mbids:
             recording = {}
             tracks.append(recording)
             recording['id'] = str(mbid)
             if meta == 1:
                 continue
             track_meta = track_meta_map.get(mbid)
             if track_meta is None:
                 continue
             recording['tracks'] = [{
                 'title': track_meta['name'],
                 'duration': track_meta['length'],
                 'artist': {
                     'id': track_meta['artist_id'],
                     'name': track_meta['artist_name'],
                 },
                 'position': track_meta['track_num'],
                 'medium': {
                     'track_count': track_meta['total_tracks'],
                     # position
                     # title
                     # format
                     'release': {
                         'id': track_meta['release_id'],
                         'title': track_meta['release_name'],
                         # medium_count
                     },
                 },
             }]
Пример #7
0
 def _inject_recording_ids_internal(self, add=True, add_sources=False):
     # type: (bool, bool) -> Tuple[Dict[str, List[Dict[str, Any]]], Dict[int, List[str]]]
     el_recording = {}  # type: Dict[str, List[Dict[str, Any]]]
     res_map = {}  # type: Dict[int, List[str]]
     track_mbid_map = lookup_mbids(self.ctx.db.get_fingerprint_db(),
                                   self.el_result.keys())
     for track_id, mbids in track_mbid_map.items():
         res_map[track_id] = []
         for mbid, sources in mbids:
             res_map[track_id].append(mbid)
             if add:
                 for result_el in self.el_result[track_id]:
                     recording = {'id': mbid}  # type: Dict[str, Any]
                     if add_sources:
                         recording['sources'] = sources
                     result_el.setdefault(self.recordings_name,
                                          []).append(recording)
                     el_recording.setdefault(mbid, []).append(recording)
             else:
                 el_recording.setdefault(mbid, []).extend(
                     self.el_result[track_id])
     return el_recording, res_map