2014-03-18 01:45:41 +00:00
|
|
|
|
using MediaBrowser.Common.Net;
|
|
|
|
|
using MediaBrowser.Controller.Channels;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2015-10-16 17:06:31 +00:00
|
|
|
|
using MediaBrowser.Model.MediaInfo;
|
2014-03-18 01:45:41 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.Channels
|
|
|
|
|
{
|
2014-09-11 01:57:11 +00:00
|
|
|
|
public class ChannelItemImageProvider : IDynamicImageProvider, IHasItemChangeMonitor
|
2014-03-18 01:45:41 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly IHttpClient _httpClient;
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
public ChannelItemImageProvider(IHttpClient httpClient, ILogger logger)
|
|
|
|
|
{
|
|
|
|
|
_httpClient = httpClient;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<ImageType> GetSupportedImages(IHasImages item)
|
|
|
|
|
{
|
|
|
|
|
return new[] { ImageType.Primary };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<DynamicImageResponse> GetImage(IHasImages item, ImageType type, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var channelItem = (IChannelItem)item;
|
|
|
|
|
|
|
|
|
|
var imageResponse = new DynamicImageResponse();
|
|
|
|
|
|
2015-10-04 18:10:50 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(channelItem.ExternalImagePath))
|
2014-03-18 01:45:41 +00:00
|
|
|
|
{
|
2015-10-16 17:06:31 +00:00
|
|
|
|
imageResponse.Path = channelItem.ExternalImagePath;
|
|
|
|
|
imageResponse.Protocol = MediaProtocol.Http;
|
|
|
|
|
imageResponse.HasImage = true;
|
2014-03-18 01:45:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return imageResponse;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Channel Image Provider"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Supports(IHasImages item)
|
|
|
|
|
{
|
|
|
|
|
return item is IChannelItem;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-11 01:57:11 +00:00
|
|
|
|
public bool HasChanged(IHasMetadata item, MetadataStatus status, IDirectoryService directoryService)
|
2014-03-18 01:45:41 +00:00
|
|
|
|
{
|
|
|
|
|
var channelItem = item as IChannelItem;
|
|
|
|
|
|
|
|
|
|
if (channelItem != null)
|
|
|
|
|
{
|
2015-10-04 18:10:50 +00:00
|
|
|
|
return !channelItem.HasImage(ImageType.Primary) && !string.IsNullOrWhiteSpace(channelItem.ExternalImagePath);
|
2014-03-18 01:45:41 +00:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|