Support anime series ordering with core providers

pull/702/head
Thomas Gillen 11 years ago committed by Tim Hobbs
parent ac81b4e3ca
commit c2537a57eb

@ -187,6 +187,7 @@
<Compile Include="Providers\MetadataRefreshOptions.cs" />
<Compile Include="Providers\NameParser.cs" />
<Compile Include="Providers\MetadataStatus.cs" />
<Compile Include="Providers\ISeriesOrderManager.cs" />
<Compile Include="Session\ISessionManager.cs" />
<Compile Include="Drawing\ImageExtensions.cs" />
<Compile Include="Entities\AggregateFolder.cs" />

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MediaBrowser.Common;
namespace MediaBrowser.Controller.Providers
{
public interface ISeriesOrderProvider
{
string OrderType { get; }
Task<int?> FindSeriesIndex(string seriesName);
}
public static class SeriesOrderTypes
{
public const string Anime = "Anime";
}
public interface ISeriesOrderManager
{
Task<int?> FindSeriesIndex(string orderType, string seriesName);
void AddParts(IEnumerable<ISeriesOrderProvider> orderProviders);
}
}

@ -0,0 +1,36 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Common;
using MediaBrowser.Controller.Providers;
namespace MediaBrowser.Providers.Manager
{
public class SeriesOrderManager : ISeriesOrderManager
{
private Dictionary<string, ISeriesOrderProvider[]> _providers;
public void AddParts(IEnumerable<ISeriesOrderProvider> orderProviders)
{
_providers = orderProviders
.GroupBy(p => p.OrderType)
.ToDictionary(g => g.Key, g => g.ToArray());
}
public async Task<int?> FindSeriesIndex(string orderType, string seriesName)
{
ISeriesOrderProvider[] providers;
if (!_providers.TryGetValue(orderType, out providers))
return null;
foreach (ISeriesOrderProvider provider in providers)
{
int? index = await provider.FindSeriesIndex(seriesName);
if (index != null)
return index;
}
return null;
}
}
}

@ -103,6 +103,7 @@
<Compile Include="Games\GameXmlParser.cs" />
<Compile Include="Games\GameXmlProvider.cs" />
<Compile Include="Games\GameSystemXmlProvider.cs" />
<Compile Include="Manager\SeriesOrderManager.cs" />
<Compile Include="MediaInfo\FFProbeAudioInfo.cs" />
<Compile Include="MediaInfo\FFProbeHelpers.cs" />
<Compile Include="MediaInfo\FFProbeProvider.cs" />

