Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate checker option for selecting highest resolution #4286

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

const findFirstFileByAge = (
Expand Down Expand Up @@ -216,6 +232,13 @@ export const SceneDuplicateChecker: React.FC = () => {
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 = () => {
setSelectedScenes([]);
const checkedArray: Record<string, boolean> = {};
Expand All @@ -236,6 +259,30 @@ export const SceneDuplicateChecker: React.FC = () => {
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) => {
setSelectedScenes([]);

Expand Down Expand Up @@ -715,6 +762,14 @@ export const SceneDuplicateChecker: React.FC = () => {
{intl.formatMessage({ id: "dupe_check.select_none" })}
</Dropdown.Item>

<Dropdown.Item
onClick={() => onSelectLargestResolutionClick()}
>
{intl.formatMessage({
id: "dupe_check.select_all_but_largest_resolution",
})}
</Dropdown.Item>

<Dropdown.Item onClick={() => onSelectLargestClick()}>
{intl.formatMessage({
id: "dupe_check.select_all_but_largest_file",
Expand Down
3 changes: 2 additions & 1 deletion ui/v2.5/src/locales/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@
"search_accuracy_label": "Search Accuracy",
"select_options": "Select Options…",
"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_oldest": "Select the oldest file in the duplicate group",
"select_youngest": "Select the youngest file in the duplicate group",
Expand Down Expand Up @@ -1367,4 +1368,4 @@
"weight_kg": "Weight (kg)",
"years_old": "years old",
"zip_file_count": "Zip File Count"
}
}
Loading