autobrr/web/src/forms/settings/ReleaseForms.tsx
kenstir 4009554d10
feat(filters): skip duplicates (#1711)
* feat(filters): skip duplicates

* fix: add interface instead of any

* fix(filters): tonullint

* feat(filters): skip dupes check month day

* chore: cleanup

* feat(db): set autoincrement id

* feat(filters): add repack and proper to dupe profile

* feat(filters): add default dupe profiles

* feat(duplicates): check audio and website

* feat(duplicates): update tests

* feat(duplicates): add toggles on addform

* feat(duplicates): fix sqlite upgrade path and initialize duplicate profiles

* feat(duplicates): simplify sqlite upgrade

avoiding temp table and unwieldy select.  Besides, FK constraints
are turned off anyway in #229.

* feat(duplicates): change CheckIsDuplicateRelease treatment of PROPER and REPACK

"Proper" and "Repack" are not parallel to the other conditions like "Title",
so they do not belong as dedup conditions.  "PROPER" means there was an issue in
the previous release, and so a PROPER is never a duplicate, even if it replaces
another PROPER.  Similarly, "REPACK" means there was an issue in the previous
release by that group, and so it is a duplicate only if we previously took a
release from a DIFFERENT group.

I have not removed Proper and Repack from the UI or the schema yet.

* feat(duplicates): update postgres schema to match sqlite

* feat(duplicates): fix web build errors

* feat(duplicates): fix postgres errors

* feat(filters): do leftjoin for duplicate profile

* fix(filters): partial update dupe profile

* go fmt `internal/domain/filter.go`

* feat(duplicates): restore straightforward logic for proper/repack

* feat(duplicates): remove mostly duplicate TV duplicate profiles

Having one profile seems the cleanest.  If somebody wants multiple
resolutions then they can add Resolution to the duplicate profile.
Tested this profile with both weekly episodic releases and daily
show releases.

* feat(release): add db indexes and sub_title

* feat(release): add IsDuplicate tests

* feat(release): update action handler

* feat(release): add more tests for skip duplicates

* feat(duplicates): check audio

* feat(duplicates): add more tests

* feat(duplicates): match edition cut and more

* fix(duplicates): tests

* fix(duplicates): missing imports

* fix(duplicates): tests

* feat(duplicates): handle sub_title edition and language in ui

* fix(duplicates): tests

* feat(duplicates): check name against normalized hash

* fix(duplicates): tests

* chore: update .gitignore to ignore .pnpm-store

* fix: tests

* fix(filters): tests

* fix: bad conflict merge

* fix: update release type in test

* fix: use vendored hot-toast

* fix: release_test.go

* fix: rss_test.go

* feat(duplicates): improve title hashing for unique check

* feat(duplicates): further improve title hashing for unique check with lang

* feat(duplicates): fix tests

* feat(duplicates): add macros IsDuplicate and DuplicateProfile ID and name

* feat(duplicates): add normalized hash match option

* fix: headlessui-state prop warning

* fix(duplicates): add missing year in daily ep normalize

* fix(duplicates): check rejections len

---------

Co-authored-by: ze0s <ze0s@riseup.net>
2024-12-25 22:33:46 +01:00

198 lines
7.8 KiB
TypeScript

/*
* Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors.
* SPDX-License-Identifier: GPL-2.0-or-later
*/
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { APIClient } from "@api/APIClient.ts";
import { ReleaseProfileDuplicateKeys } from "@api/query_keys.ts";
import { toast } from "@components/hot-toast";
import Toast from "@components/notifications/Toast.tsx";
import { SwitchGroupWide, TextFieldWide } from "@components/inputs";
import { SlideOver } from "@components/panels";
import { AddFormProps, UpdateFormProps } from "@forms/_shared";
export function ReleaseProfileDuplicateAddForm({ isOpen, toggle }: AddFormProps) {
const queryClient = useQueryClient();
const addMutation = useMutation({
mutationFn: (profile: ReleaseProfileDuplicate) => APIClient.release.profiles.duplicates.store(profile),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ReleaseProfileDuplicateKeys.lists() });
toast.custom((t) => <Toast type="success" body="Profile was added" t={t} />);
toggle();
},
onError: () => {
toast.custom((t) => <Toast type="error" body="Profile could not be added" t={t} />);
}
});
const onSubmit = (data: unknown) => addMutation.mutate(data as ReleaseProfileDuplicate);
const initialValues: ReleaseProfileDuplicate = {
id: 0,
name: "",
protocol: false,
release_name: false,
hash: false,
title: false,
sub_title: false,
year: false,
month: false,
day: false,
source: false,
resolution: false,
codec: false,
container: false,
dynamic_range: false,
audio: false,
group: false,
season: false,
episode: false,
website: false,
proper: false,
repack: false,
edition: false,
language: false,
};
return (
<SlideOver
type="CREATE"
title="Duplicate Profile"
isOpen={isOpen}
toggle={toggle}
onSubmit={onSubmit}
initialValues={initialValues}
>
{() => (
<div className="py-2 space-y-6 sm:py-0 sm:space-y-0 divide-y divide-gray-200 dark:divide-gray-700">
<TextFieldWide required name="name" label="Name"/>
<SwitchGroupWide name="release_name" label="Release name" description="Full release name" />
<SwitchGroupWide name="hash" label="Hash" description="Normalized hash of the release name. Use with Releae name for exact match" />
<SwitchGroupWide name="title" label="Title" description="Parsed title" />
<SwitchGroupWide name="sub_title" label="Sub Title" description="Parsed Sub Title like Episode Name" />
<SwitchGroupWide name="year" label="Year" />
<SwitchGroupWide name="month" label="Month" description="For daily releases" />
<SwitchGroupWide name="day" label="Day" description="For daily releases" />
<SwitchGroupWide name="source" label="Source" />
<SwitchGroupWide name="resolution" label="Resolution" />
<SwitchGroupWide name="codec" label="Codec" />
<SwitchGroupWide name="container" label="Container" />
<SwitchGroupWide name="dynamic_range" label="Dynamic Range" />
<SwitchGroupWide name="audio" label="Audio" />
<SwitchGroupWide name="group" label="Group" description="Release group" />
<SwitchGroupWide name="season" label="Season" />
<SwitchGroupWide name="episode" label="Episode" />
<SwitchGroupWide name="website" label="Website/Service" description="Services such as AMZN/HULU/NF" />
<SwitchGroupWide name="proper" label="Proper" />
<SwitchGroupWide name="repack" label="Repack" />
<SwitchGroupWide name="edition" label="Edition" />
<SwitchGroupWide name="language" label="Language" />
</div>
)}
</SlideOver>
);
}
export function ReleaseProfileDuplicateUpdateForm({ isOpen, toggle, data: profile }: UpdateFormProps<ReleaseProfileDuplicate>) {
const queryClient = useQueryClient();
const storeMutation = useMutation({
mutationFn: (profile: ReleaseProfileDuplicate) => APIClient.release.profiles.duplicates.store(profile),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ReleaseProfileDuplicateKeys.lists() });
toast.custom((t) => <Toast type="success" body="Profile was added" t={t} />);
toggle();
},
onError: () => {
toast.custom((t) => <Toast type="error" body="Profile could not be added" t={t} />);
}
});
const onSubmit = (data: unknown) => storeMutation.mutate(data as ReleaseProfileDuplicate);
const deleteMutation = useMutation({
mutationFn: (profileId: number) => APIClient.release.profiles.duplicates.delete(profileId),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ReleaseProfileDuplicateKeys.lists() });
queryClient.invalidateQueries({ queryKey: ReleaseProfileDuplicateKeys.detail(profile.id) });
toast.custom((t) => <Toast type="success" body={`Profile ${profile.name} was deleted!`} t={t} />);
toggle();
},
});
const onDelete = () => deleteMutation.mutate(profile.id);
const initialValues: ReleaseProfileDuplicate = {
id: profile.id,
name: profile.name,
protocol: profile.protocol,
release_name: profile.release_name,
hash: profile.hash,
title: profile.title,
sub_title: profile.sub_title,
year: profile.year,
month: profile.month,
day: profile.day,
source: profile.source,
resolution: profile.resolution,
codec: profile.codec,
container: profile.container,
dynamic_range: profile.dynamic_range,
audio: profile.audio,
group: profile.group,
season: profile.season,
episode: profile.episode,
website: profile.website,
proper: profile.proper,
repack: profile.repack,
edition: profile.edition,
language: profile.language,
};
return (
<SlideOver
type="UPDATE"
title="Duplicate Profile"
isOpen={isOpen}
toggle={toggle}
deleteAction={onDelete}
onSubmit={onSubmit}
initialValues={initialValues}
>
{() => (
<div className="py-2 space-y-6 sm:py-0 sm:space-y-0 divide-y divide-gray-200 dark:divide-gray-700">
<TextFieldWide required name="name" label="Name"/>
<SwitchGroupWide name="release_name" label="Release name" description="Full release name" />
<SwitchGroupWide name="hash" label="Hash" description="Normalized hash of the release name. Use with Releae name for exact match" />
<SwitchGroupWide name="title" label="Title" description="Parsed title" />
<SwitchGroupWide name="sub_title" label="Sub Title" description="Parsed Sub Title like Episode Name" />
<SwitchGroupWide name="year" label="Year" />
<SwitchGroupWide name="month" label="Month" description="For daily releases" />
<SwitchGroupWide name="day" label="Day" description="For daily releases" />
<SwitchGroupWide name="source" label="Source" />
<SwitchGroupWide name="resolution" label="Resolution" />
<SwitchGroupWide name="codec" label="Codec" />
<SwitchGroupWide name="container" label="Container" />
<SwitchGroupWide name="dynamic_range" label="Dynamic Range (HDR,DV etc)" />
<SwitchGroupWide name="audio" label="Audio" />
<SwitchGroupWide name="group" label="Group" description="Release group" />
<SwitchGroupWide name="season" label="Season" />
<SwitchGroupWide name="episode" label="Episode" />
<SwitchGroupWide name="website" label="Website/Service" description="Services such as AMZN/HULU/NF" />
<SwitchGroupWide name="repack" label="Repack" />
<SwitchGroupWide name="proper" label="Proper" />
<SwitchGroupWide name="edition" label="Edition and Cut" />
<SwitchGroupWide name="language" label="Language and Region" />
</div>
)}
</SlideOver>
);
}