-
-
Notifications
You must be signed in to change notification settings - Fork 242
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 artists based on tags present/absent on artists
(cherry picked from commit f4c19a384bd9bb4e35c9fa0ca5d9a448c04e409e) Closes #4742
- Loading branch information
1 parent
8c09c0c
commit b14e2bb
Showing
11 changed files
with
188 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { useCallback } from 'react'; | ||
import TagInputConnector from './TagInputConnector'; | ||
|
||
interface ArtistTagInputProps { | ||
name: string; | ||
value: number | number[]; | ||
onChange: ({ | ||
name, | ||
value, | ||
}: { | ||
name: string; | ||
value: number | number[]; | ||
}) => void; | ||
} | ||
|
||
export default function ArtistTagInput(props: ArtistTagInputProps) { | ||
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
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.Music; | ||
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.ArtistTag)] | ||
public int Value { get; set; } | ||
|
||
protected override bool IsSatisfiedByWithoutNegate(Artist artist) | ||
{ | ||
return artist.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