mirror of
https://github.com/Readarr/Readarr
synced 2026-01-10 01:24:08 +01:00
New: Use ISO 639-3 language codes in metadata profile
This commit is contained in:
parent
7c10f3a74d
commit
7a969a63e4
5 changed files with 20 additions and 3 deletions
|
|
@ -173,6 +173,7 @@ function EditMetadataProfileModalContent(props) {
|
|||
type={inputTypes.TEXT}
|
||||
name="allowedLanguages"
|
||||
{...allowedLanguages}
|
||||
helpText={translate('Iso639-3')}
|
||||
onChange={onInputChange}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
|
|
|||
|
|
@ -13,12 +13,16 @@ public static class Extensions
|
|||
private static readonly Dictionary<string, string> ByThree;
|
||||
private static readonly Dictionary<string, string> NameMap;
|
||||
|
||||
public static HashSet<string> KnownLanguages { get; }
|
||||
|
||||
static Extensions()
|
||||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
TwoToThree = InitializeDictionary(assembly, "2to3.json");
|
||||
ByThree = InitializeDictionary(assembly, "by3.json");
|
||||
NameMap = InitializeDictionary(assembly, "name_map.json");
|
||||
|
||||
KnownLanguages = ByThree.Keys.ToHashSet();
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> InitializeDictionary(Assembly assembly, string resource)
|
||||
|
|
|
|||
|
|
@ -305,6 +305,7 @@
|
|||
"IsExpandedShowFileInfo": "Show file info",
|
||||
"IsInUseCantDeleteAMetadataProfileThatIsAttachedToAnAuthorOrImportList": "Can't delete a metadata profile that is attached to an author or import list",
|
||||
"IsInUseCantDeleteAQualityProfileThatIsAttachedToAnAuthorOrImportList": "Can't delete a quality profile that is attached to an author or import list",
|
||||
"Iso639-3": "ISO 639-3 language codes, or 'null', comma separated",
|
||||
"IsShowingMonitoredMonitorSelected": "Monitor Selected",
|
||||
"IsShowingMonitoredUnmonitorSelected": "Unmonitor Selected",
|
||||
"IsTagUsedCannotBeDeletedWhileInUse": "Cannot be deleted while in use",
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Books;
|
||||
using NzbDrone.Core.Books.Calibre;
|
||||
using NzbDrone.Core.ImportLists;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
|
|
@ -173,14 +174,14 @@ private List<Book> FilterBooks(IEnumerable<Book> remoteBooks, List<Book> localBo
|
|||
|
||||
private List<Edition> FilterEditions(IEnumerable<Edition> editions, List<Edition> localEditions, List<BookFile> localFiles, MetadataProfile profile)
|
||||
{
|
||||
var allowedLanguages = profile.AllowedLanguages.IsNotNullOrWhiteSpace() ? new HashSet<string>(profile.AllowedLanguages.Split(',').Select(x => x.Trim().ToLower())) : new HashSet<string>();
|
||||
var allowedLanguages = profile.AllowedLanguages.IsNotNullOrWhiteSpace() ? new HashSet<string>(profile.AllowedLanguages.Trim(',').Split(',').Select(x => x.CanonicalizeLanguage())) : new HashSet<string>();
|
||||
|
||||
var hash = new HashSet<Edition>(editions);
|
||||
|
||||
var localHash = new HashSet<string>(localEditions.Where(x => x.ManualAdd).Select(x => x.ForeignEditionId));
|
||||
localHash.UnionWith(localFiles.Select(x => x.Edition.Value.ForeignEditionId));
|
||||
|
||||
FilterByPredicate(hash, x => x.ForeignEditionId, localHash, profile, (x, p) => !allowedLanguages.Any() || allowedLanguages.Contains(x.Language?.ToLower() ?? "null"), "edition language not allowed");
|
||||
FilterByPredicate(hash, x => x.ForeignEditionId, localHash, profile, (x, p) => !allowedLanguages.Any() || allowedLanguages.Contains(x.Language?.CanonicalizeLanguage() ?? "null"), "edition language not allowed");
|
||||
FilterByPredicate(hash, x => x.ForeignEditionId, localHash, profile, (x, p) => !p.SkipMissingIsbn || x.Isbn13.IsNotNullOrWhiteSpace() || x.Asin.IsNotNullOrWhiteSpace(), "isbn and asin is missing");
|
||||
FilterByPredicate(hash, x => x.ForeignEditionId, localHash, profile, (x, p) => !MatchesTerms(x.Title, p.Ignored), "contains ignored terms");
|
||||
|
||||
|
|
@ -272,7 +273,7 @@ public void Handle(ApplicationStartedEvent message)
|
|||
MinPopularity = 350,
|
||||
SkipMissingDate = true,
|
||||
SkipPartsAndSets = true,
|
||||
AllowedLanguages = "eng, en-US, en-GB, null"
|
||||
AllowedLanguages = "eng, null"
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentValidation;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
using NzbDrone.Http.REST.Attributes;
|
||||
using Readarr.Http;
|
||||
|
|
@ -17,6 +19,14 @@ public MetadataProfileController(IMetadataProfileService profileService)
|
|||
{
|
||||
_profileService = profileService;
|
||||
SharedValidator.RuleFor(c => c.Name).NotEqual("None").WithMessage("'None' is a reserved profile name").NotEmpty();
|
||||
SharedValidator.RuleFor(c => c.AllowedLanguages)
|
||||
.Must(x => x
|
||||
.Trim(',')
|
||||
.Split(',')
|
||||
.Select(y => y.Trim())
|
||||
.All(y => y == "null" || NzbDrone.Core.Books.Calibre.Extensions.KnownLanguages.Contains(y)))
|
||||
.When(x => x.AllowedLanguages.IsNotNullOrWhiteSpace())
|
||||
.WithMessage("Unknown languages");
|
||||
}
|
||||
|
||||
[RestPostById]
|
||||
|
|
|
|||
Loading…
Reference in a new issue