fix book providers

This commit is contained in:
Luke Pulverenti 2017-10-06 11:49:22 -04:00
parent db01b79901
commit 43eec485e9
7 changed files with 93 additions and 5 deletions

View File

@ -1,8 +1,9 @@
using MediaBrowser.Model.Serialization;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Serialization;
namespace MediaBrowser.Controller.Entities.Audio
{
public class AudioPodcast : Audio
public class AudioPodcast : Audio, IHasLookupInfo<SongInfo>
{
[IgnoreDataMember]
public override bool SupportsPositionTicksResume
@ -13,6 +14,15 @@ namespace MediaBrowser.Controller.Entities.Audio
}
}
[IgnoreDataMember]
public override bool SupportsPlayedStatus
{
get
{
return true;
}
}
public override double? GetDefaultPrimaryImageAspectRatio()
{
return 1;

View File

@ -1,11 +1,12 @@
using System;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.Entities
{
public class AudioBook : Audio.Audio, IHasSeries
public class AudioBook : Audio.Audio, IHasSeries, IHasLookupInfo<SongInfo>
{
[IgnoreDataMember]
public override bool SupportsPositionTicksResume

View File

@ -1,4 +1,5 @@
using MediaBrowser.Controller.Entities;
using System;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using System.Threading;
using System.Threading.Tasks;
@ -13,6 +14,7 @@ namespace MediaBrowser.Controller.Providers
/// <param name="item">The item.</param>
/// <returns><c>true</c> if this instance can refresh the specified item; otherwise, <c>false</c>.</returns>
bool CanRefresh(IHasMetadata item);
bool CanRefreshPrimary(Type type);
/// <summary>
/// Refreshes the metadata.

View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Providers;
namespace MediaBrowser.Providers.Books
{
public class GoogleBooksProvider : IRemoteMetadataProvider<AudioBook, SongInfo>
{
public string Name => "Google Books";
private readonly IHttpClient _httpClient;
public GoogleBooksProvider(IHttpClient httpClient)
{
_httpClient = httpClient;
}
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClient.GetResponse(new HttpRequestOptions
{
CancellationToken = cancellationToken,
Url = url,
BufferContent = false
});
}
public async Task<MetadataResult<AudioBook>> GetMetadata(SongInfo info, CancellationToken cancellationToken)
{
return new MetadataResult<AudioBook>();
}
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SongInfo searchInfo, CancellationToken cancellationToken)
{
return new List<RemoteSearchResult>();
}
}
}

View File

@ -453,6 +453,11 @@ namespace MediaBrowser.Providers.Manager
return item is TItemType;
}
public bool CanRefreshPrimary(Type type)
{
return type == typeof(TItemType);
}
protected virtual async Task<RefreshResult> RefreshWithProviders(MetadataResult<TItemType> metadata,
TIdType id,
MetadataRefreshOptions options,

View File

@ -118,7 +118,29 @@ namespace MediaBrowser.Providers.Manager
public Task<ItemUpdateType> RefreshSingleItem(IHasMetadata item, MetadataRefreshOptions options, CancellationToken cancellationToken)
{
var service = _metadataServices.FirstOrDefault(i => i.CanRefresh(item));
IMetadataService service = null;
var type = item.GetType();
foreach (var current in _metadataServices)
{
if (current.CanRefreshPrimary(type))
{
service = current;
break;
}
}
if (service == null)
{
foreach (var current in _metadataServices)
{
if (current.CanRefresh(item))
{
service = current;
break;
}
}
}
if (service != null)
{
@ -452,6 +474,8 @@ namespace MediaBrowser.Providers.Manager
GetPluginSummary<MusicAlbum>(),
GetPluginSummary<MusicArtist>(),
GetPluginSummary<Audio>(),
GetPluginSummary<AudioBook>(),
GetPluginSummary<AudioPodcast>(),
GetPluginSummary<Genre>(),
GetPluginSummary<Studio>(),
GetPluginSummary<GameGenre>(),

View File

@ -41,6 +41,7 @@
<Compile Include="Books\AudioBookMetadataService.cs" />
<Compile Include="Books\AudioPodcastMetadataService.cs" />
<Compile Include="Books\BookMetadataService.cs" />
<Compile Include="Books\GoogleBooksProvider.cs" />
<Compile Include="BoxSets\BoxSetMetadataService.cs" />
<Compile Include="BoxSets\MovieDbBoxSetImageProvider.cs" />
<Compile Include="BoxSets\MovieDbBoxSetProvider.cs" />