def search(self): if not self.searchButton.isEnabled(): return files = self._status['selectedfiles'] if self.curSource.group_by: group = split_by_field(files, *self.curSource.group_by) self.label.setText(translate("WebDB", 'Searching...')) text = None if self.searchEdit.text() and self.searchEdit.isEnabled(): text = unicode(self.searchEdit.text()) elif not files: self.label.setText(translate("WebDB", '<b>Select some files or enter search paramaters.</b>')) return def search(): try: ret = [] if text: return self.curSource.keyword_search(text), None else: return tag_source_search(self.curSource, group, files) except RetrievalError, e: return translate('WebDB', 'An error occured: %1').arg(unicode(e)) except Exception, e: traceback.print_exc() return translate('WebDB', 'An unhandled error occurred: %1').arg(unicode(e))
def find_best(matches, files, minimum=0.7): group = split_by_field(files, 'album', 'artist') album = group.keys()[0] artists = group[album].keys() if len(artists) == 1: artist = artists[0] else: artist = VARIOUS d = {'artist': artist, 'album': album} scores = {} for match in matches: if hasattr(match, 'info'): info = match.info else: info = match[0] score = min([ratio_compare(d, info, key) for key in d]) if score in scores: score = score + 0.01 #For albums that have same name. scores[score] = match tracks = match.tracks if hasattr(match, 'tracks') else match[1] if tracks and score < minimum: if len(tracks) == len(files): scores[minimum + 0.01] = match if scores: return [ scores[z] for z in sorted(scores, reverse=True) if z >= minimum ] else: return []
def find_best(matches, files, minimum=0.7): group = split_by_field(files, 'album', 'artist') album = group.keys()[0] artists = group[album].keys() if len(artists) == 1: artist = artists[0] else: artist = VARIOUS d = {'artist': artist, 'album': album} scores = {} for match in matches: if hasattr(match, 'info'): info = match.info else: info = match[0] score = min([ratio_compare(d, info, key) for key in d]) if score in scores: score = score + 0.01 #For albums that have same name. scores[score] = match tracks = match.tracks if hasattr(match, 'tracks') else match[1] if tracks and score < minimum: if len(tracks) == len(files): scores[minimum + 0.01] = match if scores: return [scores[z] for z in sorted(scores, reverse=True) if z >= minimum] else: return []
def search(self): if not self.searchButton.isEnabled(): return files = self._status['selectedfiles'] if self.curSource.group_by: group = split_by_field(files, *self.curSource.group_by) self.label.setText(translate("WebDB", 'Searching...')) text = None if self.searchEdit.text() and self.searchEdit.isEnabled(): text = unicode(self.searchEdit.text()) elif not files: self.label.setText( translate( "WebDB", '<b>Select some files or enter search paramaters.</b>')) return def search(): try: ret = [] if text: return self.curSource.keyword_search(text), None else: return tag_source_search(self.curSource, group, files) except RetrievalError, e: return translate('WebDB', 'An error occured: %1').arg(unicode(e)) except Exception, e: traceback.print_exc() return translate('WebDB', 'An unhandled error occurred: %1').arg( unicode(e))
def get_artist_album(files): tags = split_by_field(files, 'album', 'artist') album = tags.keys()[0] artists = tags[album] if len(artists) > 1: return VARIOUS, album else: return list(artists)[0], album
def get_artist_album(files): tags = split_by_field(files, 'album', 'artist') album = tags.keys()[0] artists = tags[album] if len(artists) > 1: return VARIOUS, album else: return list(artists)[0], album
def search(self, files=None, tag_source=None): tag_source = self.tag_source if tag_source is None else tag_source files = self.files if files is None else files assert hasattr(tag_source, 'search') assert files files = split_by_field(files, *tag_source.group_by) search_value = files.keys()[0] self.results = map(lambda x: Result(*x), tag_source.search(search_value, files[search_value])) for r in self.results: r.tag_source = self.tag_source return self.results
def search(self, files=None, tag_source=None): tag_source = self.tag_source if tag_source is None else tag_source files = self.files if files is None else files assert hasattr(tag_source, 'search') assert files files = split_by_field(files, *tag_source.group_by) search_value = files.keys()[0] self.results = map( lambda x: Result(*x), tag_source.search(search_value, files[search_value])) for r in self.results: r.tag_source = self.tag_source return self.results