converted recording providers

This commit is contained in:
Luke Pulverenti 2014-02-07 11:42:19 -05:00
parent b1713a16cd
commit 5e2a2a02ef
7 changed files with 140 additions and 105 deletions

View File

@ -38,12 +38,6 @@ namespace MediaBrowser.Api.Playback.Hls
[Api(Description = "Gets an Http live streaming segment file. Internal use only.")]
public class GetHlsVideoSegment : VideoStreamRequest
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
public string Id { get; set; }
public string PlaylistId { get; set; }
/// <summary>

View File

@ -0,0 +1,42 @@
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Providers.Manager;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Providers.LiveTv
{
public class AudioRecordingService : MetadataService<LiveTvAudioRecording, ItemLookupInfo>
{
private readonly ILibraryManager _libraryManager;
public AudioRecordingService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IProviderRepository providerRepo, IFileSystem fileSystem, ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, providerRepo, fileSystem)
{
_libraryManager = libraryManager;
}
/// <summary>
/// Merges the specified source.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="target">The target.</param>
/// <param name="lockedFields">The locked fields.</param>
/// <param name="replaceData">if set to <c>true</c> [replace data].</param>
protected override void MergeData(LiveTvAudioRecording source, LiveTvAudioRecording target, List<MetadataFields> lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
protected override Task SaveItem(LiveTvAudioRecording item, ItemUpdateType reason, CancellationToken cancellationToken)
{
return _libraryManager.UpdateItem(item, reason, cancellationToken);
}
}
}

View File

@ -0,0 +1,42 @@
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Providers.Manager;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Providers.LiveTv
{
public class VideoRecordingService : MetadataService<LiveTvVideoRecording, ItemLookupInfo>
{
private readonly ILibraryManager _libraryManager;
public VideoRecordingService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IProviderRepository providerRepo, IFileSystem fileSystem, ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, providerRepo, fileSystem)
{
_libraryManager = libraryManager;
}
/// <summary>
/// Merges the specified source.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="target">The target.</param>
/// <param name="lockedFields">The locked fields.</param>
/// <param name="replaceData">if set to <c>true</c> [replace data].</param>
protected override void MergeData(LiveTvVideoRecording source, LiveTvVideoRecording target, List<MetadataFields> lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
protected override Task SaveItem(LiveTvVideoRecording item, ItemUpdateType reason, CancellationToken cancellationToken)
{
return _libraryManager.UpdateItem(item, reason, cancellationToken);
}
}
}

View File

@ -77,9 +77,11 @@
<Compile Include="Games\GameSystemMetadataService.cs" />
<Compile Include="Games\GameSystemXmlParser.cs" />
<Compile Include="Genres\GenreMetadataService.cs" />
<Compile Include="LiveTv\AudioRecordingService.cs" />
<Compile Include="LiveTv\ChannelMetadataService.cs" />
<Compile Include="LiveTv\ChannelXmlProvider.cs" />
<Compile Include="LiveTv\ProgramMetadataService.cs" />
<Compile Include="LiveTv\VideoRecordingService.cs" />
<Compile Include="Manager\ImageSaver.cs" />
<Compile Include="Manager\ItemImageProvider.cs" />
<Compile Include="Manager\ProviderManager.cs" />
@ -121,7 +123,7 @@
<Compile Include="Music\MusicVideoMetadataService.cs" />
<Compile Include="Music\MusicVideoXmlProvider.cs" />
<Compile Include="Omdb\OmdbProvider.cs" />
<Compile Include="Omdb\OmdbSeriesProvider.cs" />
<Compile Include="Omdb\OmdbItemProvider.cs" />
<Compile Include="People\MovieDbPersonImageProvider.cs" />
<Compile Include="Movies\MovieUpdatesPrescanTask.cs" />
<Compile Include="Movies\MovieXmlParser.cs" />

View File

