You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/Emby.Server.Implementations/LiveTv/ProgramImageProvider.cs

101 lines
2.9 KiB

9 years ago
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Emby.Server.Implementations.LiveTv
{
10 years ago
public class ProgramImageProvider : IDynamicImageProvider, IHasItemChangeMonitor, IHasOrder
{
private readonly ILiveTvManager _liveTvManager;
9 years ago
public ProgramImageProvider(ILiveTvManager liveTvManager)
{
_liveTvManager = liveTvManager;
}
public IEnumerable<ImageType> GetSupportedImages(IHasImages item)
{
return new[] { ImageType.Primary };
}
private string GetItemExternalId(BaseItem item)
{
var externalId = item.ExternalId;
if (string.IsNullOrWhiteSpace(externalId))
{
externalId = item.GetProviderId("ProviderExternalId");
}
return externalId;
}
public async Task<DynamicImageResponse> GetImage(IHasImages item, ImageType type, CancellationToken cancellationToken)
{
var liveTvItem = (LiveTvProgram)item;
var imageResponse = new DynamicImageResponse();
9 years ago
var service = _liveTvManager.Services.FirstOrDefault(i => string.Equals(i.Name, liveTvItem.ServiceName, StringComparison.OrdinalIgnoreCase));
9 years ago
if (service != null)
{
try
{
9 years ago
var channel = _liveTvManager.GetInternalChannel(liveTvItem.ChannelId);
var response = await service.GetProgramImageAsync(GetItemExternalId(liveTvItem), GetItemExternalId(channel), cancellationToken).ConfigureAwait(false);
11 years ago
9 years ago
if (response != null)
11 years ago
{
9 years ago
imageResponse.HasImage = true;
imageResponse.Stream = response.Stream;
imageResponse.Format = response.Format;
11 years ago
}
}
9 years ago
catch (NotImplementedException)
{
}
}
return imageResponse;
}
public string Name
{
get { return "Live TV Service Provider"; }
}
11 years ago
public bool Supports(IHasImages item)
{
return item is LiveTvProgram;
}
public int Order
{
10 years ago
get
{
// Let the better providers run first
return 100;
}
}
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService)
{
var liveTvItem = item as LiveTvProgram;
if (liveTvItem != null)
{
return !liveTvItem.HasImage(ImageType.Primary);
}
return false;
}
}
}