Skip to content

Commit

Permalink
Add preference to ignore large files, close #430
Browse files Browse the repository at this point in the history
  • Loading branch information
arsenetar committed Aug 27, 2021
1 parent 809116c commit 3045361
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 4 deletions.
16 changes: 12 additions & 4 deletions core/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,22 @@ def __init__(self):
self.discarded_file_count = 0

def _getmatches(self, files, j):
if self.size_threshold or self.scan_type in {
ScanType.CONTENTS,
ScanType.FOLDERS,
}:
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:
Expand Down Expand Up @@ -202,5 +209,6 @@ def get_dupe_groups(self, files, ignore_list=None, j=job.nulljob):
scan_type = ScanType.FILENAME
scanned_tags = {"artist", "title"}
size_threshold = 0
large_size_threshold = 0
big_file_size_threshold = 0
word_weighting = False
46 changes: 46 additions & 0 deletions core/tests/scanner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def test_default_settings(fake_fileexists):
eq_(s.mix_file_kind, True)
eq_(s.word_weighting, False)
eq_(s.match_similar_words, False)
eq_(s.size_threshold, 0)
eq_(s.large_size_threshold, 0)
eq_(s.big_file_size_threshold, 0)


Expand Down Expand Up @@ -142,6 +144,50 @@ def md5(self):
eq_(len(s.get_dupe_groups(f)), 0)


def test_ignore_file_size(fake_fileexists):
s = Scanner()
s.scan_type = ScanType.CONTENTS
small_size = 10 # 10KB
s.size_threshold = 0
large_size = 100 * 1024 * 1024 # 100MB
s.large_size_threshold = 0
f = [
no("smallignore1", small_size - 1),
no("smallignore2", small_size - 1),
no("small1", small_size),
no("small2", small_size),
no("large1", large_size),
no("large2", large_size),
no("largeignore1", large_size + 1),
no("largeignore2", large_size + 1),
]
f[0].md5 = f[0].md5partial = f[0].md5samples = "smallignore"
f[1].md5 = f[1].md5partial = f[1].md5samples = "smallignore"
f[2].md5 = f[2].md5partial = f[2].md5samples = "small"
f[3].md5 = f[3].md5partial = f[3].md5samples = "small"
f[4].md5 = f[4].md5partial = f[4].md5samples = "large"
f[5].md5 = f[5].md5partial = f[5].md5samples = "large"
f[6].md5 = f[6].md5partial = f[6].md5samples = "largeignore"
f[7].md5 = f[7].md5partial = f[7].md5samples = "largeignore"

r = s.get_dupe_groups(f)
# No ignores
eq_(len(r), 4)
# Ignore smaller
s.size_threshold = small_size
r = s.get_dupe_groups(f)
eq_(len(r), 3)
# Ignore larger
s.size_threshold = 0
s.large_size_threshold = large_size
r = s.get_dupe_groups(f)
eq_(len(r), 3)
# Ignore both
s.size_threshold = small_size
r = s.get_dupe_groups(f)
eq_(len(r), 2)


