mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 12:54:38 +03:00
Duplicate checker option for selecting highest resolution (#4286)
* Added duplicate checker dropdown menu option to allow selecting all except highest resolution.
This commit is contained in:
@@ -177,6 +177,22 @@ export const SceneDuplicateChecker: React.FC = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const findLargestResolutionScene = (group: GQL.SlimSceneDataFragment[]) => {
|
||||||
|
// Get resolution of a scene
|
||||||
|
const sceneResolution = (scene: GQL.SlimSceneDataFragment) => {
|
||||||
|
return scene.files.reduce(
|
||||||
|
(sum: number, f) => sum + (f.height * f.width || 0),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
};
|
||||||
|
// Find scene object with maximum resolution
|
||||||
|
return group.reduce((largest, scene) => {
|
||||||
|
const largestSize = sceneResolution(largest);
|
||||||
|
const currentSize = sceneResolution(scene);
|
||||||
|
return currentSize > largestSize ? scene : largest;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// Helper to get file date
|
// Helper to get file date
|
||||||
|
|
||||||
const findFirstFileByAge = (
|
const findFirstFileByAge = (
|
||||||
@@ -216,6 +232,13 @@ export const SceneDuplicateChecker: React.FC = () => {
|
|||||||
return new Set(codecs).size === 1;
|
return new Set(codecs).size === 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkSameResolution(dataGroup: GQL.SlimSceneDataFragment[]) {
|
||||||
|
const resolutions = dataGroup.map(
|
||||||
|
(s) => s.files[0]?.width * s.files[0]?.height
|
||||||
|
);
|
||||||
|
return new Set(resolutions).size === 1;
|
||||||
|
}
|
||||||
|
|
||||||
const onSelectLargestClick = () => {
|
const onSelectLargestClick = () => {
|
||||||
setSelectedScenes([]);
|
setSelectedScenes([]);
|
||||||
const checkedArray: Record<string, boolean> = {};
|
const checkedArray: Record<string, boolean> = {};
|
||||||
@@ -236,6 +259,30 @@ export const SceneDuplicateChecker: React.FC = () => {
|
|||||||
setCheckedScenes(checkedArray);
|
setCheckedScenes(checkedArray);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onSelectLargestResolutionClick = () => {
|
||||||
|
setSelectedScenes([]);
|
||||||
|
const checkedArray: Record<string, boolean> = {};
|
||||||
|
|
||||||
|
filteredScenes.forEach((group) => {
|
||||||
|
if (chkSafeSelect && !checkSameCodec(group)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Don't select scenes where resolution is identical.
|
||||||
|
if (checkSameResolution(group)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Find the highest resolution scene in group.
|
||||||
|
const highest = findLargestResolutionScene(group);
|
||||||
|
group.forEach((scene) => {
|
||||||
|
if (scene !== highest) {
|
||||||
|
checkedArray[scene.id] = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
setCheckedScenes(checkedArray);
|
||||||
|
};
|
||||||
|
|
||||||
const onSelectByAge = (oldest: boolean) => {
|
const onSelectByAge = (oldest: boolean) => {
|
||||||
setSelectedScenes([]);
|
setSelectedScenes([]);
|
||||||
|
|
||||||
@@ -715,6 +762,14 @@ export const SceneDuplicateChecker: React.FC = () => {
|
|||||||
{intl.formatMessage({ id: "dupe_check.select_none" })}
|
{intl.formatMessage({ id: "dupe_check.select_none" })}
|
||||||
</Dropdown.Item>
|
</Dropdown.Item>
|
||||||
|
|
||||||
|
<Dropdown.Item
|
||||||
|
onClick={() => onSelectLargestResolutionClick()}
|
||||||
|
>
|
||||||
|
{intl.formatMessage({
|
||||||
|
id: "dupe_check.select_all_but_largest_resolution",
|
||||||
|
})}
|
||||||
|
</Dropdown.Item>
|
||||||
|
|
||||||
<Dropdown.Item onClick={() => onSelectLargestClick()}>
|
<Dropdown.Item onClick={() => onSelectLargestClick()}>
|
||||||
{intl.formatMessage({
|
{intl.formatMessage({
|
||||||
id: "dupe_check.select_all_but_largest_file",
|
id: "dupe_check.select_all_but_largest_file",
|
||||||
|
|||||||
@@ -931,6 +931,7 @@
|
|||||||
"search_accuracy_label": "Search Accuracy",
|
"search_accuracy_label": "Search Accuracy",
|
||||||
"select_options": "Select Options…",
|
"select_options": "Select Options…",
|
||||||
"select_all_but_largest_file": "Select every file in each duplicated group, except the largest file",
|
"select_all_but_largest_file": "Select every file in each duplicated group, except the largest file",
|
||||||
|
"select_all_but_largest_resolution": "Select every file in each duplicated group, except the file with highest resolution",
|
||||||
"select_none": "Select None",
|
"select_none": "Select None",
|
||||||
"select_oldest": "Select the oldest file in the duplicate group",
|
"select_oldest": "Select the oldest file in the duplicate group",
|
||||||
"select_youngest": "Select the youngest file in the duplicate group",
|
"select_youngest": "Select the youngest file in the duplicate group",
|
||||||
@@ -1366,4 +1367,4 @@
|
|||||||
"weight_kg": "Weight (kg)",
|
"weight_kg": "Weight (kg)",
|
||||||
"years_old": "years old",
|
"years_old": "years old",
|
||||||
"zip_file_count": "Zip File Count"
|
"zip_file_count": "Zip File Count"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user