2014-02-07 16:42:19 +00:00
|
|
|
|
using MediaBrowser.Common.Net;
|
2013-12-19 21:51:32 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.LiveTv;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
2014-02-07 16:42:19 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2013-12-19 21:51:32 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.LiveTv
|
|
|
|
|
{
|
2014-09-11 01:57:11 +00:00
|
|
|
|
public class RecordingImageProvider : IDynamicImageProvider, IHasItemChangeMonitor
|
2013-12-19 21:51:32 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly ILiveTvManager _liveTvManager;
|
|
|
|
|
private readonly IHttpClient _httpClient;
|
2014-02-07 16:42:19 +00:00
|
|
|
|
private readonly ILogger _logger;
|
2013-12-19 21:51:32 +00:00
|
|
|
|
|
2014-02-07 16:42:19 +00:00
|
|
|
|
public RecordingImageProvider(ILiveTvManager liveTvManager, IHttpClient httpClient, ILogger logger)
|
2013-12-19 21:51:32 +00:00
|
|
|
|
{
|
|
|
|
|
_liveTvManager = liveTvManager;
|
|
|
|
|
_httpClient = httpClient;
|
2014-02-07 16:42:19 +00:00
|
|
|
|
_logger = logger;
|
2013-12-19 21:51:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-07 16:42:19 +00:00
|
|
|
|
public IEnumerable<ImageType> GetSupportedImages(IHasImages item)
|
2013-12-19 21:51:32 +00:00
|
|
|
|
{
|
2014-02-07 16:42:19 +00:00
|
|
|
|
return new[] { ImageType.Primary };
|
2013-12-19 21:51:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-07 16:42:19 +00:00
|
|
|
|
public async Task<DynamicImageResponse> GetImage(IHasImages item, ImageType type, CancellationToken cancellationToken)
|
2013-12-19 21:51:32 +00:00
|
|
|
|
{
|
2014-02-07 16:42:19 +00:00
|
|
|
|
var liveTvItem = (ILiveTvRecording)item;
|
2013-12-19 21:51:32 +00:00
|
|
|
|
|
2014-02-07 16:42:19 +00:00
|
|
|
|
var imageResponse = new DynamicImageResponse();
|
2013-12-22 17:16:24 +00:00
|
|
|
|
|
2015-10-04 18:10:50 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(liveTvItem.ExternalImagePath))
|
2013-12-19 21:51:32 +00:00
|
|
|
|
{
|
2015-10-04 18:10:50 +00:00
|
|
|
|
if (liveTvItem.ExternalImagePath.StartsWith("http", StringComparison.OrdinalIgnoreCase))
|
2013-12-19 21:51:32 +00:00
|
|
|
|
{
|
2015-10-04 18:10:50 +00:00
|
|
|
|
var options = new HttpRequestOptions
|
|
|
|
|
{
|
|
|
|
|
CancellationToken = cancellationToken,
|
|
|
|
|
Url = liveTvItem.ExternalImagePath
|
|
|
|
|
};
|
2013-12-19 21:51:32 +00:00
|
|
|
|
|
2015-10-04 18:10:50 +00:00
|
|
|
|
var response = await _httpClient.GetResponse(options).ConfigureAwait(false);
|
2013-12-19 21:51:32 +00:00
|
|
|
|
|
2015-10-04 18:10:50 +00:00
|
|
|
|
if (response.ContentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
imageResponse.HasImage = true;
|
|
|
|
|
imageResponse.Stream = response.Content;
|
|
|
|
|
imageResponse.SetFormatFromMimeType(response.ContentType);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_logger.Error("Provider did not return an image content type.");
|
|
|
|
|
}
|
2014-02-07 16:42:19 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-10-04 18:10:50 +00:00
|
|
|
|
imageResponse.Path = liveTvItem.ExternalImagePath;
|
|
|
|
|
imageResponse.HasImage = true;
|
2013-12-19 21:51:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-01 17:07:55 +00:00
|
|
|
|
else
|
2013-12-19 21:51:32 +00:00
|
|
|
|
{
|
2014-02-07 16:42:19 +00:00
|
|
|
|
var service = _liveTvManager.Services.FirstOrDefault(i => string.Equals(i.Name, liveTvItem.ServiceName, StringComparison.OrdinalIgnoreCase));
|
2013-12-19 21:51:32 +00:00
|
|
|
|
|
|
|
|
|
if (service != null)
|
|
|
|
|
{
|
2013-12-22 17:16:24 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2015-06-01 17:07:55 +00:00
|
|
|
|
var response = await service.GetRecordingImageAsync(liveTvItem.ExternalId, cancellationToken).ConfigureAwait(false);
|
2013-12-22 17:16:24 +00:00
|
|
|
|
|
|
|
|
|
if (response != null)
|
|
|
|
|
{
|
2014-02-07 16:42:19 +00:00
|
|
|
|
imageResponse.HasImage = true;
|
|
|
|
|
imageResponse.Stream = response.Stream;
|
|
|
|
|
imageResponse.Format = response.Format;
|
2013-12-22 17:16:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (NotImplementedException)
|
|
|
|
|
{
|
|
|
|
|
}
|
2013-12-19 21:51:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-07 16:42:19 +00:00
|
|
|
|
return imageResponse;
|
|
|
|
|
}
|
2013-12-19 21:51:32 +00:00
|
|
|
|
|
2014-02-07 16:42:19 +00:00
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Live TV Service Provider"; }
|
|
|
|
|
}
|
2013-12-22 17:16:24 +00:00
|
|
|
|
|
2014-02-07 16:42:19 +00:00
|
|
|
|
public bool Supports(IHasImages item)
|
|
|
|
|
{
|
|
|
|
|
return item is ILiveTvRecording;
|
2013-12-19 21:51:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-07 16:42:19 +00:00
|
|
|
|
public int Order
|
2013-12-19 21:51:32 +00:00
|
|
|
|
{
|
2014-02-07 16:42:19 +00:00
|
|
|
|
get { return 0; }
|
2013-12-19 21:51:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-11 01:57:11 +00:00
|
|
|
|
public bool HasChanged(IHasMetadata item, MetadataStatus status, IDirectoryService directoryService)
|
2013-12-19 21:51:32 +00:00
|
|
|
|
{
|
2014-03-06 05:17:13 +00:00
|
|
|
|
var liveTvItem = item as ILiveTvRecording;
|
|
|
|
|
|
|
|
|
|
if (liveTvItem != null)
|
|
|
|
|
{
|
2015-10-04 18:10:50 +00:00
|
|
|
|
return !liveTvItem.HasImage(ImageType.Primary);
|
2014-03-06 05:17:13 +00:00
|
|
|
|
}
|
|
|
|
|
return false;
|
2013-12-19 21:51:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|