Ejemplo n.º 1
0
        public async Task CacheContent(bool recentlyAddedSearch = false)
        {
            var plexSettings = await Plex.GetSettingsAsync();

            if (!plexSettings.Enable)
            {
                return;
            }
            if (!ValidateSettings(plexSettings))
            {
                Logger.LogError("Plex Settings are not valid");
                return;
            }
            var processedContent = new ProcessedContent();

            Logger.LogInformation("Starting Plex Content Cacher");
            try
            {
                if (recentlyAddedSearch)
                {
                    processedContent = await StartTheCache(plexSettings, true);
                }
                else
                {
                    await StartTheCache(plexSettings, false);
                }
            }
            catch (Exception e)
            {
                Logger.LogWarning(LoggingEvents.PlexContentCacher, e, "Exception thrown when attempting to cache the Plex Content");
            }

            if (!recentlyAddedSearch)
            {
                Logger.LogInformation("Starting EP Cacher");
                BackgroundJob.Enqueue(() => EpisodeSync.Start());
            }

            if ((processedContent?.HasProcessedContent ?? false) && recentlyAddedSearch)
            {
                // Just check what we send it
                BackgroundJob.Enqueue(() => Metadata.ProcessPlexServerContent(processedContent.Content));
            }

            if ((processedContent?.HasProcessedEpisodes ?? false) && recentlyAddedSearch)
            {
                BackgroundJob.Enqueue(() => Checker.Start());
            }
        }