@ -10,13 +10,13 @@ using System.Threading.Tasks;
namespace MediaBrowser.Providers.Omdb
{
public class OmdbSeriesProvider : ICustomMetadataProvider<Series>,
public class OmdbItemProvider : ICustomMetadataProvider<Series>,
ICustomMetadataProvider<Movie>, ICustomMetadataProvider<Trailer>
{
private readonly IJsonSerializer _jsonSerializer;
private readonly IHttpClient _httpClient;
public OmdbSeriesProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient)
public OmdbItemProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient)
{
_jsonSerializer = jsonSerializer;
_httpClient = httpClient;

View File

@ -1,156 +1,111 @@
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.LiveTv
{
public class RecordingImageProvider : BaseMetadataProvider
public class RecordingImageProvider : IDynamicImageProvider, IHasChangeMonitor
{
private readonly ILiveTvManager _liveTvManager;
private readonly IProviderManager _providerManager;
private readonly IFileSystem _fileSystem;
private readonly IHttpClient _httpClient;
private readonly ILogger _logger;
public RecordingImageProvider(ILogManager logManager, IServerConfigurationManager configurationManager, ILiveTvManager liveTvManager, IProviderManager providerManager, IFileSystem fileSystem, IHttpClient httpClient)
: base(logManager, configurationManager)
public RecordingImageProvider(ILiveTvManager liveTvManager, IHttpClient httpClient, ILogger logger)
{
_liveTvManager = liveTvManager;
_providerManager = providerManager;
_fileSystem = fileSystem;
_httpClient = httpClient;
_logger = logger;
}
public override bool Supports(BaseItem item)
public IEnumerable<ImageType> GetSupportedImages(IHasImages item)
{
return item is ILiveTvRecording;
return new[] { ImageType.Primary };
}
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
public async Task<DynamicImageResponse> GetImage(IHasImages item, ImageType type, CancellationToken cancellationToken)
{
return !item.HasImage(ImageType.Primary);
}
var liveTvItem = (ILiveTvRecording)item;
public override async Task<bool> FetchAsync(BaseItem item, bool force, BaseProviderInfo providerInfo, CancellationToken cancellationToken)
{
if (item.HasImage(ImageType.Primary))
{
SetLastRefreshed(item, DateTime.UtcNow, providerInfo);
return true;
}
var imageResponse = new DynamicImageResponse();
var changed = true;
try
if (!string.IsNullOrEmpty(liveTvItem.RecordingInfo.ImagePath))
{
changed = await DownloadImage((ILiveTvRecording)item, cancellationToken).ConfigureAwait(false);
imageResponse.Path = liveTvItem.RecordingInfo.ImagePath;
imageResponse.HasImage = true;
}
catch (HttpException ex)
{
// Don't fail the provider on a 404
if (!ex.StatusCode.HasValue || ex.StatusCode.Value != HttpStatusCode.NotFound)
{
throw;
}
}
if (changed)
{
SetLastRefreshed(item, DateTime.UtcNow, providerInfo);
}
return changed;
}
private async Task<bool> DownloadImage(ILiveTvRecording item, CancellationToken cancellationToken)
{
var recordingInfo = item.RecordingInfo;
Stream imageStream = null;
string contentType = null;
if (!string.IsNullOrEmpty(recordingInfo.ImagePath))
{
contentType = "image/" + Path.GetExtension(recordingInfo.ImagePath).ToLower();
imageStream = _fileSystem.GetFileStream(recordingInfo.ImagePath, FileMode.Open, FileAccess.Read, FileShare.Read, true);
}
else if (!string.IsNullOrEmpty(recordingInfo.ImageUrl))
else if (!string.IsNullOrEmpty(liveTvItem.RecordingInfo.ImageUrl))
{
var options = new HttpRequestOptions
{
CancellationToken = cancellationToken,
Url = recordingInfo.ImageUrl
Url = liveTvItem.RecordingInfo.ImageUrl
};
var response = await _httpClient.GetResponse(options).ConfigureAwait(false);
if (!response.ContentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase))
if (response.ContentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase))
{
Logger.Error("Provider did not return an image content type.");
return false;
imageResponse.HasImage = true;
imageResponse.Stream = response.Content;
imageResponse.SetFormatFromMimeType(response.ContentType);
}
imageStream = response.Content;
contentType = response.ContentType;
}
else if (recordingInfo.HasImage ?? true)
else
{
var service = _liveTvManager.Services.FirstOrDefault(i => string.Equals(i.Name, item.ServiceName, StringComparison.OrdinalIgnoreCase));
_logger.Error("Provider did not return an image content type.");
}
}
else if (liveTvItem.RecordingInfo.HasImage ?? true)
{
var service = _liveTvManager.Services.FirstOrDefault(i => string.Equals(i.Name, liveTvItem.ServiceName, StringComparison.OrdinalIgnoreCase));
if (service != null)
{
try
{
var response = await service.GetRecordingImageAsync(recordingInfo.Id, cancellationToken).ConfigureAwait(false);
var response = await service.GetRecordingImageAsync(liveTvItem.RecordingInfo.Id, cancellationToken).ConfigureAwait(false);
if (response != null)
{
imageStream = response.Stream;
contentType = "image/" + response.Format.ToString().ToLower();
imageResponse.HasImage = true;
imageResponse.Stream = response.Stream;
imageResponse.Format = response.Format;
}
}
catch (NotImplementedException)
{
return false;
}
}
}
if (imageStream != null)
return imageResponse;
}
public string Name
{
// Dummy up the original url
var url = item.ServiceName + recordingInfo.Id;
await _providerManager.SaveImage((BaseItem)item, imageStream, contentType, ImageType.Primary, null, cancellationToken).ConfigureAwait(false);
return true;
get { return "Live TV Service Provider"; }
}
return false;
}
public override MetadataProviderPriority Priority
public bool Supports(IHasImages item)
{
get { return MetadataProviderPriority.Second; }
return item is ILiveTvRecording;
}
public override ItemUpdateType ItemUpdateType
public int Order
{
get
get { return 0; }
}
public bool HasChanged(IHasMetadata item, DateTime date)
{
return ItemUpdateType.ImageUpdate;
}
return !item.HasImage(ImageType.Primary) && (DateTime.UtcNow - date).TotalHours >= 3;
}
}
}