def old_find_torrentfile(self, the_path): # get the file / foldername (not necc. the same as the arg itself split_path = the_path.rsplit('/') arg_name = split_path[-1] the_torrentfiles = [ f for f in os.listdir(get_torrentfilesdir(self.global_conf)) if not f == '.keep' ] exclude = [c['torrentfile'] for c in self.commands] tfiles = [] for tfile in the_torrentfiles: if tfile in exclude: continue cf = self.filenamer.convert_filename( tfile.rstrip('torrent').rstrip('.'), True, interactive=False) score = SequenceMatcher('', str2utf8(arg_name), str2utf8(cf)).ratio() tfiles += [{'filename': tfile, 'conv_filename': cf, 'score': score}] tfiles = sorted(tfiles, self.compare_scored_tfiles) chosen_torrentfile = optionator('For: ' + arg_name, [t['filename'] for t in tfiles] + [CANCEL]) return chosen_torrentfile
def remove_zwsp(filename): """ removes Zero Width Spaces from a string. Returns in UTF-8. HERE BE DRAGONS """ zwsp = '\u200b' ufilename = str2utf8(filename) while zwsp in ufilename: ufilename.replace(zwsp, '') return ufilename