def cleanup_results(results_list): # nothing found if len(results_list) == 0: return [] filtered_list = [] for result in results_list: # check provider returns seeds # get_int(result['seeds']) # append hash result['hash'] = Magnet(result['uri']).info_hash.upper() logger.log.debug(result['hash']) # remove dupes # noinspection PyTypeChecker if len([ item for item in filtered_list if item['hash'].upper() == result['hash'].upper() ]) == 0 or len(result['hash']) == 0: # append item to results filtered_list.append(result) return sorted(filtered_list, key=lambda r: (get_float(r['seeds'])), reverse=True)
def get_sol(self): """Get the solenoid based on debug""" name = np.unicode(self.ui.sol_combo.currentText()) solenoid = Magnet(name=name) if not self._debug else MockMagnet(name=name) return solenoid
def cleanup_results(results_list): """ Remove duplicate results, hash results without an info_hash, and sort by seeders Args: results_list (list): Results to clean-up Returns: list: De-duplicated, hashed and sorted results """ if len(results_list) == 0: return [] hashes = [] filtered_list = [] allow_noseeds = get_setting('allow_noseeds', bool) for result in results_list: if not result['seeds'] and not allow_noseeds: continue provider_name = result['provider'][result['provider'].find(']')+1:result['provider'].find('[/')] if not result['uri']: if not result['name']: continue try: log.warning('[%s] No URI for %s' % (provider_name, repr(result['name']))) except Exception as e: import traceback log.warning("%s logging failed with: %s" % (provider_name, repr(e))) map(log.debug, traceback.format_exc().split("\n")) continue hash_ = result['info_hash'].upper() if not hash_: if result['uri'] and result['uri'].startswith('magnet'): hash_ = Magnet(result['uri']).info_hash.upper() else: hash_ = hashlib.md5(result['uri']).hexdigest() try: log.debug("[%s] Hash for %s: %s" % (provider_name, repr(result['name']), hash_)) except Exception as e: import traceback log.warning("%s logging failed with: %s" % (result['provider'], repr(e))) map(log.debug, traceback.format_exc().split("\n")) if not any(existing == hash_ for existing in hashes): filtered_list.append(result) hashes.append(hash_) if (get_setting("sort_by_resolution", bool)): log.debug("[EXPEREMENTAL] Start last sorting list by resolution of all result before send to Elementum") filtered_list = sorted(filtered_list, key=lambda r: (get_int(r.pop('resolution'))), reverse=True) else: filtered_list = sorted(filtered_list, key=lambda r: (get_int(r['seeds'])), reverse=True) return filtered_list
def cleanup_results(results_list): """ Remove duplicate results, hash results without an info_hash, and sort by seeders Args: results_list (list): Results to clean-up Returns: list: De-duplicated, hashed and sorted results """ if len(results_list) == 0: return [] hashes = [] filtered_list = [] allow_noseeds = get_setting('allow_noseeds', bool) for result in results_list: if not result['seeds'] and not allow_noseeds: continue if not result['uri']: if not result['name']: continue try: log.warning('[%s] No URI for %s' % (result['provider'][16:-8], repr(result['name']))) except Exception as e: import traceback log.warning("%s logging failed with: %s" % (result['provider'], repr(e))) map(log.debug, traceback.format_exc().split("\n")) continue hash_ = result['info_hash'].upper() if not hash_: try: if result['uri'] and result['uri'].startswith('magnet'): hash_ = Magnet(result['uri']).info_hash.upper() else: hash_ = hashlib.md5(py2_encode(result['uri'])).hexdigest() except: pass # try: # log.debug("[%s] Hash for %s: %s" % (result['provider'][16:-8], repr(result['name']), hash_)) # except Exception as e: # import traceback # log.warning("%s logging failed with: %s" % (result['provider'], repr(e))) # map(log.debug, traceback.format_exc().split("\n")) if not any(existing == hash_ for existing in hashes): filtered_list.append(result) hashes.append(hash_) return sorted(filtered_list, key=lambda r: (get_int(r['seeds'])), reverse=True)