jellyfin/Emby.Server.Implementations/Channels/ChannelImageProvider.cs

65 lines
1.9 KiB
C#
Raw Normal View History

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