2015-07-20 18:32:55 +00:00
|
|
|
|
using MediaBrowser.Common;
|
|
|
|
|
using MediaBrowser.Common.Net;
|
2013-11-24 20:51:45 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.LiveTv;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using System;
|
2014-01-29 16:16:24 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-11-24 20:51:45 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.LiveTv
|
|
|
|
|
{
|
2014-09-11 01:57:11 +00:00
|
|
|
|
public class ChannelImageProvider : IDynamicImageProvider, IHasItemChangeMonitor
|
2013-11-24 20:51:45 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly ILiveTvManager _liveTvManager;
|
2013-12-19 21:51:32 +00:00
|
|
|
|
private readonly IHttpClient _httpClient;
|
2014-01-29 16:16:24 +00:00
|
|
|
|
private readonly ILogger _logger;
|
2015-07-20 18:32:55 +00:00
|
|
|
|
private readonly IApplicationHost _appHost;
|
2013-11-24 20:51:45 +00:00
|
|
|
|
|
2015-07-20 18:32:55 +00:00
|
|
|
|
public ChannelImageProvider(ILiveTvManager liveTvManager, IHttpClient httpClient, ILogger logger, IApplicationHost appHost)
|
2013-11-24 20:51:45 +00:00
|
|
|
|
{
|
|
|
|
|
_liveTvManager = liveTvManager;
|
2013-12-19 21:51:32 +00:00
|
|
|
|
_httpClient = httpClient;
|
2014-01-29 16:16:24 +00:00
|
|
|
|
_logger = logger;
|
2015-07-20 18:32:55 +00:00
|
|
|
|
_appHost = appHost;
|
2013-11-24 20:51:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 16:16:24 +00:00
|
|
|
|
public IEnumerable<ImageType> GetSupportedImages(IHasImages item)
|
2013-11-24 20:51:45 +00:00
|
|
|
|
{
|
2014-01-29 16:16:24 +00:00
|
|
|
|
return new[] { ImageType.Primary };
|
2013-11-24 20:51:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 16:16:24 +00:00
|
|
|
|
public async Task<DynamicImageResponse> GetImage(IHasImages item, ImageType type, CancellationToken cancellationToken)
|
2013-11-24 20:51:45 +00:00
|
|
|
|
{
|
2014-01-29 16:16:24 +00:00
|
|
|
|
var liveTvItem = (LiveTvChannel)item;
|
2013-11-24 20:51:45 +00:00
|
|
|
|
|
2014-01-29 16:16:24 +00:00
|
|
|
|
var imageResponse = new DynamicImageResponse();
|
2013-11-24 20:51:45 +00:00
|
|
|
|
|
2015-10-25 17:13:30 +00:00
|
|
|
|
var service = _liveTvManager.Services.FirstOrDefault(i => string.Equals(i.Name, liveTvItem.ServiceName, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
2016-06-06 17:33:39 +00:00
|
|
|
|
if (service != null && !item.HasImage(ImageType.Primary))
|
2013-11-24 20:51:45 +00:00
|
|
|
|
{
|
2015-10-25 17:13:30 +00:00
|
|
|
|
try
|
2013-12-19 21:51:32 +00:00
|
|
|
|
{
|
2015-10-25 17:13:30 +00:00
|
|
|
|
var response = await service.GetChannelImageAsync(liveTvItem.ExternalId, cancellationToken).ConfigureAwait(false);
|
2015-03-30 03:04:55 +00:00
|
|
|
|
|
2015-10-25 17:13:30 +00:00
|
|
|
|
if (response != null)
|
2015-10-04 18:10:50 +00:00
|
|
|
|
{
|
|
|
|
|
imageResponse.HasImage = true;
|
2015-10-25 17:13:30 +00:00
|
|
|
|
imageResponse.Stream = response.Stream;
|
|
|
|
|
imageResponse.Format = response.Format;
|
2015-10-04 18:10:50 +00:00
|
|
|
|
}
|
2013-12-19 21:51:32 +00:00
|
|
|
|
}
|
2015-10-25 17:13:30 +00:00
|
|
|
|
catch (NotImplementedException)
|
2013-12-19 21:51:32 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 16:16:24 +00:00
|
|
|
|
return imageResponse;
|
|
|
|
|
}
|
2013-11-24 20:51:45 +00:00
|
|
|
|
|
2014-01-29 16:16:24 +00:00
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Live TV Service Provider"; }
|
|
|
|
|
}
|
2013-12-22 17:16:24 +00:00
|
|
|
|
|
2014-01-29 16:16:24 +00:00
|
|
|
|
public bool Supports(IHasImages item)
|
|
|
|
|
{
|
|
|
|
|
return item is LiveTvChannel;
|
2013-11-24 20:51:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 16:16:24 +00:00
|
|
|
|
public int Order
|
2013-11-24 20:51:45 +00:00
|
|
|
|
{
|
2014-01-29 16:16:24 +00:00
|
|
|
|
get { return 0; }
|
2013-11-24 20:51:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-08 18:32:38 +00:00
|
|
|
|
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService)
|
2013-11-24 20:51:45 +00:00
|
|
|
|
{
|
2014-10-08 23:31:44 +00:00
|
|
|
|
return GetSupportedImages(item).Any(i => !item.HasImage(i));
|
2013-11-24 20:51:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|