Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: Auto tag movies based on tags present/absent on movies
(cherry picked from commit f4c19a384bd9bb4e35c9fa0ca5d9a448c04e409e) Closes #9916
- Loading branch information
1 parent
56be950
commit f7ca0b8
Showing
11 changed files
with
190 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { useCallback } from 'react'; | ||
import TagInputConnector from './TagInputConnector'; | ||
|
||
interface MovieTagInputProps { | ||
name: string; | ||
value: number | number[]; | ||
onChange: ({ | ||
name, | ||
value, | ||
}: { | ||
name: string; | ||
value: number | number[]; | ||
}) => void; | ||
} | ||
|
||
export default function MovieTagInput(props: MovieTagInputProps) { | ||
const { value, onChange, ...otherProps } = props; | ||
const isArray = Array.isArray(value); | ||
|
||
const handleChange = useCallback( | ||
({ name, value: newValue }: { name: string; value: number[] }) => { | ||
if (isArray) { | ||
onChange({ name, value: newValue }); | ||
} else { | ||
onChange({ | ||
name, | ||
value: newValue.length ? newValue[newValue.length - 1] : 0, | ||
}); | ||
} | ||
}, | ||
[isArray, onChange] | ||
); | ||
|
||
let finalValue: number[] = []; | ||
|
||
if (isArray) { | ||
finalValue = value; | ||
} else if (value === 0) { | ||
finalValue = []; | ||
} else { | ||
finalValue = [value]; | ||
} | ||
|
||
return ( | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore 2786 'TagInputConnector' isn't typed yet | ||
<TagInputConnector | ||
{...otherProps} | ||
value={finalValue} | ||
onChange={handleChange} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/NzbDrone.Core/AutoTagging/Specifications/TagSpecification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using FluentValidation; | ||
using NzbDrone.Core.Annotations; | ||
using NzbDrone.Core.Movies; | ||
using NzbDrone.Core.Validation; | ||
|
||
namespace NzbDrone.Core.AutoTagging.Specifications | ||
{ | ||
public class TagSpecificationValidator : AbstractValidator<TagSpecification> | ||
{ | ||
public TagSpecificationValidator() | ||
{ | ||
RuleFor(c => c.Value).GreaterThan(0); | ||
} | ||
} | ||
|
||
public class TagSpecification : AutoTaggingSpecificationBase | ||
{ | ||
private static readonly TagSpecificationValidator Validator = new (); | ||
|
||
public override int Order => 1; | ||
public override string ImplementationName => "Tag"; | ||
|
||
[FieldDefinition(1, Label = "AutoTaggingSpecificationTag", Type = FieldType.MovieTag)] | ||
public int Value { get; set; } | ||
|
||
protected override bool IsSatisfiedByWithoutNegate(Movie movie) | ||
{ | ||
return movie.Tags.Contains(Value); | ||
} | ||
|
||
public override NzbDroneValidationResult Validate() | ||
{ | ||
return new NzbDroneValidationResult(Validator.Validate(this)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters