def load_window(parent): import puddlestuff.libraries.quodlibetlib as quodlibet from puddlestuff.constants import HOMEDIR lib = quodlibet.QuodLibet(os.path.join(HOMEDIR, '.quodlibet/songs') from Levenshtein import ratio algos = [Algo(['artist', 'title'], 0.80, ratio), Algo(['artist', 'title'], 0.70, ratio)] qb = parent.addDock('Duplicates', DupeTree, RIGHTDOCK, connect=True) qb.loadDupes(lib, algos, ['%artist% - %title%', '%title%']) def init(parent=None): action = QAction('Dupes in Lib', parent) #if not status['library']: #action.setEnabled(False) parent.connect(action, SIGNAL('triggered()'), lambda: load_window(parent)) add_shortcuts('&Tools', [action]) if __name__ == "__main__": import puddlestuff.libraries.quodlibetlib as quodlibet from puddlestuff.constants import HOMEDIR lib = quodlibet.QuodLibet(os.path.join(HOMEDIR, '.quodlibet/songs') from Levenshtein import ratio algos = [Algo(['artist', 'title'], 0.80, ratio), Algo(['artist', 'title'], 0.70, ratio)] app = QApplication(sys.argv) qb = DupeTree() qb.show() QApplication.processEvents() qb.loadDupes(lib, algos, ['%artist% - %title%', '%title%']) app.exec_()
def loadsets(): algos = [] if not os.path.exists(DUPEDIR): os.makedirs(DUPEDIR) saveset(**DEFAULTSET) files = [os.path.join(DUPEDIR, z) for z in os.listdir(DUPEDIR)] sets = [] cparser = PuddleConfig() for f in files: cparser.filename = f name = cparser.get('info', 'name', '') disp = cparser.get('info', 'disp', []) algos = [] for section in cparser.sections(): if section == 'info': continue tags = cparser.get(section, 'tags', []) threshold = float(cparser.get(section, 'threshold', '0.85')) func = cparser.get(section, 'func', '') matchcase = cparser.get(section, 'matchcase', True) maintag = cparser.get(section, 'maintag', 'artist') algos.append(Algo(tags, threshold, func, matchcase)) sets.append([name, disp, algos, maintag]) return sets
def saveAlgo(self): tags = [x for x in [z.strip() for z in unicode(self.tags.text()).split("|")] if x != ""] func = funcs[self.alcombo.currentIndex()] threshold = float(unicode(self.threshold.text())) / 100 matchcase = False if self.matchcase.checkState() == Qt.Checked: matchcase = True return Algo(tags, threshold, func, matchcase)
from decimal import Decimal from puddlestuff.puddleobjects import ListButtons, ListBox, OKCancel, PuddleConfig from matchfuncs import Algo, funcinfo, funcs, _ratio from dupefuncs import dupesinlib from puddlestuff.findfunc import tagtofilename from puddlestuff.puddleobjects import progress, winsettings import time from puddlestuff.constants import SAVEDIR, RIGHTDOCK from puddlestuff.plugins import add_shortcuts, connect_shortcut from puddlestuff.puddletag import status title_sort = lambda a: a.get('title', u'') dupe_sort = lambda a: a[0].get('title', u'') DEFAULTSET = {'setname': 'Default', 'algs': [Algo(['artist', 'title'], 0.85, _ratio, False)], 'disp': ['%artist%', '%artist% - %title%'], 'maintag': 'artist'} DUPEDIR = os.path.join(SAVEDIR, 'dupes') def saveset(setname, disp, algs, maintag): cparser = PuddleConfig() filename = os.path.join(DUPEDIR, setname) open(filename, 'w').close() #I have to clear the file because if a previous #set had more algos then the extra algos will get loaded. cparser.filename = filename algs = [{'tags': a.tags, 'threshold': a.threshold, 'func': a.func.__name__, 'matchcase': a.matchcase, 'maintag': maintag} for a in algs]