private async Task RemovePlexData() { try { var s = await _settings.GetSettingsAsync(); if (!s.Enable) { return; } const string episodeSQL = "DELETE FROM PlexEpisode"; const string seasonsSql = "DELETE FROM PlexSeasonsContent"; const string mainSql = "DELETE FROM PlexServerContent"; await _plexRepo.ExecuteSql(episodeSQL); await _plexRepo.ExecuteSql(seasonsSql); await _plexRepo.ExecuteSql(mainSql); } catch (Exception e) { _log.LogError(LoggingEvents.MediaReferesh, e, "Refreshing Plex Data Failed"); } }
private async Task RemovePlexData() { try { var s = await _settings.GetSettingsAsync(); if (!s.Enable) { return; } const string episodeSQL = "DELETE FROM PlexEpisode"; const string seasonsSql = "DELETE FROM PlexSeasonsContent"; const string mainSql = "DELETE FROM PlexServerContent"; await _plexRepo.ExecuteSql(episodeSQL); await _plexRepo.ExecuteSql(seasonsSql); await _plexRepo.ExecuteSql(mainSql); await OmbiQuartz.Scheduler.TriggerJob(new JobKey(nameof(IPlexContentSync), "Plex"), new JobDataMap(new Dictionary <string, string> { { "recentlyAddedSearch", "false" } })); } catch (Exception e) { _log.LogError(LoggingEvents.MediaReferesh, e, "Refreshing Plex Data Failed"); } }
private async Task GetEpisodes(PlexServers settings, Directory section) { var currentPosition = 0; var resultCount = settings.EpisodeBatchSize == 0 ? 150 : settings.EpisodeBatchSize; var episodes = await _api.GetAllEpisodes(settings.PlexAuthToken, settings.FullUri, section.key, currentPosition, resultCount); _log.LogInformation(LoggingEvents.PlexEpisodeCacher, $"Total Epsiodes found for {episodes.MediaContainer.librarySectionTitle} = {episodes.MediaContainer.totalSize}"); // Delete all the episodes because we cannot uniquly match an episode to series every time, // see comment below. await _repo.ExecuteSql("DELETE FROM PlexEpisode"); await ProcessEpsiodes(episodes); currentPosition += resultCount; while (currentPosition < episodes.MediaContainer.totalSize) { var ep = await _api.GetAllEpisodes(settings.PlexAuthToken, settings.FullUri, section.key, currentPosition, resultCount); await ProcessEpsiodes(ep); _log.LogInformation(LoggingEvents.PlexEpisodeCacher, $"Processed {resultCount} more episodes. Total Remaining {episodes.MediaContainer.totalSize - currentPosition}"); currentPosition += resultCount; } // we have now finished. _log.LogInformation(LoggingEvents.PlexEpisodeCacher, "We have finished caching the episodes."); await _repo.SaveChangesAsync(); }