diff --git a/PlexRequests.Api/PlexApi.cs b/PlexRequests.Api/PlexApi.cs index d220211f1..1084cc40b 100644 --- a/PlexRequests.Api/PlexApi.cs +++ b/PlexRequests.Api/PlexApi.cs @@ -224,7 +224,7 @@ namespace PlexRequests.Api var request = new RestRequest { Method = Method.GET, - Resource = "/library/metadata/{ratingKey}/allLeaves" + Resource = "/library/metadata/{ratingKey}" }; request.AddUrlSegment("ratingKey", ratingKey); diff --git a/PlexRequests.Services/Jobs/PlexAvailabilityChecker.cs b/PlexRequests.Services/Jobs/PlexAvailabilityChecker.cs index 450c93ed2..5f7afd151 100644 --- a/PlexRequests.Services/Jobs/PlexAvailabilityChecker.cs +++ b/PlexRequests.Services/Jobs/PlexAvailabilityChecker.cs @@ -244,13 +244,11 @@ namespace PlexRequests.Services.Jobs var episodes = Cache.Get>(CacheKeys.PlexEpisodes); if (episodes == null) { - Log.Trace("Episode is not available. tvdbid: {0}, season: {1}, episode: {2}",theTvDbId, season, episode); + Log.Info("Episode cache info is not available. tvdbid: {0}, season: {1}, episode: {2}",theTvDbId, season, episode); return false; } foreach (var result in episodes) { - Log.Trace("Result:"); - Log.Trace(result.DumpJson()); if (result.Episodes.ProviderId.Equals(theTvDbId) && result.Episodes.EpisodeNumber == episode && result.Episodes.SeasonNumber == season) { return true; diff --git a/PlexRequests.Services/Jobs/PlexEpisodeCacher.cs b/PlexRequests.Services/Jobs/PlexEpisodeCacher.cs index 64dc95527..2c69f1344 100644 --- a/PlexRequests.Services/Jobs/PlexEpisodeCacher.cs +++ b/PlexRequests.Services/Jobs/PlexEpisodeCacher.cs @@ -59,11 +59,12 @@ namespace PlexRequests.Services.Jobs private ICacheProvider Cache { get; } private IJobRecord Job { get; } private const int ResultCount = 25; + private const string PlexType = "episode"; public void CacheEpisodes() { - var results = new List(); + var results = new PlexSearch(); var settings = Plex.GetSettings(); var sections = PlexApi.GetLibrarySections(settings.PlexAuthToken, settings.FullUri); var tvSection = sections.Directories.FirstOrDefault(x => x.type.Equals(PlexMediaType.Show.ToString(), StringComparison.CurrentCultureIgnoreCase)); @@ -73,29 +74,28 @@ namespace PlexRequests.Services.Jobs int totalSize; var episodes = PlexApi.GetAllEpisodes(settings.PlexAuthToken, settings.FullUri, tvSectionId, currentPosition, ResultCount); - results.Add(episodes); + results = episodes; int.TryParse(episodes.TotalSize, out totalSize); - + currentPosition += ResultCount; while (currentPosition < totalSize) { - results.Add(PlexApi.GetAllEpisodes(settings.PlexAuthToken, settings.FullUri, tvSectionId, currentPosition, ResultCount)); + results.Video.AddRange(PlexApi.GetAllEpisodes(settings.PlexAuthToken, settings.FullUri, tvSectionId, currentPosition, ResultCount).Video); currentPosition += ResultCount; } - + var filteredList = results.Video.Where(x => x.Type.Equals(PlexType, StringComparison.InvariantCultureIgnoreCase)); var episodesModel = new List(); var metadataList = new List(); - foreach (var r in results) + + foreach (var video in filteredList) { - foreach (var video in r.Video) - { - var ratingKey = video.RatingKey; - var metadata = PlexApi.GetEpisodeMetaData(settings.PlexAuthToken, settings.FullUri, ratingKey); - metadataList.Add(metadata); - } + var ratingKey = video.RatingKey; + var metadata = PlexApi.GetEpisodeMetaData(settings.PlexAuthToken, settings.FullUri, ratingKey); + metadataList.Add(metadata); } + foreach (var m in metadataList) { foreach (var video in m.Video) @@ -111,7 +111,7 @@ namespace PlexRequests.Services.Jobs } - if (results.Any()) + if (results.Video.Any()) { Cache.Set(CacheKeys.PlexEpisodes, episodesModel, CacheKeys.TimeFrameMinutes.SchedulerCaching); } diff --git a/PlexRequests.UI/Modules/SearchModule.cs b/PlexRequests.UI/Modules/SearchModule.cs index 2ed91705e..06bab8857 100644 --- a/PlexRequests.UI/Modules/SearchModule.cs +++ b/PlexRequests.UI/Modules/SearchModule.cs @@ -951,11 +951,13 @@ namespace PlexRequests.UI.Modules { var seriesId = (int)Request.Query.tvId; var s = await SonarrService.GetSettingsAsync(); + var sonarrEnabled = s.Enabled; var allResults = await RequestService.GetAllAsync(); + var seriesTask = Task.Run( () => { - if (s.Enabled) + if (sonarrEnabled) { var allSeries = SonarrApi.GetSeries(s.ApiKey, s.FullUri); var selectedSeries = allSeries.FirstOrDefault(x => x.tvdbId == seriesId) ?? new Series(); @@ -972,9 +974,13 @@ namespace PlexRequests.UI.Modules var show = await Task.Run(() => TvApi.ShowLookupByTheTvDbId(seriesId)); var seasons = await Task.Run(() => TvApi.EpisodeLookup(show.id)); - var sonarrSeries = await seriesTask; - var sonarrEp = SonarrApi.GetEpisodes(sonarrSeries.id.ToString(), s.ApiKey, s.FullUri); - var sonarrEpisodes = sonarrEp?.ToList() ?? new List(); + var sonarrEpisodes = new List(); + if (sonarrEnabled) + { + var sonarrSeries = await seriesTask; + var sonarrEp = SonarrApi.GetEpisodes(sonarrSeries.id.ToString(), s.ApiKey, s.FullUri); + sonarrEpisodes = sonarrEp?.ToList() ?? new List(); + } foreach (var ep in seasons) {