2019-01-13 12:54:44 -07:00
|
|
|
using System.Collections.Generic;
|
2014-03-18 10:05:57 -07:00
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2019-01-13 12:20:16 -07:00
|
|
|
using MediaBrowser.Controller.Channels;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Entities;
|
2014-03-18 10:05:57 -07:00
|
|
|
|
2016-11-02 13:53:50 -07:00
|
|
|
namespace Emby.Server.Implementations.Channels
|
2014-03-18 10:05:57 -07:00
|
|
|
{
|
2020-04-14 12:29:57 -07:00
|
|
|
/// <summary>
|
|
|
|
/// An image provider for channels.
|
|
|
|
/// </summary>
|
2014-09-10 18:57:11 -07:00
|
|
|
public class ChannelImageProvider : IDynamicImageProvider, IHasItemChangeMonitor
|
2014-03-18 10:05:57 -07:00
|
|
|
{
|
|
|
|
private readonly IChannelManager _channelManager;
|
|
|
|
|
2020-04-14 12:29:57 -07:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="ChannelImageProvider"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="channelManager">The channel manager.</param>
|
2014-03-18 10:05:57 -07:00
|
|
|
public ChannelImageProvider(IChannelManager channelManager)
|
|
|
|
{
|
|
|
|
_channelManager = channelManager;
|
|
|
|
}
|
|
|
|
|
2020-04-22 06:44:20 -07:00
|
|
|
/// <inheritdoc />
|
2020-04-11 03:03:10 -07:00
|
|
|
public string Name => "Channel Image Provider";
|
|
|
|
|
2020-04-14 12:29:57 -07:00
|
|
|
/// <inheritdoc />
|
2018-09-12 10:26:21 -07:00
|
|
|
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
2014-03-18 10:05:57 -07:00
|
|
|
{
|
|
|
|
return GetChannel(item).GetSupportedChannelImages();
|
|
|
|
}
|
|
|
|
|
2020-04-14 12:29:57 -07:00
|
|
|
/// <inheritdoc />
|
2018-09-12 10:26:21 -07:00
|
|
|
public Task<DynamicImageResponse> GetImage(BaseItem item, ImageType type, CancellationToken cancellationToken)
|
2014-03-18 10:05:57 -07:00
|
|
|
{
|
|
|
|
var channel = GetChannel(item);
|
|
|
|
|
|
|
|
return channel.GetChannelImage(type, cancellationToken);
|
|
|
|
}
|
|
|
|
|
2020-04-14 12:29:57 -07:00
|
|
|
/// <inheritdoc />
|
2018-09-12 10:26:21 -07:00
|
|
|
public bool Supports(BaseItem item)
|
2014-03-18 10:05:57 -07:00
|
|
|
{
|
|
|
|
return item is Channel;
|
|
|
|
}
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
private IChannel GetChannel(BaseItem item)
|
2014-03-18 10:05:57 -07:00
|
|
|
{
|
|
|
|
var channel = (Channel)item;
|
|
|
|
|
|
|
|
return ((ChannelManager)_channelManager).GetChannelProvider(channel);
|
|
|
|
}
|
2014-09-10 18:57:11 -07:00
|
|
|
|
2020-04-14 12:29:57 -07:00
|
|
|
/// <inheritdoc />
|
2018-09-12 10:26:21 -07:00
|
|
|
public bool HasChanged(BaseItem item, IDirectoryService directoryService)
|
2014-09-10 18:57:11 -07:00
|
|
|
{
|
|
|
|
return GetSupportedImages(item).Any(i => !item.HasImage(i));
|
|
|
|
}
|
2014-03-18 10:05:57 -07:00
|
|
|
}
|
|
|
|
}
|