public async Task<DynamicImageResponse> GetImage(IHasImages item, ImageType type, CancellationToken cancellationToken) { var liveTvItem = (LiveTvChannel)item; var imageResponse = new DynamicImageResponse(); var service = _liveTvManager.Services.FirstOrDefault(i => string.Equals(i.Name, liveTvItem.ServiceName, StringComparison.OrdinalIgnoreCase)); if (service != null && !item.HasImage(ImageType.Primary)) { try { var response = await service.GetChannelImageAsync(liveTvItem.ExternalId, cancellationToken).ConfigureAwait(false); if (response != null) { imageResponse.HasImage = true; imageResponse.Stream = response.Stream; imageResponse.Format = response.Format; } } catch (NotImplementedException) { } } return imageResponse; }
public async Task<DynamicImageResponse> GetImage(IHasImages item, ImageType type, CancellationToken cancellationToken) { var channelItem = (IChannelItem)item; var imageResponse = new DynamicImageResponse(); if (!string.IsNullOrEmpty(channelItem.OriginalImageUrl)) { var options = new HttpRequestOptions { CancellationToken = cancellationToken, Url = channelItem.OriginalImageUrl }; var response = await _httpClient.GetResponse(options).ConfigureAwait(false); if (response.ContentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase)) { imageResponse.HasImage = true; imageResponse.Stream = response.Content; imageResponse.SetFormatFromMimeType(response.ContentType); } else { _logger.Error("Provider did not return an image content type."); } } return imageResponse; }
public async Task<DynamicImageResponse> GetImage(IHasImages item, ImageType type, CancellationToken cancellationToken) { var liveTvItem = (LiveTvProgram)item; var imageResponse = new DynamicImageResponse(); if (!string.IsNullOrEmpty(liveTvItem.ProviderImagePath)) { imageResponse.Path = liveTvItem.ProviderImagePath; imageResponse.HasImage = true; } else if (!string.IsNullOrEmpty(liveTvItem.ProviderImageUrl)) { var options = new HttpRequestOptions { CancellationToken = cancellationToken, Url = liveTvItem.ProviderImageUrl }; var response = await _httpClient.GetResponse(options).ConfigureAwait(false); if (response.ContentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase)) { imageResponse.HasImage = true; imageResponse.Stream = response.Content; imageResponse.SetFormatFromMimeType(response.ContentType); } else { _logger.Error("Provider did not return an image content type."); } } else if (liveTvItem.HasProviderImage ?? true) { var service = _liveTvManager.Services.FirstOrDefault(i => string.Equals(i.Name, liveTvItem.ServiceName, StringComparison.OrdinalIgnoreCase)); if (service != null) { try { var channel = _liveTvManager.GetInternalChannel(liveTvItem.ChannelId); var response = await service.GetProgramImageAsync(liveTvItem.ExternalId, channel.ExternalId, cancellationToken).ConfigureAwait(false); if (response != null) { imageResponse.HasImage = true; imageResponse.Stream = response.Stream; imageResponse.Format = response.Format; } } catch (NotImplementedException) { } } } return imageResponse; }