mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-08 16:58:50 +01:00
More DI
This commit is contained in:
@@ -4,6 +4,7 @@ using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.MediaInfo;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.MediaInfo;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -28,29 +29,44 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
|
||||
/// Gets or sets the bluray examiner.
|
||||
/// </summary>
|
||||
/// <value>The bluray examiner.</value>
|
||||
private IBlurayExaminer BlurayExaminer { get; set; }
|
||||
private readonly IBlurayExaminer _blurayExaminer;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// The _iso manager
|
||||
/// </summary>
|
||||
private readonly IIsoManager _isoManager;
|
||||
|
||||
/// <summary>
|
||||
/// The _protobuf serializer
|
||||
/// </summary>
|
||||
private readonly IProtobufSerializer _protobufSerializer;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FFProbeVideoInfoProvider" /> class.
|
||||
/// </summary>
|
||||
/// <param name="isoManager">The iso manager.</param>
|
||||
/// <param name="blurayExaminer">The bluray examiner.</param>
|
||||
/// <param name="protobufSerializer">The protobuf serializer.</param>
|
||||
/// <exception cref="System.ArgumentNullException">blurayExaminer</exception>
|
||||
public FFProbeVideoInfoProvider(IIsoManager isoManager, IBlurayExaminer blurayExaminer)
|
||||
public FFProbeVideoInfoProvider(IIsoManager isoManager, IBlurayExaminer blurayExaminer, IProtobufSerializer protobufSerializer)
|
||||
: base()
|
||||
{
|
||||
if (isoManager == null)
|
||||
{
|
||||
throw new ArgumentNullException("isoManager");
|
||||
}
|
||||
if (blurayExaminer == null)
|
||||
{
|
||||
throw new ArgumentNullException("blurayExaminer");
|
||||
}
|
||||
if (protobufSerializer == null)
|
||||
{
|
||||
throw new ArgumentNullException("protobufSerializer");
|
||||
}
|
||||
|
||||
BlurayExaminer = blurayExaminer;
|
||||
_blurayExaminer = blurayExaminer;
|
||||
_isoManager = isoManager;
|
||||
_protobufSerializer = protobufSerializer;
|
||||
|
||||
BdInfoCache = new FileSystemRepository(Path.Combine(Kernel.Instance.ApplicationPaths.CachePath, "bdinfo"));
|
||||
}
|
||||
@@ -315,13 +331,13 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
|
||||
|
||||
try
|
||||
{
|
||||
result = Kernel.Instance.ProtobufSerializer.DeserializeFromFile<BlurayDiscInfo>(cacheFile);
|
||||
result = _protobufSerializer.DeserializeFromFile<BlurayDiscInfo>(cacheFile);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
result = GetBDInfo(inputPath);
|
||||
|
||||
Kernel.Instance.ProtobufSerializer.SerializeToFile(result, cacheFile);
|
||||
_protobufSerializer.SerializeToFile(result, cacheFile);
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
@@ -400,7 +416,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
|
||||
/// <returns>VideoStream.</returns>
|
||||
private BlurayDiscInfo GetBDInfo(string path)
|
||||
{
|
||||
return BlurayExaminer.GetDiscInfo(path);
|
||||
return _blurayExaminer.GetDiscInfo(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.Serialization;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Model.Entities;
|
||||
@@ -15,6 +14,7 @@ using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
|
||||
namespace MediaBrowser.Controller.Providers.Movies
|
||||
{
|
||||
@@ -30,6 +30,27 @@ namespace MediaBrowser.Controller.Providers.Movies
|
||||
/// </summary>
|
||||
public class MovieDbProvider : BaseMetadataProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the json serializer.
|
||||
/// </summary>
|
||||
/// <value>The json serializer.</value>
|
||||
protected IJsonSerializer JsonSerializer { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MovieDbProvider" /> class.
|
||||
/// </summary>
|
||||
/// <param name="jsonSerializer">The json serializer.</param>
|
||||
/// <exception cref="System.ArgumentNullException">jsonSerializer</exception>
|
||||
public MovieDbProvider(IJsonSerializer jsonSerializer)
|
||||
: base()
|
||||
{
|
||||
if (jsonSerializer == null)
|
||||
{
|
||||
throw new ArgumentNullException("jsonSerializer");
|
||||
}
|
||||
JsonSerializer = jsonSerializer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the priority.
|
||||
/// </summary>
|
||||
@@ -93,7 +114,7 @@ namespace MediaBrowser.Controller.Providers.Movies
|
||||
{
|
||||
get
|
||||
{
|
||||
LazyInitializer.EnsureInitialized(ref _tmdbSettingsTask, ref _tmdbSettingsTaskInitialized, ref _tmdbSettingsTaskSyncLock, GetTmdbSettings);
|
||||
LazyInitializer.EnsureInitialized(ref _tmdbSettingsTask, ref _tmdbSettingsTaskInitialized, ref _tmdbSettingsTaskSyncLock, () => GetTmdbSettings(JsonSerializer));
|
||||
return _tmdbSettingsTask;
|
||||
}
|
||||
}
|
||||
@@ -102,13 +123,13 @@ namespace MediaBrowser.Controller.Providers.Movies
|
||||
/// Gets the TMDB settings.
|
||||
/// </summary>
|
||||
/// <returns>Task{TmdbSettingsResult}.</returns>
|
||||
private static async Task<TmdbSettingsResult> GetTmdbSettings()
|
||||
private static async Task<TmdbSettingsResult> GetTmdbSettings(IJsonSerializer jsonSerializer)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var json = await Kernel.Instance.HttpManager.Get(String.Format(TmdbConfigUrl, ApiKey), Kernel.Instance.ResourcePools.MovieDb, CancellationToken.None).ConfigureAwait(false))
|
||||
{
|
||||
return JsonSerializer.DeserializeFromStream<TmdbSettingsResult>(json);
|
||||
return jsonSerializer.DeserializeFromStream<TmdbSettingsResult>(json);
|
||||
}
|
||||
}
|
||||
catch (HttpException e)
|
||||
@@ -168,7 +189,7 @@ namespace MediaBrowser.Controller.Providers.Movies
|
||||
{
|
||||
//in addition to ours, we need to set the last refreshed time for the local data provider
|
||||
//so it won't see the new files we download and process them all over again
|
||||
if (JsonProvider == null) JsonProvider = new MovieProviderFromJson();
|
||||
if (JsonProvider == null) JsonProvider = new MovieProviderFromJson(JsonSerializer);
|
||||
var data = item.ProviderData.GetValueOrDefault(JsonProvider.Id, new BaseProviderInfo { ProviderId = JsonProvider.Id });
|
||||
data.LastRefreshed = value;
|
||||
item.ProviderData[JsonProvider.Id] = data;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using MediaBrowser.Common.Serialization;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
@@ -12,6 +12,10 @@ namespace MediaBrowser.Controller.Providers.Movies
|
||||
/// </summary>
|
||||
public class MovieProviderFromJson : MovieDbProvider
|
||||
{
|
||||
public MovieProviderFromJson(IJsonSerializer jsonSerializer) : base(jsonSerializer)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the priority.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using MediaBrowser.Common.Serialization;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
@@ -12,6 +12,10 @@ namespace MediaBrowser.Controller.Providers.Movies
|
||||
/// </summary>
|
||||
class PersonProviderFromJson : TmdbPersonProvider
|
||||
{
|
||||
public PersonProviderFromJson(IJsonSerializer jsonSerializer) : base(jsonSerializer)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Supportses the specified item.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using MediaBrowser.Common.Serialization;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Net;
|
||||
using System;
|
||||
@@ -10,6 +9,7 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
|
||||
namespace MediaBrowser.Controller.Providers.Movies
|
||||
{
|
||||
@@ -23,6 +23,27 @@ namespace MediaBrowser.Controller.Providers.Movies
|
||||
/// </summary>
|
||||
protected const string MetaFileName = "MBPerson.json";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the json serializer.
|
||||
/// </summary>
|
||||
/// <value>The json serializer.</value>
|
||||
protected IJsonSerializer JsonSerializer { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MovieDbProvider" /> class.
|
||||
/// </summary>
|
||||
/// <param name="jsonSerializer">The json serializer.</param>
|
||||
/// <exception cref="System.ArgumentNullException">jsonSerializer</exception>
|
||||
public TmdbPersonProvider(IJsonSerializer jsonSerializer)
|
||||
: base()
|
||||
{
|
||||
if (jsonSerializer == null)
|
||||
{
|
||||
throw new ArgumentNullException("jsonSerializer");
|
||||
}
|
||||
JsonSerializer = jsonSerializer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Supportses the specified item.
|
||||
/// </summary>
|
||||
@@ -56,7 +77,7 @@ namespace MediaBrowser.Controller.Providers.Movies
|
||||
protected override async Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
|
||||
var person = (Person)item;
|
||||
var tasks = new List<Task>();
|
||||
|
||||
@@ -169,7 +190,7 @@ namespace MediaBrowser.Controller.Providers.Movies
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
|
||||
if (searchResult != null && searchResult.Biography != null)
|
||||
{
|
||||
ProcessInfo(person, searchResult);
|
||||
|
||||
Reference in New Issue
Block a user