| | 1 | | using System.Collections.Generic; |
| | 2 | | using System.Linq; |
| | 3 | | using System.Threading; |
| | 4 | | using System.Threading.Tasks; |
| | 5 | | using MediaBrowser.Controller.Channels; |
| | 6 | | using MediaBrowser.Controller.Entities; |
| | 7 | | using MediaBrowser.Controller.Providers; |
| | 8 | | using MediaBrowser.Model.Entities; |
| | 9 | |
|
| | 10 | | namespace Jellyfin.LiveTv.Channels |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// An image provider for channels. |
| | 14 | | /// </summary> |
| | 15 | | public class ChannelImageProvider : IDynamicImageProvider, IHasItemChangeMonitor |
| | 16 | | { |
| | 17 | | private readonly IChannelManager _channelManager; |
| | 18 | |
|
| | 19 | | /// <summary> |
| | 20 | | /// Initializes a new instance of the <see cref="ChannelImageProvider"/> class. |
| | 21 | | /// </summary> |
| | 22 | | /// <param name="channelManager">The channel manager.</param> |
| | 23 | | public ChannelImageProvider(IChannelManager channelManager) |
| | 24 | | { |
| 21 | 25 | | _channelManager = channelManager; |
| 21 | 26 | | } |
| | 27 | |
|
| | 28 | | /// <inheritdoc /> |
| 0 | 29 | | public string Name => "Channel Image Provider"; |
| | 30 | |
|
| | 31 | | /// <inheritdoc /> |
| | 32 | | public IEnumerable<ImageType> GetSupportedImages(BaseItem item) |
| | 33 | | { |
| 0 | 34 | | return GetChannel(item).GetSupportedChannelImages(); |
| | 35 | | } |
| | 36 | |
|
| | 37 | | /// <inheritdoc /> |
| | 38 | | public Task<DynamicImageResponse> GetImage(BaseItem item, ImageType type, CancellationToken cancellationToken) |
| | 39 | | { |
| 0 | 40 | | var channel = GetChannel(item); |
| | 41 | |
|
| 0 | 42 | | return channel.GetChannelImage(type, cancellationToken); |
| | 43 | | } |
| | 44 | |
|
| | 45 | | /// <inheritdoc /> |
| | 46 | | public bool Supports(BaseItem item) |
| | 47 | | { |
| 53 | 48 | | return item is Channel; |
| | 49 | | } |
| | 50 | |
|
| | 51 | | private IChannel GetChannel(BaseItem item) |
| | 52 | | { |
| 0 | 53 | | var channel = (Channel)item; |
| | 54 | |
|
| 0 | 55 | | return ((ChannelManager)_channelManager).GetChannelProvider(channel); |
| | 56 | | } |
| | 57 | |
|
| | 58 | | /// <inheritdoc /> |
| | 59 | | public bool HasChanged(BaseItem item, IDirectoryService directoryService) |
| | 60 | | { |
| 0 | 61 | | return GetSupportedImages(item).Any(i => !item.HasImage(i)); |
| | 62 | | } |
| | 63 | | } |
| | 64 | | } |