Esempio n. 1
0
 def _getmatches(self, files, j):
     if self.size_threshold or self.scan_type in {ScanType.Contents, ScanType.Folders}:
         j = j.start_subjob([2, 8])
         for f in j.iter_with_progress(files, tr("Read size of %d/%d files")):
             f.size # pre-read, makes a smoother progress if read here (especially for bundles)
         if self.size_threshold:
             files = [f for f in files if f.size >= self.size_threshold]
     if self.scan_type in {ScanType.Contents, ScanType.Folders}:
         return engine.getmatches_by_contents(files, j=j)
     else:
         j = j.start_subjob([2, 8])
         kw = {}
         kw['match_similar_words'] = self.match_similar_words
         kw['weight_words'] = self.word_weighting
         kw['min_match_percentage'] = self.min_match_percentage
         if self.scan_type == ScanType.FieldsNoOrder:
             self.scan_type = ScanType.Fields
             kw['no_field_order'] = True
         func = {
             ScanType.Filename: lambda f: engine.getwords(rem_file_ext(f.name)),
             ScanType.Fields: lambda f: engine.getfields(rem_file_ext(f.name)),
             ScanType.Tag: lambda f: [
                 engine.getwords(str(getattr(f, attrname)))
                 for attrname in SCANNABLE_TAGS
                 if attrname in self.scanned_tags
             ],
         }[self.scan_type]
         for f in j.iter_with_progress(files, tr("Read metadata of %d/%d files")):
             logging.debug("Reading metadata of %s", f.path)
             f.words = func(f)
         return engine.getmatches(files, j=j, **kw)
Esempio n. 2
0
 def _tie_breaker(ref, dupe):
     refname = rem_file_ext(ref.name).lower()
     dupename = rem_file_ext(dupe.name).lower()
     if 'copy' in dupename:
         return False
     if 'copy' in refname:
         return True
     if is_same_with_digit(dupename, refname):
         return False
     if is_same_with_digit(refname, dupename):
         return True
     return len(dupe.path) > len(ref.path)
Esempio n. 3
0
 def _tie_breaker(ref, dupe):
     refname = rem_file_ext(ref.name).lower()
     dupename = rem_file_ext(dupe.name).lower()
     if 'copy' in dupename:
         return False
     if 'copy' in refname:
         return True
     if is_same_with_digit(dupename, refname):
         return False
     if is_same_with_digit(refname, dupename):
         return True
     return len(dupe.path) > len(ref.path)
Esempio n. 4
0
 def _getmatches(self, files, j):
     if self.size_threshold:
         j = j.start_subjob([2, 8])
         for f in j.iter_with_progress(files,
                                       tr("Read size of %d/%d files")):
             f.size  # pre-read, makes a smoother progress if read here (especially for bundles)
         files = [f for f in files if f.size >= self.size_threshold]
     if self.scan_type in {
             ScanType.Contents, ScanType.ContentsAudio, ScanType.Folders
     }:
         sizeattr = 'audiosize' if self.scan_type == ScanType.ContentsAudio else 'size'
         return engine.getmatches_by_contents(
             files,
             sizeattr,
             partial=self.scan_type == ScanType.ContentsAudio,
             j=j)
     else:
         j = j.start_subjob([2, 8])
         kw = {}
         kw['match_similar_words'] = self.match_similar_words
         kw['weight_words'] = self.word_weighting
         kw['min_match_percentage'] = self.min_match_percentage
         if self.scan_type == ScanType.FieldsNoOrder:
             self.scan_type = ScanType.Fields
             kw['no_field_order'] = True
         func = {
             ScanType.Filename:
             lambda f: engine.getwords(rem_file_ext(f.name)),
             ScanType.Fields:
             lambda f: engine.getfields(rem_file_ext(f.name)),
             ScanType.Tag:
             lambda f: [
                 engine.getwords(str(getattr(f, attrname)))
                 for attrname in SCANNABLE_TAGS
                 if attrname in self.scanned_tags
             ],
         }[self.scan_type]
         for f in j.iter_with_progress(files,
                                       tr("Read metadata of %d/%d files")):
             logging.debug("Reading metadata of {}".format(str(f.path)))
             f.words = func(f)
         return engine.getmatches(files, j=j, **kw)