@ -77,7 +77,8 @@ namespace MediaBrowser.Providers.TV
try
{
AddImages(list, season.IndexNumber.Value, xmlPath, cancellationToken);
int seasonNumber = AdjustForSeriesOffset(series, season.IndexNumber.Value);
AddImages(list, seasonNumber, xmlPath, cancellationToken);
}
catch (FileNotFoundException)
{
@ -115,6 +116,15 @@ namespace MediaBrowser.Providers.TV
.ThenByDescending(i => i.VoteCount ?? 0);
}
private int AdjustForSeriesOffset(Series series, int seasonNumber)
{
var offset = TvdbSeriesProvider.GetSeriesOffset(series.ProviderIds);
if (offset != null)
return (int)(seasonNumber + offset);
return seasonNumber;
}
private void AddImages(List<RemoteImageInfo> list, int seasonNumber, string xmlPath, CancellationToken cancellationToken)
{
using (var streamReader = new StreamReader(xmlPath, Encoding.UTF8))

@ -62,8 +62,9 @@ namespace MediaBrowser.Providers.TV
{
// Process images
var seriesDataPath = TvdbSeriesProvider.GetSeriesDataPath(_config.ApplicationPaths, seriesId);
var indexOffset = TvdbSeriesProvider.GetSeriesOffset(series.ProviderIds) ?? 0;
var files = TvdbEpisodeProvider.Current.GetEpisodeXmlFiles(episode.ParentIndexNumber, episode.IndexNumber, episode.IndexNumberEnd, seriesDataPath);
var files = TvdbEpisodeProvider.Current.GetEpisodeXmlFiles(episode.ParentIndexNumber + indexOffset, episode.IndexNumber, episode.IndexNumberEnd, seriesDataPath);
var result = files.Select(i => GetImageInfo(i, cancellationToken))
.Where(i => i != null);

@ -52,7 +52,7 @@ namespace MediaBrowser.Providers.TV
try
{
var item = FetchEpisodeData(searchInfo, seriesDataPath, cancellationToken);
var item = FetchEpisodeData(searchInfo, seriesDataPath, searchInfo.SeriesProviderIds, cancellationToken);
if (item != null)
{
@ -96,7 +96,7 @@ namespace MediaBrowser.Providers.TV
try
{
result.Item = FetchEpisodeData(searchInfo, seriesDataPath, cancellationToken);
result.Item = FetchEpisodeData(searchInfo, seriesDataPath, searchInfo.SeriesProviderIds, cancellationToken);
result.HasMetadata = result.Item != null;
}
catch (FileNotFoundException)
@ -213,7 +213,7 @@ namespace MediaBrowser.Providers.TV
/// <param name="seriesDataPath">The series data path.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
private Episode FetchEpisodeData(EpisodeInfo id, string seriesDataPath, CancellationToken cancellationToken)
private Episode FetchEpisodeData(EpisodeInfo id, string seriesDataPath, Dictionary<string, string> seriesProviderIds, CancellationToken cancellationToken)
{
if (id.IndexNumber == null)
{
@ -221,7 +221,8 @@ namespace MediaBrowser.Providers.TV
}
var episodeNumber = id.IndexNumber.Value;
var seasonNumber = id.ParentIndexNumber;
var seasonOffset = TvdbSeriesProvider.GetSeriesOffset(seriesProviderIds) ?? 0;
var seasonNumber = id.ParentIndexNumber + seasonOffset;
if (seasonNumber == null)
{

@ -22,8 +22,9 @@ namespace MediaBrowser.Providers.TV
{
public class TvdbSeasonImageProvider : IRemoteImageProvider, IHasOrder, IHasChangeMonitor
{
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
private readonly IServerConfigurationManager _config;
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private readonly IHttpClient _httpClient;
private readonly IFileSystem _fileSystem;
@ -77,7 +78,8 @@ namespace MediaBrowser.Providers.TV
try
{
return GetImages(path, item.GetPreferredMetadataLanguage(), season.IndexNumber.Value, cancellationToken);
int seasonNumber = AdjustForSeriesOffset(series, season.IndexNumber.Value);
return GetImages(path, item.GetPreferredMetadataLanguage(), seasonNumber, cancellationToken);
}
catch (FileNotFoundException)
{
@ -88,7 +90,16 @@ namespace MediaBrowser.Providers.TV
return new RemoteImageInfo[] { };
}
private IEnumerable<RemoteImageInfo> GetImages(string xmlPath, string preferredLanguage, int seasonNumber, CancellationToken cancellationToken)
private int AdjustForSeriesOffset(Series series, int seasonNumber)
{
var offset = TvdbSeriesProvider.GetSeriesOffset(series.ProviderIds);
if (offset != null)
return (int) (seasonNumber + offset);
return seasonNumber;
}
internal static IEnumerable<RemoteImageInfo> GetImages(string xmlPath, string preferredLanguage, int seasonNumber, CancellationToken cancellationToken)
{
var settings = new XmlReaderSettings
{
@ -159,7 +170,7 @@ namespace MediaBrowser.Providers.TV
.ToList();
}
private void AddImage(XmlReader reader, List<RemoteImageInfo> images, int seasonNumber)
private static void AddImage(XmlReader reader, List<RemoteImageInfo> images, int seasonNumber)
{
reader.MoveToContent();
@ -186,7 +197,7 @@ namespace MediaBrowser.Providers.TV
double rval;
if (double.TryParse(val, NumberStyles.Any, _usCulture, out rval))
if (double.TryParse(val, NumberStyles.Any, UsCulture, out rval))
{
rating = rval;
}
@ -200,7 +211,7 @@ namespace MediaBrowser.Providers.TV
int rval;
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out rval))
if (int.TryParse(val, NumberStyles.Integer, UsCulture, out rval))
{
voteCount = rval;
}
@ -237,12 +248,12 @@ namespace MediaBrowser.Providers.TV
{
int rval;
if (int.TryParse(resolutionParts[0], NumberStyles.Integer, _usCulture, out rval))
if (int.TryParse(resolutionParts[0], NumberStyles.Integer, UsCulture, out rval))
{
width = rval;
}
if (int.TryParse(resolutionParts[1], NumberStyles.Integer, _usCulture, out rval))
if (int.TryParse(resolutionParts[1], NumberStyles.Integer, UsCulture, out rval))
{
height = rval;
}
@ -285,7 +296,7 @@ namespace MediaBrowser.Providers.TV
CommunityRating = rating,
VoteCount = voteCount,
Url = TVUtils.BannerUrl + url,
ProviderName = Name,
ProviderName = ProviderName,
Language = language,
Width = width,
Height = height

@ -77,6 +77,10 @@ namespace MediaBrowser.Providers.TV
try
{
var seriesOffset = TvdbSeriesProvider.GetSeriesOffset(series.ProviderIds);
if (seriesOffset != null)
return TvdbSeasonImageProvider.GetImages(path, language, seriesOffset.Value + 1, cancellationToken);
return GetImages(path, language, cancellationToken);
}
catch (FileNotFoundException)

@ -25,6 +25,8 @@ namespace MediaBrowser.Providers.TV
{
public class TvdbSeriesProvider : IRemoteMetadataProvider<Series, SeriesInfo>, IHasOrder
{
internal const string TvdbSeriesOffset = "TvdbSeriesOffset";
internal readonly SemaphoreSlim TvDbResourcePool = new SemaphoreSlim(2, 2);
internal static TvdbSeriesProvider Current { get; private set; }
private readonly IZipClient _zipClient;
@ -33,14 +35,16 @@ namespace MediaBrowser.Providers.TV
private readonly IServerConfigurationManager _config;
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private readonly ILogger _logger;
private readonly ISeriesOrderManager _seriesOrder;
public TvdbSeriesProvider(IZipClient zipClient, IHttpClient httpClient, IFileSystem fileSystem, IServerConfigurationManager config, ILogger logger)
public TvdbSeriesProvider(IZipClient zipClient, IHttpClient httpClient, IFileSystem fileSystem, IServerConfigurationManager config, ILogger logger, ISeriesOrderManager seriesOrder)
{
_zipClient = zipClient;
_httpClient = httpClient;
_fileSystem = fileSystem;
_config = config;
_logger = logger;
_seriesOrder = seriesOrder;
Current = this;
}
@ -92,11 +96,35 @@ namespace MediaBrowser.Providers.TV
result.HasMetadata = true;
FetchSeriesData(result.Item, seriesId, cancellationToken);
await FindAnimeSeriesIndex(result.Item, itemId).ConfigureAwait(false);
}
return result;
}
private async Task FindAnimeSeriesIndex(Series series, SeriesInfo info)
{
var index = await _seriesOrder.FindSeriesIndex(SeriesOrderTypes.Anime, series.Name);
if (index == null)
return;
var offset = info.AnimeSeriesIndex - index;
series.SetProviderId(TvdbSeriesOffset, offset.ToString());
}
internal static int? GetSeriesOffset(Dictionary<string, string> seriesProviderIds)
{
string offsetString;
if (!seriesProviderIds.TryGetValue(TvdbSeriesOffset, out offsetString))
return null;
int offset;
if (int.TryParse(offsetString, out offset))
return offset;
return null;
}
/// <summary>
/// Fetches the series data.
/// </summary>

@ -157,6 +157,7 @@ namespace MediaBrowser.ServerApplication
private IHttpServer HttpServer { get; set; }
private IDtoService DtoService { get; set; }
private IImageProcessor ImageProcessor { get; set; }
private ISeriesOrderManager SeriesOrderManager { get; set; }
/// <summary>
/// Gets or sets the media encoder.
@ -453,6 +454,9 @@ namespace MediaBrowser.ServerApplication
ProviderManager = new ProviderManager(HttpClient, ServerConfigurationManager, LibraryMonitor, LogManager, FileSystemManager);
RegisterSingleInstance(ProviderManager);
SeriesOrderManager = new SeriesOrderManager();
RegisterSingleInstance(SeriesOrderManager);
RegisterSingleInstance<ISearchEngine>(() => new SearchEngine(LogManager, LibraryManager, UserManager));
SessionManager = new SessionManager(UserDataManager, ServerConfigurationManager, Logger, UserRepository, LibraryManager, UserManager);
@ -680,6 +684,8 @@ namespace MediaBrowser.ServerApplication
GetExports<IImageSaver>(),
GetExports<IExternalId>());
SeriesOrderManager.AddParts(GetExports<ISeriesOrderProvider>());
ImageProcessor.AddParts(GetExports<IImageEnhancer>());
LiveTvManager.AddParts(GetExports<ILiveTvService>());

@ -251,7 +251,4 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
EndGlobal

Loading…
Cancel
Save