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.")] [Api(Description = "Gets an Http live streaming segment file. Internal use only.")]
public class GetHlsVideoSegment : VideoStreamRequest 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; } public string PlaylistId { get; set; }
/// <summary> /// <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\GameSystemMetadataService.cs" />
<Compile Include="Games\GameSystemXmlParser.cs" /> <Compile Include="Games\GameSystemXmlParser.cs" />
<Compile Include="Genres\GenreMetadataService.cs" /> <Compile Include="Genres\GenreMetadataService.cs" />
<Compile Include="LiveTv\AudioRecordingService.cs" />
<Compile Include="LiveTv\ChannelMetadataService.cs" /> <Compile Include="LiveTv\ChannelMetadataService.cs" />
<Compile Include="LiveTv\ChannelXmlProvider.cs" /> <Compile Include="LiveTv\ChannelXmlProvider.cs" />
<Compile Include="LiveTv\ProgramMetadataService.cs" /> <Compile Include="LiveTv\ProgramMetadataService.cs" />
<Compile Include="LiveTv\VideoRecordingService.cs" />
<Compile Include="Manager\ImageSaver.cs" /> <Compile Include="Manager\ImageSaver.cs" />
<Compile Include="Manager\ItemImageProvider.cs" /> <Compile Include="Manager\ItemImageProvider.cs" />
<Compile Include="Manager\ProviderManager.cs" /> <Compile Include="Manager\ProviderManager.cs" />
@ -121,7 +123,7 @@
<Compile Include="Music\MusicVideoMetadataService.cs" /> <Compile Include="Music\MusicVideoMetadataService.cs" />
<Compile Include="Music\MusicVideoXmlProvider.cs" /> <Compile Include="Music\MusicVideoXmlProvider.cs" />
<Compile Include="Omdb\OmdbProvider.cs" /> <Compile Include="Omdb\OmdbProvider.cs" />
<Compile Include="Omdb\OmdbSeriesProvider.cs" /> <Compile Include="Omdb\OmdbItemProvider.cs" />
<Compile Include="People\MovieDbPersonImageProvider.cs" /> <Compile Include="People\MovieDbPersonImageProvider.cs" />
<Compile Include="Movies\MovieUpdatesPrescanTask.cs" /> <Compile Include="Movies\MovieUpdatesPrescanTask.cs" />
<Compile Include="Movies\MovieXmlParser.cs" /> <Compile Include="Movies\MovieXmlParser.cs" />

View File

@ -17,7 +17,7 @@ namespace MediaBrowser.Providers.Music
public async Task<MetadataResult<MusicArtist>> GetMetadata(ArtistInfo id, CancellationToken cancellationToken) public async Task<MetadataResult<MusicArtist>> GetMetadata(ArtistInfo id, CancellationToken cancellationToken)
{ {
var result = new MetadataResult<MusicArtist>(); var result = new MetadataResult<MusicArtist>();
var musicBrainzId = id.GetProviderId(MetadataProviders.Musicbrainz) ?? await FindId(id, cancellationToken).ConfigureAwait(false); var musicBrainzId = id.GetProviderId(MetadataProviders.Musicbrainz) ?? await FindId(id, cancellationToken).ConfigureAwait(false);
if (!string.IsNullOrWhiteSpace(musicBrainzId)) if (!string.IsNullOrWhiteSpace(musicBrainzId))

View File

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

View File

@ -1,156 +1,111 @@
using System; using MediaBrowser.Common.Net;
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.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging; 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 namespace MediaBrowser.Server.Implementations.LiveTv
{ {
public class RecordingImageProvider : BaseMetadataProvider public class RecordingImageProvider : IDynamicImageProvider, IHasChangeMonitor
{ {
private readonly ILiveTvManager _liveTvManager; private readonly ILiveTvManager _liveTvManager;
private readonly IProviderManager _providerManager;
private readonly IFileSystem _fileSystem;
private readonly IHttpClient _httpClient; private readonly IHttpClient _httpClient;
private readonly ILogger _logger;
public RecordingImageProvider(ILogManager logManager, IServerConfigurationManager configurationManager, ILiveTvManager liveTvManager, IProviderManager providerManager, IFileSystem fileSystem, IHttpClient httpClient) public RecordingImageProvider(ILiveTvManager liveTvManager, IHttpClient httpClient, ILogger logger)
: base(logManager, configurationManager)
{ {
_liveTvManager = liveTvManager; _liveTvManager = liveTvManager;
_providerManager = providerManager;
_fileSystem = fileSystem;
_httpClient = httpClient; _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) var imageResponse = new DynamicImageResponse();
{
if (item.HasImage(ImageType.Primary)) if (!string.IsNullOrEmpty(liveTvItem.RecordingInfo.ImagePath))
{ {
SetLastRefreshed(item, DateTime.UtcNow, providerInfo); imageResponse.Path = liveTvItem.RecordingInfo.ImagePath;
return true; imageResponse.HasImage = true;
} }
else if (!string.IsNullOrEmpty(liveTvItem.RecordingInfo.ImageUrl))
var changed = true;
try
{
changed = await DownloadImage((ILiveTvRecording)item, cancellationToken).ConfigureAwait(false);
}
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))
{ {
var options = new HttpRequestOptions var options = new HttpRequestOptions
{ {
CancellationToken = cancellationToken, CancellationToken = cancellationToken,
Url = recordingInfo.ImageUrl Url = liveTvItem.RecordingInfo.ImageUrl
}; };
var response = await _httpClient.GetResponse(options).ConfigureAwait(false); 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."); imageResponse.HasImage = true;
return false; imageResponse.Stream = response.Content;
imageResponse.SetFormatFromMimeType(response.ContentType);
}
else
{
_logger.Error("Provider did not return an image content type.");
} }
imageStream = response.Content;
contentType = response.ContentType;
} }
else if (recordingInfo.HasImage ?? true) else if (liveTvItem.RecordingInfo.HasImage ?? true)
{ {
var service = _liveTvManager.Services.FirstOrDefault(i => string.Equals(i.Name, item.ServiceName, StringComparison.OrdinalIgnoreCase)); var service = _liveTvManager.Services.FirstOrDefault(i => string.Equals(i.Name, liveTvItem.ServiceName, StringComparison.OrdinalIgnoreCase));
if (service != null) if (service != null)
{ {
try 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) if (response != null)
{ {
imageStream = response.Stream; imageResponse.HasImage = true;
contentType = "image/" + response.Format.ToString().ToLower(); imageResponse.Stream = response.Stream;
imageResponse.Format = response.Format;
} }
} }
catch (NotImplementedException) catch (NotImplementedException)
{ {
return false;
} }
} }
} }
if (imageStream != null) return imageResponse;
{
// 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;
}
return false;
} }
public override MetadataProviderPriority Priority public string Name
{ {
get { return MetadataProviderPriority.Second; } get { return "Live TV Service Provider"; }
} }
public override ItemUpdateType ItemUpdateType public bool Supports(IHasImages item)
{ {
get return item is ILiveTvRecording;
{ }
return ItemUpdateType.ImageUpdate;
} public int Order
{
get { return 0; }
}
public bool HasChanged(IHasMetadata item, DateTime date)
{
return !item.HasImage(ImageType.Primary) && (DateTime.UtcNow - date).TotalHours >= 3;
} }
} }
} }