public async Task Process(bool isPreview, RadarrConfiguration config)
    {
        _cache.Load();

        await _guideProcessor.BuildGuideDataAsync(config.CustomFormats.AsReadOnly(), _cache.CfCache);

        if (!ValidateGuideDataAndCheckShouldProceed(config))
        {
            return;
        }

        if (isPreview)
        {
            PreviewCustomFormats();
        }
        else
        {
            await _persistenceProcessor.PersistCustomFormats(_guideProcessor.ProcessedCustomFormats,
                                                             _guideProcessor.DeletedCustomFormatsInCache, _guideProcessor.ProfileScores);

            PrintApiStatistics(_persistenceProcessor.Transactions);
            PrintQualityProfileUpdates();

            // Cache all the custom formats (using ID from API response).
            _cache.Update(_guideProcessor.ProcessedCustomFormats);
            _cache.Save();
        }

        _persistenceProcessor.Reset();
        _guideProcessor.Reset();
    }
    private bool ValidateGuideDataAndCheckShouldProceed(RadarrConfiguration config)
    {
        Console.WriteLine("");

        if (_guideProcessor.DuplicatedCustomFormats.Count > 0)
        {
            Log.Warning("One or more of the custom formats you want are duplicated in the guide. These custom " +
                        "formats WILL BE SKIPPED. Trash Updater is not able to choose which one you actually " +
                        "wanted. To resolve this ambiguity, use the `trash_ids` property in your YML " +
                        "configuration to refer to the custom format using its Trash ID instead of its name");

            foreach (var(cfName, dupes) in _guideProcessor.DuplicatedCustomFormats)
            {
                Log.Warning("{CfName} is duplicated {DupeTimes} with the following Trash IDs:", cfName,
                            dupes.Count);
                foreach (var cf in dupes)
                {
                    Log.Warning(" - {TrashId}", cf.TrashId);
                }
            }

            Console.WriteLine("");
        }

        if (_guideProcessor.CustomFormatsNotInGuide.Count > 0)
        {
            Log.Warning("The Custom Formats below do not exist in the guide and will " +
                        "be skipped. Names must match the 'name' field in the actual JSON, not the header in " +
                        "the guide! Either fix the names or remove them from your YAML config to resolve this " +
                        "warning");
            Log.Warning("{CfList}", _guideProcessor.CustomFormatsNotInGuide);

            Console.WriteLine("");
        }

        var cfsWithoutQualityProfiles = _guideProcessor.ConfigData
                                        .Where(d => d.QualityProfiles.Count == 0)
                                        .SelectMany(d => d.CustomFormats.Select(cf => cf.Name))
                                        .ToList();

        if (cfsWithoutQualityProfiles.Count > 0)
        {
            Log.Debug("These custom formats will be uploaded but are not associated to a quality profile in the " +
                      "config file: {UnassociatedCfs}", cfsWithoutQualityProfiles);

            Console.WriteLine("");
        }

        // No CFs are defined in this item, or they are all invalid. Skip this whole instance.
        if (_guideProcessor.ConfigData.Count == 0)
        {
            Log.Error("Guide processing yielded no custom formats for configured instance host {BaseUrl}",
                      config.BaseUrl);
            return(false);
        }

        if (_guideProcessor.CustomFormatsWithoutScore.Count > 0)
        {
            Log.Warning("The below custom formats have no score in the guide or YAML " +
                        "config and will be skipped (remove them from your config or specify a " +
                        "score to fix this warning)");
            foreach (var tuple in _guideProcessor.CustomFormatsWithoutScore)
            {
                Log.Warning("{CfList}", tuple);
            }

            Console.WriteLine("");
        }

        if (_guideProcessor.CustomFormatsWithOutdatedNames.Count > 0)
        {
            Log.Warning("One or more custom format names in your YAML config have been renamed in the guide and " +
                        "are outdated. Each outdated name will be listed below. These custom formats will refuse " +
                        "to sync if your cache is deleted. To fix this warning, rename each one to its new name");

            foreach (var(oldName, newName) in _guideProcessor.CustomFormatsWithOutdatedNames)
            {
                Log.Warning(" - '{OldName}' -> '{NewName}'", oldName, newName);
            }

            Console.WriteLine("");
        }

        return(true);
    }
Beispiel #3
0
        public async Task Process(IRadarrCommand args, RadarrConfiguration config)
        {
            Log.Information("Processing Quality Definition: {QualityDefinition}", config.QualityDefinition !.Type);
            var qualityDefinitions = _parser.ParseMarkdown(await _parser.GetMarkdownData());

            var selectedQuality = qualityDefinitions[config.QualityDefinition !.Type];