public async Task <IReadOnlyCollection <PlexTvShow> > GetTvShowsAsync(PlexServer server) { _logger.LogInformation($"Retrieving plex tv shows from server {server.Name}."); var libraries = await _plexClient.GetLibraries(server.AccessToken, server.Host); var tvDirectories = libraries.MediaContainer.Directory.Where(x => x.Type == "show").ToList(); var tvShowMetadata = (await Task.WhenAll(tvDirectories.Select(d => _plexClient.GetLibrary(server.AccessToken, server.Host, d.Key)))).SelectMany(x => x.MediaContainer.Metadata).ToList(); var tvShows = tvShowMetadata.Select(metadata => new PlexTvShow(metadata.Title, metadata.Year, metadata.RatingKey)); return(tvShows.ToList()); }
private Plex.Api.Models.PlexMediaContainer GetLibrary(string libraryName) { var plexServer = GetPreferredServer(); var fullURL = plexServer.FullUri.ToString(); var plexMediaContainer = plexApi.GetLibraries(plexServer.AccessToken, fullURL).Result; //If this errors for "forcibly closed by the remote host", go to your Plex settings, choose "Network" and set it to "Preferred". //If it is set to "required", it will error for not using https. But the HTTPS cert for the IP is not valid. var library = plexMediaContainer.MediaContainer.Directory.FirstOrDefault(c => c.Title == libraryName); if (library == null) { return(null); } return(plexApi.GetLibrary(plexServer.AccessToken, fullURL, library.Key).Result); }
public async Task <List <Directory> > GetLibraries(string authKey, string plexServerHost) { var container = await _plexClient.GetLibraries(authKey, plexServerHost); return(container?.MediaContainer?.Directory); }