Esempio n. 5
0
 def _getmatches(self, files, j):
     if (
         self.size_threshold
         or self.large_size_threshold
         or self.scan_type
         in {
             ScanType.CONTENTS,
             ScanType.FOLDERS,
         }
     ):
         j = j.start_subjob([2, 8])
         for f in j.iter_with_progress(files, tr("Read size of %d/%d files")):
             f.size  # pre-read, makes a smoother progress if read here (especially for bundles)
         if self.size_threshold:
             files = [f for f in files if f.size >= self.size_threshold]
         if self.large_size_threshold:
             files = [f for f in files if f.size <= self.large_size_threshold]
     if self.scan_type in {ScanType.CONTENTS, ScanType.FOLDERS}:
         return engine.getmatches_by_contents(files, bigsize=self.big_file_size_threshold, j=j)
     else:
         j = j.start_subjob([2, 8])
         kw = {}
         kw["match_similar_words"] = self.match_similar_words
         kw["weight_words"] = self.word_weighting
         kw["min_match_percentage"] = self.min_match_percentage
         if self.scan_type == ScanType.FIELDSNOORDER:
             self.scan_type = ScanType.FIELDS
             kw["no_field_order"] = True
         func = {
             ScanType.FILENAME: lambda f: engine.getwords(rem_file_ext(f.name)),
             ScanType.FIELDS: lambda f: engine.getfields(rem_file_ext(f.name)),
             ScanType.TAG: lambda f: [
                 engine.getwords(str(getattr(f, attrname)))
                 for attrname in SCANNABLE_TAGS
                 if attrname in self.scanned_tags
             ],
         }[self.scan_type]
         for f in j.iter_with_progress(files, tr("Read metadata of %d/%d files")):
             logging.debug("Reading metadata of %s", f.path)
             f.words = func(f)
         return engine.getmatches(files, j=j, **kw)
Esempio n. 6
0
def cmp_value(dupe, attrname):
    if attrname == 'name':
        value = rem_file_ext(dupe.name)
    else:
        value = getattr(dupe, attrname, '')
    return value.lower() if isinstance(value, str) else value
Esempio n. 7
0
def cmp_value(dupe, attrname):
    if attrname == 'name':
        value = rem_file_ext(dupe.name)
    else:
        value = getattr(dupe, attrname, '')
    return value.lower() if isinstance(value, str) else value
Esempio n. 8
0
 def extract_value(self, dupe):
     return rem_file_ext(dupe.name)
Esempio n. 9
0
 def extract_value(self, dupe):
     return rem_file_ext(dupe.name)
# === RÉCUPÉRATION DES DOUBLONS ===
print("Scan des doublons ...")
j = j.start_subjob([2, 8])

kw = {}
kw['match_similar_words'] = False
kw['weight_words'] = True
kw['min_match_percentage'] = 65
kw['no_field_order'] = True

scan_type = "filename"

func = {
    "filename":
    lambda f: engine.getwords(rem_file_ext(f.name)),
    "fields":
    lambda f: engine.getfields(rem_file_ext(f.name)),
    "tag":
    lambda f: [
        engine.getwords(str(getattr(f, attrname)))
        for attrname in SCANNABLE_TAGS if attrname in self.scanned_tags
    ],
}[scan_type]

for f in j.iter_with_progress(files,
                              "Lecture des métadonnées de %d/%d fichiers"):
    print('Lecture des métadonnées de ' + f.name)
    f.words = func(f)

doublons = engine.getmatches(files, j=j, **kw)
Esempio n. 11
0
        if case == 'upper':
            result = result.upper()
        else:
            result = result.lower()
        return result

    handlers = {
        'artist': lambda d: do_process(d.artist),
        'album': lambda d: do_process(d.album),
        'year': lambda d: do_process(str(d.year)),
        'genre': lambda d: do_process(d.genre),
        'track': lambda d: do_process('%02d' % d.track, False),
        'title': lambda d: do_process(d.title),
        'extension': lambda d: do_process(d.extension),
        'oldpath': lambda d: do_process(str(d.parent.path), False),
        'oldfilename': lambda d: do_process(rem_file_ext(d.name)),
        'group': handle_group,
        'firstletter': handle_firstletter,
    }
    namingmodel = namingmodel.replace('\\', '/')
    result = AutoResolve(None, '')
    if not case_sensitive:
        result.case_sensitive = False
    files = directory.allfiles
    parent_job.start_job(len(files))
    for song in files:
        new_path_str = process_tokens(namingmodel, handlers, song)
        if song.extension:
            new_path_str = "%s.%s" % (new_path_str, song.extension)
        if (not rename_empty_tag) and ('(none)' in new_path_str):
            new_path = (('(not renamed)', ) + song.path)