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/RecordingImageProvider.cs

83 lines
2.4 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
{
public class RecordingImageProvider : IDynamicImageProvider, IHasItemChangeMonitor
{
private readonly ILiveTvManager _liveTvManager;
9 years ago
public RecordingImageProvider(ILiveTvManager liveTvManager)
{
_liveTvManager = liveTvManager;
}
public IEnumerable<ImageType> GetSupportedImages(IHasMetadata item)
{
return new[] { ImageType.Primary };
}
public async Task<DynamicImageResponse> GetImage(IHasMetadata item, ImageType type, CancellationToken cancellationToken)
{
var liveTvItem = (ILiveTvRecording)item;
var imageResponse = new DynamicImageResponse();
11 years ago
9 years ago
var service = _liveTvManager.Services.FirstOrDefault(i => string.Equals(i.Name, liveTvItem.ServiceName, StringComparison.OrdinalIgnoreCase));
if (service != null)
{
9 years ago
try
{
9 years ago
var response = await service.GetRecordingImageAsync(liveTvItem.ExternalId, cancellationToken).ConfigureAwait(false);
9 years ago
if (response != null)
{
imageResponse.HasImage = true;
9 years ago
imageResponse.Stream = response.Stream;
imageResponse.Format = response.Format;
}
}
9 years ago
catch (NotImplementedException)
{
}
}
return imageResponse;
}
public string Name
{
get { return "Live TV Service Provider"; }
}
11 years ago
public bool Supports(IHasMetadata item)
{
return item is ILiveTvRecording;
}
public int Order
{
get { return 0; }
}
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService)
{
var liveTvItem = item as ILiveTvRecording;
if (liveTvItem != null)
{
return !liveTvItem.HasImage(ImageType.Primary);
}
return false;
}
}
}