2015-10-25 10:13:30 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-12-19 14:51:32 -07:00
|
|
|
|
using MediaBrowser.Controller.LiveTv;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using System;
|
2014-01-29 09:16:24 -07:00
|
|
|
|
using System.Collections.Generic;
|
2013-12-19 14:51:32 -07:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.LiveTv
|
|
|
|
|
{
|
2015-04-11 18:38:38 -07:00
|
|
|
|
public class ProgramImageProvider : IDynamicImageProvider, IHasItemChangeMonitor, IHasOrder
|
2013-12-19 14:51:32 -07:00
|
|
|
|
{
|
|
|
|
|
private readonly ILiveTvManager _liveTvManager;
|
|
|
|
|
|
2015-10-25 10:13:30 -07:00
|
|
|
|
public ProgramImageProvider(ILiveTvManager liveTvManager)
|
2013-12-19 14:51:32 -07:00
|
|
|
|
{
|
|
|
|
|
_liveTvManager = liveTvManager;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 09:16:24 -07:00
|
|
|
|
public IEnumerable<ImageType> GetSupportedImages(IHasImages item)
|
2013-12-19 14:51:32 -07:00
|
|
|
|
{
|
2014-01-29 09:16:24 -07:00
|
|
|
|
return new[] { ImageType.Primary };
|
2013-12-19 14:51:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 09:16:24 -07:00
|
|
|
|
public async Task<DynamicImageResponse> GetImage(IHasImages item, ImageType type, CancellationToken cancellationToken)
|
2013-12-19 14:51:32 -07:00
|
|
|
|
{
|
2014-01-29 09:16:24 -07:00
|
|
|
|
var liveTvItem = (LiveTvProgram)item;
|
2013-12-19 14:51:32 -07:00
|
|
|
|
|
2014-01-29 09:16:24 -07:00
|
|
|
|
var imageResponse = new DynamicImageResponse();
|
2013-12-19 14:51:32 -07:00
|
|
|
|
|
2015-10-25 10:13:30 -07:00
|
|
|
|
var service = _liveTvManager.Services.FirstOrDefault(i => string.Equals(i.Name, liveTvItem.ServiceName, StringComparison.OrdinalIgnoreCase));
|
2013-12-19 14:51:32 -07:00
|
|
|
|
|
2015-10-25 10:13:30 -07:00
|
|
|
|
if (service != null)
|
|
|
|
|
{
|
|
|
|
|
try
|
2013-12-19 14:51:32 -07:00
|
|
|
|
{
|
2015-10-25 10:13:30 -07:00
|
|
|
|
var channel = _liveTvManager.GetInternalChannel(liveTvItem.ChannelId);
|
2015-06-01 07:49:23 -07:00
|
|
|
|
|
2015-10-25 10:13:30 -07:00
|
|
|
|
var response = await service.GetProgramImageAsync(liveTvItem.ExternalId, channel.ExternalId, cancellationToken).ConfigureAwait(false);
|
2013-12-22 10:16:24 -07:00
|
|
|
|
|
2015-10-25 10:13:30 -07:00
|
|
|
|
if (response != null)
|
2013-12-22 10:16:24 -07:00
|
|
|
|
{
|
2015-10-25 10:13:30 -07:00
|
|
|
|
imageResponse.HasImage = true;
|
|
|
|
|
imageResponse.Stream = response.Stream;
|
|
|
|
|
imageResponse.Format = response.Format;
|
2013-12-22 10:16:24 -07:00
|
|
|
|
}
|
2013-12-19 14:51:32 -07:00
|
|
|
|
}
|
2015-10-25 10:13:30 -07:00
|
|
|
|
catch (NotImplementedException)
|
|
|
|
|
{
|
|
|
|
|
}
|
2013-12-19 14:51:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 09:16:24 -07:00
|
|
|
|
return imageResponse;
|
|
|
|
|
}
|
2013-12-19 14:51:32 -07:00
|
|
|
|
|
2014-01-29 09:16:24 -07:00
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Live TV Service Provider"; }
|
|
|
|
|
}
|
2013-12-22 10:16:24 -07:00
|
|
|
|
|
2014-01-29 09:16:24 -07:00
|
|
|
|
public bool Supports(IHasImages item)
|
|
|
|
|
{
|
|
|
|
|
return item is LiveTvProgram;
|
2013-12-19 14:51:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 09:16:24 -07:00
|
|
|
|
public int Order
|
2013-12-19 14:51:32 -07:00
|
|
|
|
{
|
2015-04-11 18:38:38 -07:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
// Let the better providers run first
|
|
|
|
|
return 100;
|
|
|
|
|
}
|
2013-12-19 14:51:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-10 18:57:11 -07:00
|
|
|
|
public bool HasChanged(IHasMetadata item, MetadataStatus status, IDirectoryService directoryService)
|
2013-12-19 14:51:32 -07:00
|
|
|
|
{
|
2014-03-05 22:17:13 -07:00
|
|
|
|
var liveTvItem = item as LiveTvProgram;
|
|
|
|
|
|
|
|
|
|
if (liveTvItem != null)
|
|
|
|
|
{
|
2015-10-04 11:10:50 -07:00
|
|
|
|
return !liveTvItem.HasImage(ImageType.Primary);
|
2014-03-05 22:17:13 -07:00
|
|
|
|
}
|
|
|
|
|
return false;
|
2013-12-19 14:51:32 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|