def test_big_file_partial_hashes(fake_fileexists):
s = Scanner()
s.scan_type = ScanType.CONTENTS
Expand Down
4 changes: 4 additions & 0 deletions qt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ def _update_options(self):
self.model.options["match_similar_words"] = self.prefs.match_similar
threshold = self.prefs.small_file_threshold if self.prefs.ignore_small_files else 0
self.model.options["size_threshold"] = threshold * 1024 # threshold is in KB. The scanner wants bytes
large_threshold = self.prefs.large_file_threshold if self.prefs.ignore_large_files else 0
self.model.options["large_size_threshold"] = (
large_threshold * 1024 * 1024
) # threshold is in MB. The Scanner wants bytes
big_file_size_threshold = self.prefs.big_file_size_threshold if self.prefs.big_file_partial_hashes else 0
self.model.options["big_file_size_threshold"] = (
big_file_size_threshold
Expand Down
6 changes: 6 additions & 0 deletions qt/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def _load_values(self, settings):
self.match_similar = get("MatchSimilar", self.match_similar)
self.ignore_small_files = get("IgnoreSmallFiles", self.ignore_small_files)
self.small_file_threshold = get("SmallFileThreshold", self.small_file_threshold)
self.ignore_large_files = get("IgnoreLargeFiles", self.ignore_large_files)
self.large_file_threshold = get("LargeFileThreshold", self.large_file_threshold)
self.big_file_partial_hashes = get("BigFilePartialHashes", self.big_file_partial_hashes)
self.big_file_size_threshold = get("BigFileSizeThreshold", self.big_file_size_threshold)
self.scan_tag_track = get("ScanTagTrack", self.scan_tag_track)
Expand Down Expand Up @@ -119,6 +121,8 @@ def reset(self):
self.match_similar = False
self.ignore_small_files = True
self.small_file_threshold = 10 # KB
self.ignore_large_files = False
self.large_file_threshold = 1000 # MB
self.big_file_partial_hashes = False
self.big_file_size_threshold = 100 # MB
self.scan_tag_track = False
Expand Down Expand Up @@ -167,6 +171,8 @@ def _save_values(self, settings):
set_("MatchSimilar", self.match_similar)
set_("IgnoreSmallFiles", self.ignore_small_files)
set_("SmallFileThreshold", self.small_file_threshold)
set_("IgnoreLargeFiles", self.ignore_large_files)
set_("LargeFileThreshold", self.large_file_threshold)
set_("BigFilePartialHashes", self.big_file_partial_hashes)
set_("BigFileSizeThreshold", self.big_file_size_threshold)
set_("ScanTagTrack", self.scan_tag_track)
Expand Down
19 changes: 19 additions & 0 deletions qt/se/preferences_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ def _setupPreferenceWidgets(self):
spacer_item1 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
self.horizontalLayout_2.addItem(spacer_item1)
self.verticalLayout_4.addLayout(self.horizontalLayout_2)
self.horizontalLayout_2a = QHBoxLayout()
self._setupAddCheckbox("ignoreLargeFilesBox", tr("Ignore files larger than"), self.widget)
self.horizontalLayout_2a.addWidget(self.ignoreLargeFilesBox)
self.sizeSaturationSpinBox = QSpinBox(self.widget)
size_policy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
self.sizeSaturationSpinBox.setSizePolicy(size_policy)
self.sizeSaturationSpinBox.setMaximumSize(QSize(100, 16777215))
self.sizeSaturationSpinBox.setRange(0, 1000000)
self.horizontalLayout_2a.addWidget(self.sizeSaturationSpinBox)
self.label_6a = QLabel(self.widget)
self.label_6a.setText(tr("MB"))
self.horizontalLayout_2a.addWidget(self.label_6a)
spacer_item3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
self.horizontalLayout_2a.addItem(spacer_item3)
self.verticalLayout_4.addLayout(self.horizontalLayout_2a)
self.horizontalLayout_2b = QHBoxLayout()
self._setupAddCheckbox(
"bigFilePartialHashesBox",
Expand Down Expand Up @@ -98,6 +113,8 @@ def _load(self, prefs, setchecked, section):
setchecked(self.wordWeightingBox, prefs.word_weighting)
setchecked(self.ignoreSmallFilesBox, prefs.ignore_small_files)
self.sizeThresholdSpinBox.setValue(prefs.small_file_threshold)
setchecked(self.ignoreLargeFilesBox, prefs.ignore_large_files)
self.sizeSaturationSpinBox.setValue(prefs.large_file_threshold)
setchecked(self.bigFilePartialHashesBox, prefs.big_file_partial_hashes)
self.bigSizeThresholdSpinBox.setValue(prefs.big_file_size_threshold)

Expand All @@ -113,5 +130,7 @@ def _save(self, prefs, ischecked):
prefs.word_weighting = ischecked(self.wordWeightingBox)
prefs.ignore_small_files = ischecked(self.ignoreSmallFilesBox)
prefs.small_file_threshold = self.sizeThresholdSpinBox.value()
prefs.ignore_large_files = ischecked(self.ignoreLargeFilesBox)
prefs.large_file_threshold = self.sizeSaturationSpinBox.value()
prefs.big_file_partial_hashes = ischecked(self.bigFilePartialHashesBox)
prefs.big_file_size_threshold = self.bigSizeThresholdSpinBox.value()

0 comments on commit 3045361

Please sign in to comment.