Merge pull request #2020 from Bond-009/baseurl

Add support for multi segment base urls
This commit is contained in:
dkanada 2019-12-10 22:11:32 +09:00 committed by GitHub
commit b5d0bd0d76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
73 changed files with 1252 additions and 714 deletions

View file

@ -1,7 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Emby.Dlna.Main; using Emby.Dlna.Main;
@ -195,7 +193,7 @@ namespace Emby.Dlna.Api
private ControlResponse PostAsync(Stream requestStream, IUpnpService service) private ControlResponse PostAsync(Stream requestStream, IUpnpService service)
{ {
var id = GetPathValue(2); var id = GetPathValue(2).ToString();
return service.ProcessControlRequest(new ControlRequest return service.ProcessControlRequest(new ControlRequest
{ {
@ -206,51 +204,99 @@ namespace Emby.Dlna.Api
}); });
} }
protected string GetPathValue(int index) // Copied from MediaBrowser.Api/BaseApiService.cs
// TODO: Remove code duplication
/// <summary>
/// Gets the path segment at the specified index.
/// </summary>
/// <param name="index">The index of the path segment.</param>
/// <returns>The path segment at the specified index.</returns>
/// <exception cref="IndexOutOfRangeException" >Path doesn't contain enough segments.</exception>
/// <exception cref="InvalidDataException" >Path doesn't start with the base url.</exception>
protected internal ReadOnlySpan<char> GetPathValue(int index)
{ {
var pathInfo = Parse(Request.PathInfo); static void ThrowIndexOutOfRangeException()
var first = pathInfo[0]; => throw new IndexOutOfRangeException("Path doesn't contain enough segments.");
static void ThrowInvalidDataException()
=> throw new InvalidDataException("Path doesn't start with the base url.");
ReadOnlySpan<char> path = Request.PathInfo;
// Remove the protocol part from the url
int pos = path.LastIndexOf("://");
if (pos != -1)
{
path = path.Slice(pos + 3);
}
// Remove the query string
pos = path.LastIndexOf('?');
if (pos != -1)
{
path = path.Slice(0, pos);
}
// Remove the domain
pos = path.IndexOf('/');
if (pos != -1)
{
path = path.Slice(pos);
}
// Remove base url
string baseUrl = _configurationManager.Configuration.BaseUrl; string baseUrl = _configurationManager.Configuration.BaseUrl;
int baseUrlLen = baseUrl.Length;
// backwards compatibility if (baseUrlLen != 0)
if (baseUrl.Length == 0)
{ {
if (string.Equals(first, "mediabrowser", StringComparison.OrdinalIgnoreCase) if (path.StartsWith(baseUrl, StringComparison.OrdinalIgnoreCase))
|| string.Equals(first, "emby", StringComparison.OrdinalIgnoreCase))
{ {
index++; path = path.Slice(baseUrlLen);
} }
} else
else if (string.Equals(first, baseUrl.Remove(0, 1)))
{
index++;
var second = pathInfo[1];
if (string.Equals(second, "mediabrowser", StringComparison.OrdinalIgnoreCase)
|| string.Equals(second, "emby", StringComparison.OrdinalIgnoreCase))
{ {
index++; // The path doesn't start with the base url,
// how did we get here?
ThrowInvalidDataException();
} }
} }
return pathInfo[index]; // Remove leading /
} path = path.Slice(1);
private static string[] Parse(string pathUri) // Backwards compatibility
{ const string Emby = "emby/";
var actionParts = pathUri.Split(new[] { "://" }, StringSplitOptions.None); if (path.StartsWith(Emby, StringComparison.OrdinalIgnoreCase))
var pathInfo = actionParts[actionParts.Length - 1];
var optionsPos = pathInfo.LastIndexOf('?');
if (optionsPos != -1)
{ {
pathInfo = pathInfo.Substring(0, optionsPos); path = path.Slice(Emby.Length);
} }
var args = pathInfo.Split('/'); const string MediaBrowser = "mediabrowser/";
if (path.StartsWith(MediaBrowser, StringComparison.OrdinalIgnoreCase))
{
path = path.Slice(MediaBrowser.Length);
}
return args.Skip(1).ToArray(); // Skip segments until we are at the right index
for (int i = 0; i < index; i++)
{
pos = path.IndexOf('/');
if (pos == -1)
{
ThrowIndexOutOfRangeException();
}
path = path.Slice(pos + 1);
}
// Remove the rest
pos = path.IndexOf('/');
if (pos != -1)
{
path = path.Slice(0, pos);
}
return path;
} }
public object Get(GetIcon request) public object Get(GetIcon request)

View file

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using Emby.Dlna.Service; using Emby.Dlna.Service;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
@ -104,7 +103,7 @@ namespace Emby.Dlna.ContentDirectory
{ {
if (!string.IsNullOrEmpty(profile.UserId)) if (!string.IsNullOrEmpty(profile.UserId))
{ {
var user = _userManager.GetUserById(profile.UserId); var user = _userManager.GetUserById(Guid.Parse(profile.UserId));
if (user != null) if (user != null)
{ {
@ -116,7 +115,7 @@ namespace Emby.Dlna.ContentDirectory
if (!string.IsNullOrEmpty(userId)) if (!string.IsNullOrEmpty(userId))
{ {
var user = _userManager.GetUserById(userId); var user = _userManager.GetUserById(Guid.Parse(userId));
if (user != null) if (user != null)
{ {

View file

@ -55,6 +55,7 @@ namespace Emby.Server.Implementations.Library
{ {
throw new ArgumentNullException(nameof(userData)); throw new ArgumentNullException(nameof(userData));
} }
if (item == null) if (item == null)
{ {
throw new ArgumentNullException(nameof(item)); throw new ArgumentNullException(nameof(item));
@ -160,11 +161,6 @@ namespace Emby.Server.Implementations.Library
return GetUserData(user, item.Id, item.GetUserDataKeys()); return GetUserData(user, item.Id, item.GetUserDataKeys());
} }
public UserItemData GetUserData(string userId, BaseItem item)
{
return GetUserData(new Guid(userId), item);
}
public UserItemData GetUserData(Guid userId, BaseItem item) public UserItemData GetUserData(Guid userId, BaseItem item)
{ {
return GetUserData(userId, item.Id, item.GetUserDataKeys()); return GetUserData(userId, item.Id, item.GetUserDataKeys());

View file

@ -194,10 +194,6 @@ namespace Emby.Server.Implementations.Library
return user; return user;
} }
/// <inheritdoc />
public User GetUserById(string id)
=> GetUserById(new Guid(id));
public User GetUserByName(string name) public User GetUserByName(string name)
{ {
if (string.IsNullOrWhiteSpace(name)) if (string.IsNullOrWhiteSpace(name))

View file

@ -31,13 +31,13 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
} }
/// <summary> /// <summary>
/// Creates the triggers that define when the task will run /// Creates the triggers that define when the task will run.
/// </summary> /// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns> /// <returns>IEnumerable{BaseTaskTrigger}.</returns>
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers() => new List<TaskTriggerInfo>(); public IEnumerable<TaskTriggerInfo> GetDefaultTriggers() => new List<TaskTriggerInfo>();
/// <summary> /// <summary>
/// Returns the task to be executed /// Returns the task to be executed.
/// </summary> /// </summary>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress.</param> /// <param name="progress">The progress.</param>
@ -52,9 +52,8 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
return Task.CompletedTask; return Task.CompletedTask;
} }
/// <summary> /// <summary>
/// Deletes the transcoded temp files from directory with a last write time less than a given date /// Deletes the transcoded temp files from directory with a last write time less than a given date.
/// </summary> /// </summary>
/// <param name="cancellationToken">The task cancellation token.</param> /// <param name="cancellationToken">The task cancellation token.</param>
/// <param name="directory">The directory.</param> /// <param name="directory">The directory.</param>

View file

@ -10,11 +10,9 @@ using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Plugins;
using MediaBrowser.Controller.Session; using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Diagnostics; using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Session; using MediaBrowser.Model.Session;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -22,26 +20,24 @@ using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api namespace MediaBrowser.Api
{ {
/// <summary> /// <summary>
/// Class ServerEntryPoint /// Class ServerEntryPoint.
/// </summary> /// </summary>
public class ApiEntryPoint : IServerEntryPoint public class ApiEntryPoint : IServerEntryPoint
{ {
/// <summary> /// <summary>
/// The instance /// The instance.
/// </summary> /// </summary>
public static ApiEntryPoint Instance; public static ApiEntryPoint Instance;
/// <summary> /// <summary>
/// Gets or sets the logger. /// The logger.
/// </summary> /// </summary>
/// <value>The logger.</value> private ILogger _logger;
internal ILogger Logger { get; private set; }
internal IHttpResultFactory ResultFactory { get; private set; }
/// <summary> /// <summary>
/// Gets the configuration manager. /// The configuration manager.
/// </summary> /// </summary>
internal IServerConfigurationManager ConfigurationManager { get; } private IServerConfigurationManager _serverConfigurationManager;
private readonly ISessionManager _sessionManager; private readonly ISessionManager _sessionManager;
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
@ -70,18 +66,16 @@ namespace MediaBrowser.Api
ISessionManager sessionManager, ISessionManager sessionManager,
IServerConfigurationManager config, IServerConfigurationManager config,
IFileSystem fileSystem, IFileSystem fileSystem,
IMediaSourceManager mediaSourceManager, IMediaSourceManager mediaSourceManager)
IHttpResultFactory resultFactory)
{ {
Logger = logger; _logger = logger;
_sessionManager = sessionManager; _sessionManager = sessionManager;
ConfigurationManager = config; _serverConfigurationManager = config;
_fileSystem = fileSystem; _fileSystem = fileSystem;
_mediaSourceManager = mediaSourceManager; _mediaSourceManager = mediaSourceManager;
ResultFactory = resultFactory;
_sessionManager.PlaybackProgress += _sessionManager_PlaybackProgress; _sessionManager.PlaybackProgress += OnPlaybackProgress;
_sessionManager.PlaybackStart += _sessionManager_PlaybackStart; _sessionManager.PlaybackStart += OnPlaybackStart;
Instance = this; Instance = this;
} }
@ -115,7 +109,7 @@ namespace MediaBrowser.Api
} }
} }
private void _sessionManager_PlaybackStart(object sender, PlaybackProgressEventArgs e) private void OnPlaybackStart(object sender, PlaybackProgressEventArgs e)
{ {
if (!string.IsNullOrWhiteSpace(e.PlaySessionId)) if (!string.IsNullOrWhiteSpace(e.PlaySessionId))
{ {
@ -123,7 +117,7 @@ namespace MediaBrowser.Api
} }
} }
void _sessionManager_PlaybackProgress(object sender, PlaybackProgressEventArgs e) private void OnPlaybackProgress(object sender, PlaybackProgressEventArgs e)
{ {
if (!string.IsNullOrWhiteSpace(e.PlaySessionId)) if (!string.IsNullOrWhiteSpace(e.PlaySessionId))
{ {
@ -140,17 +134,9 @@ namespace MediaBrowser.Api
{ {
DeleteEncodedMediaCache(); DeleteEncodedMediaCache();
} }
catch (FileNotFoundException)
{
// Don't clutter the log
}
catch (IOException)
{
// Don't clutter the log
}
catch (Exception ex) catch (Exception ex)
{ {
Logger.LogError(ex, "Error deleting encoded media cache"); _logger.LogError(ex, "Error deleting encoded media cache");
} }
return Task.CompletedTask; return Task.CompletedTask;
@ -161,8 +147,7 @@ namespace MediaBrowser.Api
/// </summary> /// </summary>
private void DeleteEncodedMediaCache() private void DeleteEncodedMediaCache()
{ {
var path = ConfigurationManager.GetTranscodePath(); var path = _serverConfigurationManager.GetTranscodePath();
if (!Directory.Exists(path)) if (!Directory.Exists(path))
{ {
return; return;
@ -174,9 +159,7 @@ namespace MediaBrowser.Api
} }
} }
/// <summary> /// <inheritdoc />
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose() public void Dispose()
{ {
Dispose(true); Dispose(true);
@ -219,8 +202,8 @@ namespace MediaBrowser.Api
_activeTranscodingJobs.Clear(); _activeTranscodingJobs.Clear();
_transcodingLocks.Clear(); _transcodingLocks.Clear();
_sessionManager.PlaybackProgress -= _sessionManager_PlaybackProgress; _sessionManager.PlaybackProgress -= OnPlaybackProgress;
_sessionManager.PlaybackStart -= _sessionManager_PlaybackStart; _sessionManager.PlaybackStart -= OnPlaybackStart;
_disposed = true; _disposed = true;
} }
@ -252,7 +235,7 @@ namespace MediaBrowser.Api
{ {
lock (_activeTranscodingJobs) lock (_activeTranscodingJobs)
{ {
var job = new TranscodingJob(Logger) var job = new TranscodingJob(_logger)
{ {
Type = type, Type = type,
Path = path, Path = path,
@ -406,12 +389,13 @@ namespace MediaBrowser.Api
public void OnTranscodeEndRequest(TranscodingJob job) public void OnTranscodeEndRequest(TranscodingJob job)
{ {
job.ActiveRequestCount--; job.ActiveRequestCount--;
Logger.LogDebug("OnTranscodeEndRequest job.ActiveRequestCount={0}", job.ActiveRequestCount); _logger.LogDebug("OnTranscodeEndRequest job.ActiveRequestCount={0}", job.ActiveRequestCount);
if (job.ActiveRequestCount <= 0) if (job.ActiveRequestCount <= 0)
{ {
PingTimer(job, false); PingTimer(job, false);
} }
} }
internal void PingTranscodingJob(string playSessionId, bool? isUserPaused) internal void PingTranscodingJob(string playSessionId, bool? isUserPaused)
{ {
if (string.IsNullOrEmpty(playSessionId)) if (string.IsNullOrEmpty(playSessionId))
@ -419,7 +403,7 @@ namespace MediaBrowser.Api
throw new ArgumentNullException(nameof(playSessionId)); throw new ArgumentNullException(nameof(playSessionId));
} }
Logger.LogDebug("PingTranscodingJob PlaySessionId={0} isUsedPaused: {1}", playSessionId, isUserPaused); _logger.LogDebug("PingTranscodingJob PlaySessionId={0} isUsedPaused: {1}", playSessionId, isUserPaused);
List<TranscodingJob> jobs; List<TranscodingJob> jobs;
@ -434,9 +418,10 @@ namespace MediaBrowser.Api
{ {
if (isUserPaused.HasValue) if (isUserPaused.HasValue)
{ {
Logger.LogDebug("Setting job.IsUserPaused to {0}. jobId: {1}", isUserPaused, job.Id); _logger.LogDebug("Setting job.IsUserPaused to {0}. jobId: {1}", isUserPaused, job.Id);
job.IsUserPaused = isUserPaused.Value; job.IsUserPaused = isUserPaused.Value;
} }
PingTimer(job, true); PingTimer(job, true);
} }
} }
@ -489,7 +474,7 @@ namespace MediaBrowser.Api
} }
} }
Logger.LogInformation("Transcoding kill timer stopped for JobId {0} PlaySessionId {1}. Killing transcoding", job.Id, job.PlaySessionId); _logger.LogInformation("Transcoding kill timer stopped for JobId {0} PlaySessionId {1}. Killing transcoding", job.Id, job.PlaySessionId);
await KillTranscodingJob(job, true, path => true); await KillTranscodingJob(job, true, path => true);
} }
@ -558,7 +543,7 @@ namespace MediaBrowser.Api
{ {
job.DisposeKillTimer(); job.DisposeKillTimer();
Logger.LogDebug("KillTranscodingJob - JobId {0} PlaySessionId {1}. Killing transcoding", job.Id, job.PlaySessionId); _logger.LogDebug("KillTranscodingJob - JobId {0} PlaySessionId {1}. Killing transcoding", job.Id, job.PlaySessionId);
lock (_activeTranscodingJobs) lock (_activeTranscodingJobs)
{ {
@ -590,14 +575,14 @@ namespace MediaBrowser.Api
{ {
try try
{ {
Logger.LogInformation("Stopping ffmpeg process with q command for {Path}", job.Path); _logger.LogInformation("Stopping ffmpeg process with q command for {Path}", job.Path);
process.StandardInput.WriteLine("q"); process.StandardInput.WriteLine("q");
// Need to wait because killing is asynchronous // Need to wait because killing is asynchronous
if (!process.WaitForExit(5000)) if (!process.WaitForExit(5000))
{ {
Logger.LogInformation("Killing ffmpeg process for {Path}", job.Path); _logger.LogInformation("Killing ffmpeg process for {Path}", job.Path);
process.Kill(); process.Kill();
} }
} }
@ -620,7 +605,7 @@ namespace MediaBrowser.Api
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.LogError(ex, "Error closing live stream for {Path}", job.Path); _logger.LogError(ex, "Error closing live stream for {Path}", job.Path);
} }
} }
} }
@ -632,7 +617,7 @@ namespace MediaBrowser.Api
return; return;
} }
Logger.LogInformation("Deleting partial stream file(s) {Path}", path); _logger.LogInformation("Deleting partial stream file(s) {Path}", path);
await Task.Delay(delayMs).ConfigureAwait(false); await Task.Delay(delayMs).ConfigureAwait(false);
@ -646,20 +631,16 @@ namespace MediaBrowser.Api
{ {
DeleteHlsPartialStreamFiles(path); DeleteHlsPartialStreamFiles(path);
} }
}
catch (FileNotFoundException)
{
} }
catch (IOException ex) catch (IOException ex)
{ {
Logger.LogError(ex, "Error deleting partial stream file(s) {Path}", path); _logger.LogError(ex, "Error deleting partial stream file(s) {Path}", path);
await DeletePartialStreamFiles(path, jobType, retryCount + 1, 500).ConfigureAwait(false); await DeletePartialStreamFiles(path, jobType, retryCount + 1, 500).ConfigureAwait(false);
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.LogError(ex, "Error deleting partial stream file(s) {Path}", path); _logger.LogError(ex, "Error deleting partial stream file(s) {Path}", path);
} }
} }
@ -669,7 +650,10 @@ namespace MediaBrowser.Api
/// <param name="outputFilePath">The output file path.</param> /// <param name="outputFilePath">The output file path.</param>
private void DeleteProgressivePartialStreamFiles(string outputFilePath) private void DeleteProgressivePartialStreamFiles(string outputFilePath)
{ {
_fileSystem.DeleteFile(outputFilePath); if (File.Exists(outputFilePath))
{
_fileSystem.DeleteFile(outputFilePath);
}
} }
/// <summary> /// <summary>
@ -684,178 +668,24 @@ namespace MediaBrowser.Api
var filesToDelete = _fileSystem.GetFilePaths(directory) var filesToDelete = _fileSystem.GetFilePaths(directory)
.Where(f => f.IndexOf(name, StringComparison.OrdinalIgnoreCase) != -1); .Where(f => f.IndexOf(name, StringComparison.OrdinalIgnoreCase) != -1);
Exception e = null; List<Exception> exs = null;
foreach (var file in filesToDelete) foreach (var file in filesToDelete)
{ {
try try
{ {
Logger.LogDebug("Deleting HLS file {0}", file); _logger.LogDebug("Deleting HLS file {0}", file);
_fileSystem.DeleteFile(file); _fileSystem.DeleteFile(file);
}
catch (FileNotFoundException)
{
} }
catch (IOException ex) catch (IOException ex)
{ {
e = ex; (exs ??= new List<Exception>(4)).Add(ex);
Logger.LogError(ex, "Error deleting HLS file {Path}", file); _logger.LogError(ex, "Error deleting HLS file {Path}", file);
} }
} }
if (e != null) if (exs != null)
{ {
throw e; throw new AggregateException("Error deleting HLS files", exs);
}
}
}
/// <summary>
/// Class TranscodingJob
/// </summary>
public class TranscodingJob
{
/// <summary>
/// Gets or sets the play session identifier.
/// </summary>
/// <value>The play session identifier.</value>
public string PlaySessionId { get; set; }
/// <summary>
/// Gets or sets the live stream identifier.
/// </summary>
/// <value>The live stream identifier.</value>
public string LiveStreamId { get; set; }
public bool IsLiveOutput { get; set; }
/// <summary>
/// Gets or sets the path.
/// </summary>
/// <value>The path.</value>
public MediaSourceInfo MediaSource { get; set; }
public string Path { get; set; }
/// <summary>
/// Gets or sets the type.
/// </summary>
/// <value>The type.</value>
public TranscodingJobType Type { get; set; }
/// <summary>
/// Gets or sets the process.
/// </summary>
/// <value>The process.</value>
public Process Process { get; set; }
public ILogger Logger { get; private set; }
/// <summary>
/// Gets or sets the active request count.
/// </summary>
/// <value>The active request count.</value>
public int ActiveRequestCount { get; set; }
/// <summary>
/// Gets or sets the kill timer.
/// </summary>
/// <value>The kill timer.</value>
private Timer KillTimer { get; set; }
public string DeviceId { get; set; }
public CancellationTokenSource CancellationTokenSource { get; set; }
public object ProcessLock = new object();
public bool HasExited { get; set; }
public bool IsUserPaused { get; set; }
public string Id { get; set; }
public float? Framerate { get; set; }
public double? CompletionPercentage { get; set; }
public long? BytesDownloaded { get; set; }
public long? BytesTranscoded { get; set; }
public int? BitRate { get; set; }
public long? TranscodingPositionTicks { get; set; }
public long? DownloadPositionTicks { get; set; }
public TranscodingThrottler TranscodingThrottler { get; set; }
private readonly object _timerLock = new object();
public DateTime LastPingDate { get; set; }
public int PingTimeout { get; set; }
public TranscodingJob(ILogger logger)
{
Logger = logger;
}
public void StopKillTimer()
{
lock (_timerLock)
{
if (KillTimer != null)
{
KillTimer.Change(Timeout.Infinite, Timeout.Infinite);
}
}
}
public void DisposeKillTimer()
{
lock (_timerLock)
{
if (KillTimer != null)
{
KillTimer.Dispose();
KillTimer = null;
}
}
}
public void StartKillTimer(Action<object> callback)
{
StartKillTimer(callback, PingTimeout);
}
public void StartKillTimer(Action<object> callback, int intervalMs)
{
if (HasExited)
{
return;
}
lock (_timerLock)
{
if (KillTimer == null)
{
Logger.LogDebug("Starting kill timer at {0}ms. JobId {1} PlaySessionId {2}", intervalMs, Id, PlaySessionId);
KillTimer = new Timer(new TimerCallback(callback), this, intervalMs, Timeout.Infinite);
}
else
{
Logger.LogDebug("Changing kill timer to {0}ms. JobId {1} PlaySessionId {2}", intervalMs, Id, PlaySessionId);
KillTimer.Change(intervalMs, Timeout.Infinite);
}
}
}
public void ChangeKillTimerIfStarted()
{
if (HasExited)
{
return;
}
lock (_timerLock)
{
if (KillTimer != null)
{
var intervalMs = PingTimeout;
Logger.LogDebug("Changing kill timer to {0}ms. JobId {1} PlaySessionId {2}", intervalMs, Id, PlaySessionId);
KillTimer.Change(intervalMs, Timeout.Infinite);
}
} }
} }
} }

View file

@ -1,5 +1,7 @@
using System; using System;
using System.IO;
using System.Linq; using System.Linq;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Audio;
@ -16,19 +18,35 @@ namespace MediaBrowser.Api
/// <summary> /// <summary>
/// Class BaseApiService /// Class BaseApiService
/// </summary> /// </summary>
public class BaseApiService : IService, IRequiresRequest public abstract class BaseApiService : IService, IRequiresRequest
{ {
/// <summary> public BaseApiService(
/// Gets or sets the logger. ILogger logger,
/// </summary> IServerConfigurationManager serverConfigurationManager,
/// <value>The logger.</value> IHttpResultFactory httpResultFactory)
public ILogger Logger => ApiEntryPoint.Instance.Logger; {
Logger = logger;
ServerConfigurationManager = serverConfigurationManager;
ResultFactory = httpResultFactory;
}
/// <summary> /// <summary>
/// Gets or sets the HTTP result factory. /// Gets the logger.
/// </summary>
/// <value>The logger.</value>
protected ILogger Logger { get; }
/// <summary>
/// Gets or sets the server configuration manager.
/// </summary>
/// <value>The server configuration manager.</value>
protected IServerConfigurationManager ServerConfigurationManager { get; }
/// <summary>
/// Gets the HTTP result factory.
/// </summary> /// </summary>
/// <value>The HTTP result factory.</value> /// <value>The HTTP result factory.</value>
public IHttpResultFactory ResultFactory => ApiEntryPoint.Instance.ResultFactory; protected IHttpResultFactory ResultFactory { get; }
/// <summary> /// <summary>
/// Gets or sets the request context. /// Gets or sets the request context.
@ -36,10 +54,7 @@ namespace MediaBrowser.Api
/// <value>The request context.</value> /// <value>The request context.</value>
public IRequest Request { get; set; } public IRequest Request { get; set; }
public string GetHeader(string name) public string GetHeader(string name) => Request.Headers[name];
{
return Request.Headers[name];
}
public static string[] SplitValue(string value, char delim) public static string[] SplitValue(string value, char delim)
{ {
@ -292,51 +307,97 @@ namespace MediaBrowser.Api
return result; return result;
} }
protected string GetPathValue(int index) /// <summary>
/// Gets the path segment at the specified index.
/// </summary>
/// <param name="index">The index of the path segment.</param>
/// <returns>The path segment at the specified index.</returns>
/// <exception cref="IndexOutOfRangeException" >Path doesn't contain enough segments.</exception>
/// <exception cref="InvalidDataException" >Path doesn't start with the base url.</exception>
protected internal ReadOnlySpan<char> GetPathValue(int index)
{ {
var pathInfo = Parse(Request.PathInfo); static void ThrowIndexOutOfRangeException()
var first = pathInfo[0]; => throw new IndexOutOfRangeException("Path doesn't contain enough segments.");
string baseUrl = ApiEntryPoint.Instance.ConfigurationManager.Configuration.BaseUrl; static void ThrowInvalidDataException()
=> throw new InvalidDataException("Path doesn't start with the base url.");
// backwards compatibility ReadOnlySpan<char> path = Request.PathInfo;
if (baseUrl.Length == 0)
// Remove the protocol part from the url
int pos = path.LastIndexOf("://");
if (pos != -1)
{ {
if (string.Equals(first, "mediabrowser", StringComparison.OrdinalIgnoreCase) path = path.Slice(pos + 3);
|| string.Equals(first, "emby", StringComparison.OrdinalIgnoreCase))
{
index++;
}
} }
else if (string.Equals(first, baseUrl.Remove(0, 1)))
// Remove the query string
pos = path.LastIndexOf('?');
if (pos != -1)
{ {
index++; path = path.Slice(0, pos);
var second = pathInfo[1]; }
if (string.Equals(second, "mediabrowser", StringComparison.OrdinalIgnoreCase)
|| string.Equals(second, "emby", StringComparison.OrdinalIgnoreCase)) // Remove the domain
pos = path.IndexOf('/');
if (pos != -1)
{
path = path.Slice(pos);
}
// Remove base url
string baseUrl = ServerConfigurationManager.Configuration.BaseUrl;
int baseUrlLen = baseUrl.Length;
if (baseUrlLen != 0)
{
if (path.StartsWith(baseUrl, StringComparison.OrdinalIgnoreCase))
{ {
index++; path = path.Slice(baseUrlLen);
}
else
{
// The path doesn't start with the base url,
// how did we get here?
ThrowInvalidDataException();
} }
} }
return pathInfo[index]; // Remove leading /
} path = path.Slice(1);
private static string[] Parse(string pathUri) // Backwards compatibility
{ const string Emby = "emby/";
var actionParts = pathUri.Split(new[] { "://" }, StringSplitOptions.None); if (path.StartsWith(Emby, StringComparison.OrdinalIgnoreCase))
var pathInfo = actionParts[actionParts.Length - 1];
var optionsPos = pathInfo.LastIndexOf('?');
if (optionsPos != -1)
{ {
pathInfo = pathInfo.Substring(0, optionsPos); path = path.Slice(Emby.Length);
} }
var args = pathInfo.Split('/'); const string MediaBrowser = "mediabrowser/";
if (path.StartsWith(MediaBrowser, StringComparison.OrdinalIgnoreCase))
{
path = path.Slice(MediaBrowser.Length);
}
return args.Skip(1).ToArray(); // Skip segments until we are at the right index
for (int i = 0; i < index; i++)
{
pos = path.IndexOf('/');
if (pos == -1)
{
ThrowIndexOutOfRangeException();
}
path = path.Slice(pos + 1);
}
// Remove the rest
pos = path.IndexOf('/');
if (pos != -1)
{
path = path.Slice(0, pos);
}
return path;
} }
/// <summary> /// <summary>

View file

@ -1,6 +1,9 @@
using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Branding; using MediaBrowser.Model.Branding;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api namespace MediaBrowser.Api
{ {
@ -17,21 +20,22 @@ namespace MediaBrowser.Api
public class BrandingService : BaseApiService public class BrandingService : BaseApiService
{ {
private readonly IConfigurationManager _config; public BrandingService(
ILogger<BrandingService> logger,
public BrandingService(IConfigurationManager config) IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_config = config;
} }
public object Get(GetBrandingOptions request) public object Get(GetBrandingOptions request)
{ {
return _config.GetConfiguration<BrandingOptions>("branding"); return ServerConfigurationManager.GetConfiguration<BrandingOptions>("branding");
} }
public object Get(GetBrandingCss request) public object Get(GetBrandingCss request)
{ {
var result = _config.GetConfiguration<BrandingOptions>("branding"); var result = ServerConfigurationManager.GetConfiguration<BrandingOptions>("branding");
// When null this throws a 405 error under Mono OSX, so default to empty string // When null this throws a 405 error under Mono OSX, so default to empty string
return ResultFactory.GetResult(Request, result.CustomCss ?? string.Empty, "text/css"); return ResultFactory.GetResult(Request, result.CustomCss ?? string.Empty, "text/css");

View file

@ -4,6 +4,7 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Api.UserLibrary; using MediaBrowser.Api.UserLibrary;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
@ -13,6 +14,7 @@ using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api namespace MediaBrowser.Api
{ {
@ -188,7 +190,13 @@ namespace MediaBrowser.Api
private readonly IChannelManager _channelManager; private readonly IChannelManager _channelManager;
private IUserManager _userManager; private IUserManager _userManager;
public ChannelService(IChannelManager channelManager, IUserManager userManager) public ChannelService(
ILogger<ChannelService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IChannelManager channelManager,
IUserManager userManager)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_channelManager = channelManager; _channelManager = channelManager;
_userManager = userManager; _userManager = userManager;

View file

@ -1,14 +1,12 @@
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api namespace MediaBrowser.Api
{ {
@ -78,18 +76,19 @@ namespace MediaBrowser.Api
/// </summary> /// </summary>
private readonly IServerConfigurationManager _configurationManager; private readonly IServerConfigurationManager _configurationManager;
private readonly IFileSystem _fileSystem;
private readonly IProviderManager _providerManager;
private readonly ILibraryManager _libraryManager;
private readonly IMediaEncoder _mediaEncoder; private readonly IMediaEncoder _mediaEncoder;
public ConfigurationService(IJsonSerializer jsonSerializer, IServerConfigurationManager configurationManager, IFileSystem fileSystem, IProviderManager providerManager, ILibraryManager libraryManager, IMediaEncoder mediaEncoder) public ConfigurationService(
ILogger<ConfigurationService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IJsonSerializer jsonSerializer,
IServerConfigurationManager configurationManager,
IMediaEncoder mediaEncoder)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_jsonSerializer = jsonSerializer; _jsonSerializer = jsonSerializer;
_configurationManager = configurationManager; _configurationManager = configurationManager;
_fileSystem = fileSystem;
_providerManager = providerManager;
_libraryManager = libraryManager;
_mediaEncoder = mediaEncoder; _mediaEncoder = mediaEncoder;
} }
@ -131,7 +130,7 @@ namespace MediaBrowser.Api
public async Task Post(UpdateNamedConfiguration request) public async Task Post(UpdateNamedConfiguration request)
{ {
var key = GetPathValue(2); var key = GetPathValue(2).ToString();
var configurationType = _configurationManager.GetConfigurationType(key); var configurationType = _configurationManager.GetConfigurationType(key);
var configuration = await _jsonSerializer.DeserializeFromStreamAsync(request.RequestStream, configurationType).ConfigureAwait(false); var configuration = await _jsonSerializer.DeserializeFromStreamAsync(request.RequestStream, configurationType).ConfigureAwait(false);

View file

@ -1,6 +1,6 @@
using System;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Devices; using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Security; using MediaBrowser.Controller.Security;
@ -8,6 +8,7 @@ using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Devices; using MediaBrowser.Model.Devices;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.Devices namespace MediaBrowser.Api.Devices
{ {
@ -81,7 +82,14 @@ namespace MediaBrowser.Api.Devices
private readonly IAuthenticationRepository _authRepo; private readonly IAuthenticationRepository _authRepo;
private readonly ISessionManager _sessionManager; private readonly ISessionManager _sessionManager;
public DeviceService(IDeviceManager deviceManager, IAuthenticationRepository authRepo, ISessionManager sessionManager) public DeviceService(
ILogger<DeviceService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IDeviceManager deviceManager,
IAuthenticationRepository authRepo,
ISessionManager sessionManager)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_deviceManager = deviceManager; _deviceManager = deviceManager;
_authRepo = authRepo; _authRepo = authRepo;

View file

@ -1,9 +1,11 @@
using System.Threading; using System.Threading;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api namespace MediaBrowser.Api
{ {
@ -61,7 +63,13 @@ namespace MediaBrowser.Api
/// </summary> /// </summary>
/// <param name="jsonSerializer">The json serializer.</param> /// <param name="jsonSerializer">The json serializer.</param>
/// <param name="displayPreferencesManager">The display preferences manager.</param> /// <param name="displayPreferencesManager">The display preferences manager.</param>
public DisplayPreferencesService(IJsonSerializer jsonSerializer, IDisplayPreferencesRepository displayPreferencesManager) public DisplayPreferencesService(
ILogger<DisplayPreferencesService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IJsonSerializer jsonSerializer,
IDisplayPreferencesRepository displayPreferencesManager)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_jsonSerializer = jsonSerializer; _jsonSerializer = jsonSerializer;
_displayPreferencesManager = displayPreferencesManager; _displayPreferencesManager = displayPreferencesManager;

View file

@ -3,10 +3,12 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Net; using MediaBrowser.Model.Net;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api namespace MediaBrowser.Api
{ {
@ -108,8 +110,8 @@ namespace MediaBrowser.Api
[Authenticated(Roles = "Admin", AllowBeforeStartupWizard = true)] [Authenticated(Roles = "Admin", AllowBeforeStartupWizard = true)]
public class EnvironmentService : BaseApiService public class EnvironmentService : BaseApiService
{ {
const char UncSeparator = '\\'; private const char UncSeparator = '\\';
const string UncSeparatorString = "\\"; private const string UncSeparatorString = "\\";
/// <summary> /// <summary>
/// The _network manager /// The _network manager
@ -121,13 +123,14 @@ namespace MediaBrowser.Api
/// Initializes a new instance of the <see cref="EnvironmentService" /> class. /// Initializes a new instance of the <see cref="EnvironmentService" /> class.
/// </summary> /// </summary>
/// <param name="networkManager">The network manager.</param> /// <param name="networkManager">The network manager.</param>
public EnvironmentService(INetworkManager networkManager, IFileSystem fileSystem) public EnvironmentService(
ILogger<EnvironmentService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
INetworkManager networkManager,
IFileSystem fileSystem)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
if (networkManager == null)
{
throw new ArgumentNullException(nameof(networkManager));
}
_networkManager = networkManager; _networkManager = networkManager;
_fileSystem = fileSystem; _fileSystem = fileSystem;
} }

View file

@ -1,12 +1,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api namespace MediaBrowser.Api
{ {
@ -84,7 +86,13 @@ namespace MediaBrowser.Api
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
public FilterService(ILibraryManager libraryManager, IUserManager userManager) public FilterService(
ILogger<FilterService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
ILibraryManager libraryManager,
IUserManager userManager)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_libraryManager = libraryManager; _libraryManager = libraryManager;
_userManager = userManager; _userManager = userManager;

View file

@ -5,11 +5,13 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller; using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.Images namespace MediaBrowser.Api.Images
{ {
@ -101,17 +103,19 @@ namespace MediaBrowser.Api.Images
private readonly IServerApplicationPaths _appPaths; private readonly IServerApplicationPaths _appPaths;
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
private readonly IHttpResultFactory _resultFactory;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageByNameService" /> class. /// Initializes a new instance of the <see cref="ImageByNameService" /> class.
/// </summary> /// </summary>
/// <param name="appPaths">The app paths.</param> public ImageByNameService(
public ImageByNameService(IServerApplicationPaths appPaths, IFileSystem fileSystem, IHttpResultFactory resultFactory) ILogger<ImageByNameService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory resultFactory,
IFileSystem fileSystem)
: base(logger, serverConfigurationManager, resultFactory)
{ {
_appPaths = appPaths; _appPaths = serverConfigurationManager.ApplicationPaths;
_fileSystem = fileSystem; _fileSystem = fileSystem;
_resultFactory = resultFactory;
} }
public object Get(GetMediaInfoImages request) public object Get(GetMediaInfoImages request)
@ -187,7 +191,7 @@ namespace MediaBrowser.Api.Images
var path = paths.FirstOrDefault(File.Exists) ?? paths.FirstOrDefault(); var path = paths.FirstOrDefault(File.Exists) ?? paths.FirstOrDefault();
return _resultFactory.GetStaticFileResult(Request, path); return ResultFactory.GetStaticFileResult(Request, path);
} }
/// <summary> /// <summary>
@ -207,7 +211,7 @@ namespace MediaBrowser.Api.Images
if (!string.IsNullOrEmpty(path)) if (!string.IsNullOrEmpty(path))
{ {
return _resultFactory.GetStaticFileResult(Request, path); return ResultFactory.GetStaticFileResult(Request, path);
} }
} }
@ -224,7 +228,7 @@ namespace MediaBrowser.Api.Images
if (!string.IsNullOrEmpty(path)) if (!string.IsNullOrEmpty(path))
{ {
return _resultFactory.GetStaticFileResult(Request, path); return ResultFactory.GetStaticFileResult(Request, path);
} }
} }
@ -247,7 +251,7 @@ namespace MediaBrowser.Api.Images
if (!string.IsNullOrEmpty(path)) if (!string.IsNullOrEmpty(path))
{ {
return _resultFactory.GetStaticFileResult(Request, path); return ResultFactory.GetStaticFileResult(Request, path);
} }
} }
@ -263,7 +267,7 @@ namespace MediaBrowser.Api.Images
if (!string.IsNullOrEmpty(path)) if (!string.IsNullOrEmpty(path))
{ {
return _resultFactory.GetStaticFileResult(Request, path); return ResultFactory.GetStaticFileResult(Request, path);
} }
} }

View file

@ -6,12 +6,12 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Drawing; using MediaBrowser.Model.Drawing;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
@ -231,7 +231,6 @@ namespace MediaBrowser.Api.Images
private readonly IProviderManager _providerManager; private readonly IProviderManager _providerManager;
private readonly IItemRepository _itemRepo;
private readonly IImageProcessor _imageProcessor; private readonly IImageProcessor _imageProcessor;
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
private readonly IAuthorizationContext _authContext; private readonly IAuthorizationContext _authContext;
@ -239,12 +238,21 @@ namespace MediaBrowser.Api.Images
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageService" /> class. /// Initializes a new instance of the <see cref="ImageService" /> class.
/// </summary> /// </summary>
public ImageService(IUserManager userManager, ILibraryManager libraryManager, IProviderManager providerManager, IItemRepository itemRepo, IImageProcessor imageProcessor, IFileSystem fileSystem, IAuthorizationContext authContext) public ImageService(
Logger<ImageService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager,
ILibraryManager libraryManager,
IProviderManager providerManager,
IImageProcessor imageProcessor,
IFileSystem fileSystem,
IAuthorizationContext authContext)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_userManager = userManager; _userManager = userManager;
_libraryManager = libraryManager; _libraryManager = libraryManager;
_providerManager = providerManager; _providerManager = providerManager;
_itemRepo = itemRepo;
_imageProcessor = imageProcessor; _imageProcessor = imageProcessor;
_fileSystem = fileSystem; _fileSystem = fileSystem;
_authContext = authContext; _authContext = authContext;
@ -402,7 +410,7 @@ namespace MediaBrowser.Api.Images
public object Get(GetItemByNameImage request) public object Get(GetItemByNameImage request)
{ {
var type = GetPathValue(0); var type = GetPathValue(0).ToString();
var item = GetItemByName(request.Name, type, _libraryManager, new DtoOptions(false)); var item = GetItemByName(request.Name, type, _libraryManager, new DtoOptions(false));
@ -411,7 +419,7 @@ namespace MediaBrowser.Api.Images
public object Head(GetItemByNameImage request) public object Head(GetItemByNameImage request)
{ {
var type = GetPathValue(0); var type = GetPathValue(0).ToString();
var item = GetItemByName(request.Name, type, _libraryManager, new DtoOptions(false)); var item = GetItemByName(request.Name, type, _libraryManager, new DtoOptions(false));
@ -424,12 +432,13 @@ namespace MediaBrowser.Api.Images
/// <param name="request">The request.</param> /// <param name="request">The request.</param>
public Task Post(PostUserImage request) public Task Post(PostUserImage request)
{ {
var userId = GetPathValue(1); var id = Guid.Parse(GetPathValue(1));
AssertCanUpdateUser(_authContext, _userManager, new Guid(userId), true);
request.Type = (ImageType)Enum.Parse(typeof(ImageType), GetPathValue(3), true); AssertCanUpdateUser(_authContext, _userManager, id, true);
var item = _userManager.GetUserById(userId); request.Type = Enum.Parse<ImageType>(GetPathValue(3).ToString(), true);
var item = _userManager.GetUserById(id);
return PostImage(item, request.RequestStream, request.Type, Request.ContentType); return PostImage(item, request.RequestStream, request.Type, Request.ContentType);
} }
@ -440,9 +449,9 @@ namespace MediaBrowser.Api.Images
/// <param name="request">The request.</param> /// <param name="request">The request.</param>
public Task Post(PostItemImage request) public Task Post(PostItemImage request)
{ {
var id = GetPathValue(1); var id = Guid.Parse(GetPathValue(1));
request.Type = (ImageType)Enum.Parse(typeof(ImageType), GetPathValue(3), true); request.Type = Enum.Parse<ImageType>(GetPathValue(3).ToString(), true);
var item = _libraryManager.GetItemById(id); var item = _libraryManager.GetItemById(id);

View file

@ -7,7 +7,7 @@ using System.Threading.Tasks;
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Controller; using MediaBrowser.Controller;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
@ -16,6 +16,7 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Providers; using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.Images namespace MediaBrowser.Api.Images
{ {
@ -108,13 +109,20 @@ namespace MediaBrowser.Api.Images
private readonly IHttpClient _httpClient; private readonly IHttpClient _httpClient;
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
private readonly IDtoService _dtoService;
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
public RemoteImageService(IProviderManager providerManager, IDtoService dtoService, IServerApplicationPaths appPaths, IHttpClient httpClient, IFileSystem fileSystem, ILibraryManager libraryManager) public RemoteImageService(
ILogger<RemoteImageService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IProviderManager providerManager,
IServerApplicationPaths appPaths,
IHttpClient httpClient,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_providerManager = providerManager; _providerManager = providerManager;
_dtoService = dtoService;
_appPaths = appPaths; _appPaths = appPaths;
_httpClient = httpClient; _httpClient = httpClient;
_fileSystem = fileSystem; _fileSystem = fileSystem;

View file

@ -6,6 +6,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller; using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.Movies;
@ -121,10 +122,18 @@ namespace MediaBrowser.Api
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly IJsonSerializer _json; private readonly IJsonSerializer _json;
public ItemLookupService(IProviderManager providerManager, IServerApplicationPaths appPaths, IFileSystem fileSystem, ILibraryManager libraryManager, IJsonSerializer json) public ItemLookupService(
ILogger<ItemLookupService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager,
IJsonSerializer json)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_providerManager = providerManager; _providerManager = providerManager;
_appPaths = appPaths; _appPaths = serverConfigurationManager.ApplicationPaths;
_fileSystem = fileSystem; _fileSystem = fileSystem;
_libraryManager = libraryManager; _libraryManager = libraryManager;
_json = json; _json = json;

View file

@ -1,3 +1,4 @@
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
@ -38,14 +39,19 @@ namespace MediaBrowser.Api
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly IProviderManager _providerManager; private readonly IProviderManager _providerManager;
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
private readonly ILogger _logger;
public ItemRefreshService(ILibraryManager libraryManager, IProviderManager providerManager, IFileSystem fileSystem, ILogger logger) public ItemRefreshService(
ILogger<ItemRefreshService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
ILibraryManager libraryManager,
IProviderManager providerManager,
IFileSystem fileSystem)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_libraryManager = libraryManager; _libraryManager = libraryManager;
_providerManager = providerManager; _providerManager = providerManager;
_fileSystem = fileSystem; _fileSystem = fileSystem;
_logger = logger;
} }
/// <summary> /// <summary>

View file

@ -16,6 +16,7 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization; using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api namespace MediaBrowser.Api
{ {
@ -49,19 +50,25 @@ namespace MediaBrowser.Api
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly IProviderManager _providerManager; private readonly IProviderManager _providerManager;
private readonly ILocalizationManager _localizationManager; private readonly ILocalizationManager _localizationManager;
private readonly IServerConfigurationManager _config;
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
public ItemUpdateService(IFileSystem fileSystem, ILibraryManager libraryManager, IProviderManager providerManager, ILocalizationManager localizationManager, IServerConfigurationManager config) public ItemUpdateService(
ILogger<ItemUpdateService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IFileSystem fileSystem,
ILibraryManager libraryManager,
IProviderManager providerManager,
ILocalizationManager localizationManager)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_libraryManager = libraryManager; _libraryManager = libraryManager;
_providerManager = providerManager; _providerManager = providerManager;
_localizationManager = localizationManager; _localizationManager = localizationManager;
_config = config;
_fileSystem = fileSystem; _fileSystem = fileSystem;
} }
public async Task<object> Get(GetMetadataEditorInfo request) public object Get(GetMetadataEditorInfo request)
{ {
var item = _libraryManager.GetItemById(request.ItemId); var item = _libraryManager.GetItemById(request.ItemId);
@ -101,7 +108,7 @@ namespace MediaBrowser.Api
var item = _libraryManager.GetItemById(request.ItemId); var item = _libraryManager.GetItemById(request.ItemId);
var path = item.ContainingFolderPath; var path = item.ContainingFolderPath;
var types = _config.Configuration.ContentTypes var types = ServerConfigurationManager.Configuration.ContentTypes
.Where(i => !string.IsNullOrWhiteSpace(i.Name)) .Where(i => !string.IsNullOrWhiteSpace(i.Name))
.Where(i => !string.Equals(i.Name, path, StringComparison.OrdinalIgnoreCase)) .Where(i => !string.Equals(i.Name, path, StringComparison.OrdinalIgnoreCase))
.ToList(); .ToList();
@ -115,8 +122,8 @@ namespace MediaBrowser.Api
}); });
} }
_config.Configuration.ContentTypes = types.ToArray(); ServerConfigurationManager.Configuration.ContentTypes = types.ToArray();
_config.SaveConfiguration(); ServerConfigurationManager.SaveConfiguration();
} }
private List<NameValuePair> GetContentTypeOptions(bool isForItem) private List<NameValuePair> GetContentTypeOptions(bool isForItem)

View file

@ -25,7 +25,6 @@ using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Globalization; using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
@ -315,46 +314,40 @@ namespace MediaBrowser.Api.Library
/// </summary> /// </summary>
public class LibraryService : BaseApiService public class LibraryService : BaseApiService
{ {
/// <summary> private readonly IProviderManager _providerManager;
/// The _item repo
/// </summary>
private readonly IItemRepository _itemRepo;
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
private readonly IUserDataManager _userDataManager;
private readonly IDtoService _dtoService; private readonly IDtoService _dtoService;
private readonly IAuthorizationContext _authContext; private readonly IAuthorizationContext _authContext;
private readonly IActivityManager _activityManager; private readonly IActivityManager _activityManager;
private readonly ILocalizationManager _localization; private readonly ILocalizationManager _localization;
private readonly ILiveTvManager _liveTv;
private readonly ITVSeriesManager _tvManager;
private readonly ILibraryMonitor _libraryMonitor; private readonly ILibraryMonitor _libraryMonitor;
private readonly IFileSystem _fileSystem;
private readonly IServerConfigurationManager _config;
private readonly IProviderManager _providerManager;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="LibraryService" /> class. /// Initializes a new instance of the <see cref="LibraryService" /> class.
/// </summary> /// </summary>
public LibraryService(IProviderManager providerManager, IItemRepository itemRepo, ILibraryManager libraryManager, IUserManager userManager, public LibraryService(
IDtoService dtoService, IUserDataManager userDataManager, IAuthorizationContext authContext, IActivityManager activityManager, ILocalizationManager localization, ILiveTvManager liveTv, ITVSeriesManager tvManager, ILibraryMonitor libraryMonitor, IFileSystem fileSystem, IServerConfigurationManager config) ILogger<LibraryService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IProviderManager providerManager,
ILibraryManager libraryManager,
IUserManager userManager,
IDtoService dtoService,
IAuthorizationContext authContext,
IActivityManager activityManager,
ILocalizationManager localization,
ILibraryMonitor libraryMonitor)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_itemRepo = itemRepo; _providerManager = providerManager;
_libraryManager = libraryManager; _libraryManager = libraryManager;
_userManager = userManager; _userManager = userManager;
_dtoService = dtoService; _dtoService = dtoService;
_userDataManager = userDataManager;
_authContext = authContext; _authContext = authContext;
_activityManager = activityManager; _activityManager = activityManager;
_localization = localization; _localization = localization;
_liveTv = liveTv;
_tvManager = tvManager;
_libraryMonitor = libraryMonitor; _libraryMonitor = libraryMonitor;
_fileSystem = fileSystem;
_config = config;
_providerManager = providerManager;
} }
private string[] GetRepresentativeItemTypes(string contentType) private string[] GetRepresentativeItemTypes(string contentType)
@ -390,7 +383,7 @@ namespace MediaBrowser.Api.Library
return false; return false;
} }
var metadataOptions = _config.Configuration.MetadataOptions var metadataOptions = ServerConfigurationManager.Configuration.MetadataOptions
.Where(i => itemTypes.Contains(i.ItemType ?? string.Empty, StringComparer.OrdinalIgnoreCase)) .Where(i => itemTypes.Contains(i.ItemType ?? string.Empty, StringComparer.OrdinalIgnoreCase))
.ToArray(); .ToArray();
@ -446,7 +439,7 @@ namespace MediaBrowser.Api.Library
return false; return false;
} }
var metadataOptions = _config.Configuration.MetadataOptions var metadataOptions = ServerConfigurationManager.Configuration.MetadataOptions
.Where(i => string.Equals(i.ItemType, type, StringComparison.OrdinalIgnoreCase)) .Where(i => string.Equals(i.ItemType, type, StringComparison.OrdinalIgnoreCase))
.ToArray(); .ToArray();
@ -510,7 +503,7 @@ namespace MediaBrowser.Api.Library
return false; return false;
} }
var metadataOptions = _config.Configuration.MetadataOptions var metadataOptions = ServerConfigurationManager.Configuration.MetadataOptions
.Where(i => string.Equals(i.ItemType, type, StringComparison.OrdinalIgnoreCase)) .Where(i => string.Equals(i.ItemType, type, StringComparison.OrdinalIgnoreCase))
.ToArray(); .ToArray();
@ -630,7 +623,14 @@ namespace MediaBrowser.Api.Library
if (item is Movie || (program != null && program.IsMovie) || item is Trailer) if (item is Movie || (program != null && program.IsMovie) || item is Trailer)
{ {
return new MoviesService(_userManager, _libraryManager, _dtoService, _config, _authContext) return new MoviesService(
Logger,
ServerConfigurationManager,
ResultFactory,
_userManager,
_libraryManager,
_dtoService,
_authContext)
{ {
Request = Request, Request = Request,

View file

@ -7,13 +7,14 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Common.Progress; using MediaBrowser.Common.Progress;
using MediaBrowser.Controller; using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.Library namespace MediaBrowser.Api.Library
{ {
@ -179,25 +180,23 @@ namespace MediaBrowser.Api.Library
/// The _library manager /// The _library manager
/// </summary> /// </summary>
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly ILibraryMonitor _libraryMonitor; private readonly ILibraryMonitor _libraryMonitor;
private readonly IFileSystem _fileSystem;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="LibraryStructureService" /> class. /// Initializes a new instance of the <see cref="LibraryStructureService" /> class.
/// </summary> /// </summary>
public LibraryStructureService(IServerApplicationPaths appPaths, ILibraryManager libraryManager, ILibraryMonitor libraryMonitor, IFileSystem fileSystem) public LibraryStructureService(
ILogger<LibraryStructureService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
ILibraryManager libraryManager,
ILibraryMonitor libraryMonitor)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
if (appPaths == null) _appPaths = serverConfigurationManager.ApplicationPaths;
{
throw new ArgumentNullException(nameof(appPaths));
}
_appPaths = appPaths;
_libraryManager = libraryManager; _libraryManager = libraryManager;
_libraryMonitor = libraryMonitor; _libraryMonitor = libraryMonitor;
_fileSystem = fileSystem;
} }
/// <summary> /// <summary>

View file

@ -18,13 +18,13 @@ using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace MediaBrowser.Api.LiveTv namespace MediaBrowser.Api.LiveTv
@ -692,35 +692,33 @@ namespace MediaBrowser.Api.LiveTv
{ {
private readonly ILiveTvManager _liveTvManager; private readonly ILiveTvManager _liveTvManager;
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
private readonly IServerConfigurationManager _config;
private readonly IHttpClient _httpClient; private readonly IHttpClient _httpClient;
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly IDtoService _dtoService; private readonly IDtoService _dtoService;
private readonly IAuthorizationContext _authContext; private readonly IAuthorizationContext _authContext;
private readonly ISessionContext _sessionContext; private readonly ISessionContext _sessionContext;
private readonly ICryptoProvider _cryptographyProvider;
private readonly IStreamHelper _streamHelper; private readonly IStreamHelper _streamHelper;
private readonly IMediaSourceManager _mediaSourceManager; private readonly IMediaSourceManager _mediaSourceManager;
public LiveTvService( public LiveTvService(
ICryptoProvider crypto, ILogger<LiveTvService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IMediaSourceManager mediaSourceManager, IMediaSourceManager mediaSourceManager,
IStreamHelper streamHelper, IStreamHelper streamHelper,
ILiveTvManager liveTvManager, ILiveTvManager liveTvManager,
IUserManager userManager, IUserManager userManager,
IServerConfigurationManager config,
IHttpClient httpClient, IHttpClient httpClient,
ILibraryManager libraryManager, ILibraryManager libraryManager,
IDtoService dtoService, IDtoService dtoService,
IAuthorizationContext authContext, IAuthorizationContext authContext,
ISessionContext sessionContext) ISessionContext sessionContext)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_cryptographyProvider = crypto;
_mediaSourceManager = mediaSourceManager; _mediaSourceManager = mediaSourceManager;
_streamHelper = streamHelper; _streamHelper = streamHelper;
_liveTvManager = liveTvManager; _liveTvManager = liveTvManager;
_userManager = userManager; _userManager = userManager;
_config = config;
_httpClient = httpClient; _httpClient = httpClient;
_libraryManager = libraryManager; _libraryManager = libraryManager;
_dtoService = dtoService; _dtoService = dtoService;
@ -911,17 +909,17 @@ namespace MediaBrowser.Api.LiveTv
config.TunerHosts = config.TunerHosts.Where(i => !string.Equals(request.Id, i.Id, StringComparison.OrdinalIgnoreCase)).ToArray(); config.TunerHosts = config.TunerHosts.Where(i => !string.Equals(request.Id, i.Id, StringComparison.OrdinalIgnoreCase)).ToArray();
_config.SaveConfiguration("livetv", config); ServerConfigurationManager.SaveConfiguration("livetv", config);
} }
private LiveTvOptions GetConfiguration() private LiveTvOptions GetConfiguration()
{ {
return _config.GetConfiguration<LiveTvOptions>("livetv"); return ServerConfigurationManager.GetConfiguration<LiveTvOptions>("livetv");
} }
private void UpdateConfiguration(LiveTvOptions options) private void UpdateConfiguration(LiveTvOptions options)
{ {
_config.SaveConfiguration("livetv", options); ServerConfigurationManager.SaveConfiguration("livetv", options);
} }
public async Task<object> Get(GetLineups request) public async Task<object> Get(GetLineups request)

View file

@ -1,7 +1,9 @@
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization; using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api namespace MediaBrowser.Api
{ {
@ -52,7 +54,12 @@ namespace MediaBrowser.Api
/// Initializes a new instance of the <see cref="LocalizationService"/> class. /// Initializes a new instance of the <see cref="LocalizationService"/> class.
/// </summary> /// </summary>
/// <param name="localization">The localization.</param> /// <param name="localization">The localization.</param>
public LocalizationService(ILocalizationManager localization) public LocalizationService(
ILogger<LocalizationService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
ILocalizationManager localization)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_localization = localization; _localization = localization;
} }

View file

@ -1,9 +1,11 @@
using System; using System;
using MediaBrowser.Controller.Collections; using MediaBrowser.Controller.Collections;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Collections; using MediaBrowser.Model.Collections;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.Movies namespace MediaBrowser.Api.Movies
{ {
@ -50,7 +52,14 @@ namespace MediaBrowser.Api.Movies
private readonly IDtoService _dtoService; private readonly IDtoService _dtoService;
private readonly IAuthorizationContext _authContext; private readonly IAuthorizationContext _authContext;
public CollectionService(ICollectionManager collectionManager, IDtoService dtoService, IAuthorizationContext authContext) public CollectionService(
ILogger<CollectionService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
ICollectionManager collectionManager,
IDtoService dtoService,
IAuthorizationContext authContext)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_collectionManager = collectionManager; _collectionManager = collectionManager;
_dtoService = dtoService; _dtoService = dtoService;

View file

@ -14,6 +14,7 @@ using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.Movies namespace MediaBrowser.Api.Movies
{ {
@ -75,18 +76,24 @@ namespace MediaBrowser.Api.Movies
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly IDtoService _dtoService; private readonly IDtoService _dtoService;
private readonly IServerConfigurationManager _config;
private readonly IAuthorizationContext _authContext; private readonly IAuthorizationContext _authContext;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="MoviesService" /> class. /// Initializes a new instance of the <see cref="MoviesService" /> class.
/// </summary> /// </summary>
public MoviesService(IUserManager userManager, ILibraryManager libraryManager, IDtoService dtoService, IServerConfigurationManager config, IAuthorizationContext authContext) public MoviesService(
ILogger logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager,
ILibraryManager libraryManager,
IDtoService dtoService,
IAuthorizationContext authContext)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_userManager = userManager; _userManager = userManager;
_libraryManager = libraryManager; _libraryManager = libraryManager;
_dtoService = dtoService; _dtoService = dtoService;
_config = config;
_authContext = authContext; _authContext = authContext;
} }
@ -110,7 +117,7 @@ namespace MediaBrowser.Api.Movies
_libraryManager.RootFolder) : _libraryManager.GetItemById(request.Id); _libraryManager.RootFolder) : _libraryManager.GetItemById(request.Id);
var itemTypes = new List<string> { typeof(Movie).Name }; var itemTypes = new List<string> { typeof(Movie).Name };
if (_config.Configuration.EnableExternalContentInSuggestions) if (ServerConfigurationManager.Configuration.EnableExternalContentInSuggestions)
{ {
itemTypes.Add(typeof(Trailer).Name); itemTypes.Add(typeof(Trailer).Name);
itemTypes.Add(typeof(LiveTvProgram).Name); itemTypes.Add(typeof(LiveTvProgram).Name);
@ -167,7 +174,7 @@ namespace MediaBrowser.Api.Movies
var recentlyPlayedMovies = _libraryManager.GetItemList(query); var recentlyPlayedMovies = _libraryManager.GetItemList(query);
var itemTypes = new List<string> { typeof(Movie).Name }; var itemTypes = new List<string> { typeof(Movie).Name };
if (_config.Configuration.EnableExternalContentInSuggestions) if (ServerConfigurationManager.Configuration.EnableExternalContentInSuggestions)
{ {
itemTypes.Add(typeof(Trailer).Name); itemTypes.Add(typeof(Trailer).Name);
itemTypes.Add(typeof(LiveTvProgram).Name); itemTypes.Add(typeof(LiveTvProgram).Name);
@ -249,7 +256,7 @@ namespace MediaBrowser.Api.Movies
private IEnumerable<RecommendationDto> GetWithDirector(User user, IEnumerable<string> names, int itemLimit, DtoOptions dtoOptions, RecommendationType type) private IEnumerable<RecommendationDto> GetWithDirector(User user, IEnumerable<string> names, int itemLimit, DtoOptions dtoOptions, RecommendationType type)
{ {
var itemTypes = new List<string> { typeof(Movie).Name }; var itemTypes = new List<string> { typeof(Movie).Name };
if (_config.Configuration.EnableExternalContentInSuggestions) if (ServerConfigurationManager.Configuration.EnableExternalContentInSuggestions)
{ {
itemTypes.Add(typeof(Trailer).Name); itemTypes.Add(typeof(Trailer).Name);
itemTypes.Add(typeof(LiveTvProgram).Name); itemTypes.Add(typeof(LiveTvProgram).Name);
@ -291,7 +298,7 @@ namespace MediaBrowser.Api.Movies
private IEnumerable<RecommendationDto> GetWithActor(User user, IEnumerable<string> names, int itemLimit, DtoOptions dtoOptions, RecommendationType type) private IEnumerable<RecommendationDto> GetWithActor(User user, IEnumerable<string> names, int itemLimit, DtoOptions dtoOptions, RecommendationType type)
{ {
var itemTypes = new List<string> { typeof(Movie).Name }; var itemTypes = new List<string> { typeof(Movie).Name };
if (_config.Configuration.EnableExternalContentInSuggestions) if (ServerConfigurationManager.Configuration.EnableExternalContentInSuggestions)
{ {
itemTypes.Add(typeof(Trailer).Name); itemTypes.Add(typeof(Trailer).Name);
itemTypes.Add(typeof(LiveTvProgram).Name); itemTypes.Add(typeof(LiveTvProgram).Name);
@ -332,7 +339,7 @@ namespace MediaBrowser.Api.Movies
private IEnumerable<RecommendationDto> GetSimilarTo(User user, List<BaseItem> baselineItems, int itemLimit, DtoOptions dtoOptions, RecommendationType type) private IEnumerable<RecommendationDto> GetSimilarTo(User user, List<BaseItem> baselineItems, int itemLimit, DtoOptions dtoOptions, RecommendationType type)
{ {
var itemTypes = new List<string> { typeof(Movie).Name }; var itemTypes = new List<string> { typeof(Movie).Name };
if (_config.Configuration.EnableExternalContentInSuggestions) if (ServerConfigurationManager.Configuration.EnableExternalContentInSuggestions)
{ {
itemTypes.Add(typeof(Trailer).Name); itemTypes.Add(typeof(Trailer).Name);
itemTypes.Add(typeof(LiveTvProgram).Name); itemTypes.Add(typeof(LiveTvProgram).Name);

View file

@ -1,5 +1,5 @@
using MediaBrowser.Api.UserLibrary; using MediaBrowser.Api.UserLibrary;
using MediaBrowser.Controller.Collections; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
@ -8,6 +8,7 @@ using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.Movies namespace MediaBrowser.Api.Movies
{ {
@ -27,28 +28,31 @@ namespace MediaBrowser.Api.Movies
/// </summary> /// </summary>
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
/// <summary>
/// The _user data repository
/// </summary>
private readonly IUserDataManager _userDataRepository;
/// <summary> /// <summary>
/// The _library manager /// The _library manager
/// </summary> /// </summary>
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly IDtoService _dtoService; private readonly IDtoService _dtoService;
private readonly ICollectionManager _collectionManager;
private readonly ILocalizationManager _localizationManager; private readonly ILocalizationManager _localizationManager;
private readonly IJsonSerializer _json; private readonly IJsonSerializer _json;
private readonly IAuthorizationContext _authContext; private readonly IAuthorizationContext _authContext;
public TrailersService(IUserManager userManager, IUserDataManager userDataRepository, ILibraryManager libraryManager, IDtoService dtoService, ICollectionManager collectionManager, ILocalizationManager localizationManager, IJsonSerializer json, IAuthorizationContext authContext) public TrailersService(
ILogger<TrailersService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager,
ILibraryManager libraryManager,
IDtoService dtoService,
ILocalizationManager localizationManager,
IJsonSerializer json,
IAuthorizationContext authContext)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_userManager = userManager; _userManager = userManager;
_userDataRepository = userDataRepository;
_libraryManager = libraryManager; _libraryManager = libraryManager;
_dtoService = dtoService; _dtoService = dtoService;
_collectionManager = collectionManager;
_localizationManager = localizationManager; _localizationManager = localizationManager;
_json = json; _json = json;
_authContext = authContext; _authContext = authContext;
@ -61,7 +65,15 @@ namespace MediaBrowser.Api.Movies
getItems.IncludeItemTypes = "Trailer"; getItems.IncludeItemTypes = "Trailer";
return new ItemsService(_userManager, _libraryManager, _localizationManager, _dtoService, _authContext) return new ItemsService(
Logger,
ServerConfigurationManager,
ResultFactory,
_userManager,
_libraryManager,
_localizationManager,
_dtoService,
_authContext)
{ {
Request = Request, Request = Request,

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Audio;
@ -8,6 +9,7 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.Music namespace MediaBrowser.Api.Music
{ {
@ -41,7 +43,17 @@ namespace MediaBrowser.Api.Music
private readonly IDtoService _dtoService; private readonly IDtoService _dtoService;
private readonly IAuthorizationContext _authContext; private readonly IAuthorizationContext _authContext;
public AlbumsService(IUserManager userManager, IUserDataManager userDataRepository, ILibraryManager libraryManager, IItemRepository itemRepo, IDtoService dtoService, IAuthorizationContext authContext) public AlbumsService(
Logger<AlbumsService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager,
IUserDataManager userDataRepository,
ILibraryManager libraryManager,
IItemRepository itemRepo,
IDtoService dtoService,
IAuthorizationContext authContext)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_userManager = userManager; _userManager = userManager;
_userDataRepository = userDataRepository; _userDataRepository = userDataRepository;

View file

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
@ -8,6 +9,7 @@ using MediaBrowser.Controller.Playlists;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.Music namespace MediaBrowser.Api.Music
{ {
@ -62,7 +64,16 @@ namespace MediaBrowser.Api.Music
private readonly IMusicManager _musicManager; private readonly IMusicManager _musicManager;
private readonly IAuthorizationContext _authContext; private readonly IAuthorizationContext _authContext;
public InstantMixService(IUserManager userManager, IDtoService dtoService, IMusicManager musicManager, ILibraryManager libraryManager, IAuthorizationContext authContext) public InstantMixService(
ILogger<InstantMixService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager,
IDtoService dtoService,
IMusicManager musicManager,
ILibraryManager libraryManager,
IAuthorizationContext authContext)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_userManager = userManager; _userManager = userManager;
_dtoService = dtoService; _dtoService = dtoService;

View file

@ -2,14 +2,14 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Common;
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Updates; using MediaBrowser.Common.Updates;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using MediaBrowser.Model.Updates; using MediaBrowser.Model.Updates;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api namespace MediaBrowser.Api
{ {
@ -118,12 +118,15 @@ namespace MediaBrowser.Api
public class PackageService : BaseApiService public class PackageService : BaseApiService
{ {
private readonly IInstallationManager _installationManager; private readonly IInstallationManager _installationManager;
private readonly IApplicationHost _appHost;
public PackageService(IInstallationManager installationManager, IApplicationHost appHost) public PackageService(
ILogger<PackageService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IInstallationManager installationManager)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_installationManager = installationManager; _installationManager = installationManager;
_appHost = appHost;
} }
/// <summary> /// <summary>

View file

@ -33,12 +33,6 @@ namespace MediaBrowser.Api.Playback
{ {
protected virtual bool EnableOutputInSubFolder => false; protected virtual bool EnableOutputInSubFolder => false;
/// <summary>
/// Gets or sets the application paths.
/// </summary>
/// <value>The application paths.</value>
protected IServerConfigurationManager ServerConfigurationManager { get; private set; }
/// <summary> /// <summary>
/// Gets or sets the user manager. /// Gets or sets the user manager.
/// </summary> /// </summary>
@ -89,7 +83,9 @@ namespace MediaBrowser.Api.Playback
/// Initializes a new instance of the <see cref="BaseStreamingService" /> class. /// Initializes a new instance of the <see cref="BaseStreamingService" /> class.
/// </summary> /// </summary>
protected BaseStreamingService( protected BaseStreamingService(
IServerConfigurationManager serverConfig, ILogger logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager, IUserManager userManager,
ILibraryManager libraryManager, ILibraryManager libraryManager,
IIsoManager isoManager, IIsoManager isoManager,
@ -101,8 +97,8 @@ namespace MediaBrowser.Api.Playback
IMediaSourceManager mediaSourceManager, IMediaSourceManager mediaSourceManager,
IJsonSerializer jsonSerializer, IJsonSerializer jsonSerializer,
IAuthorizationContext authorizationContext) IAuthorizationContext authorizationContext)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
ServerConfigurationManager = serverConfig;
UserManager = userManager; UserManager = userManager;
LibraryManager = libraryManager; LibraryManager = libraryManager;
IsoManager = isoManager; IsoManager = isoManager;
@ -588,7 +584,7 @@ namespace MediaBrowser.Api.Playback
} }
/// <summary> /// <summary>
/// Parses query parameters as StreamOptions /// Parses query parameters as StreamOptions.
/// </summary> /// </summary>
/// <param name="request">The stream request.</param> /// <param name="request">The stream request.</param>
private void ParseStreamOptions(StreamRequest request) private void ParseStreamOptions(StreamRequest request)

View file

@ -12,7 +12,6 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Net; using MediaBrowser.Model.Net;
using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Serialization;
@ -25,6 +24,39 @@ namespace MediaBrowser.Api.Playback.Hls
/// </summary> /// </summary>
public abstract class BaseHlsService : BaseStreamingService public abstract class BaseHlsService : BaseStreamingService
{ {
public BaseHlsService(
ILogger logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager,
ILibraryManager libraryManager,
IIsoManager isoManager,
IMediaEncoder mediaEncoder,
IFileSystem fileSystem,
IDlnaManager dlnaManager,
ISubtitleEncoder subtitleEncoder,
IDeviceManager deviceManager,
IMediaSourceManager mediaSourceManager,
IJsonSerializer jsonSerializer,
IAuthorizationContext authorizationContext)
: base(
logger,
serverConfigurationManager,
httpResultFactory,
userManager,
libraryManager,
isoManager,
mediaEncoder,
fileSystem,
dlnaManager,
subtitleEncoder,
deviceManager,
mediaSourceManager,
jsonSerializer,
authorizationContext)
{
}
/// <summary> /// <summary>
/// Gets the audio arguments. /// Gets the audio arguments.
/// </summary> /// </summary>
@ -313,33 +345,5 @@ namespace MediaBrowser.Api.Playback.Hls
{ {
return 0; return 0;
} }
public BaseHlsService(
IServerConfigurationManager serverConfig,
IUserManager userManager,
ILibraryManager libraryManager,
IIsoManager isoManager,
IMediaEncoder mediaEncoder,
IFileSystem fileSystem,
IDlnaManager dlnaManager,
ISubtitleEncoder subtitleEncoder,
IDeviceManager deviceManager,
IMediaSourceManager mediaSourceManager,
IJsonSerializer jsonSerializer,
IAuthorizationContext authorizationContext)
: base(serverConfig,
userManager,
libraryManager,
isoManager,
mediaEncoder,
fileSystem,
dlnaManager,
subtitleEncoder,
deviceManager,
mediaSourceManager,
jsonSerializer,
authorizationContext)
{
}
} }
} }

View file

@ -94,9 +94,10 @@ namespace MediaBrowser.Api.Playback.Hls
[Authenticated] [Authenticated]
public class DynamicHlsService : BaseHlsService public class DynamicHlsService : BaseHlsService
{ {
public DynamicHlsService( public DynamicHlsService(
IServerConfigurationManager serverConfig, ILogger logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager, IUserManager userManager,
ILibraryManager libraryManager, ILibraryManager libraryManager,
IIsoManager isoManager, IIsoManager isoManager,
@ -109,7 +110,10 @@ namespace MediaBrowser.Api.Playback.Hls
IJsonSerializer jsonSerializer, IJsonSerializer jsonSerializer,
IAuthorizationContext authorizationContext, IAuthorizationContext authorizationContext,
INetworkManager networkManager) INetworkManager networkManager)
: base(serverConfig, : base(
logger,
serverConfigurationManager,
httpResultFactory,
userManager, userManager,
libraryManager, libraryManager,
isoManager, isoManager,

View file

@ -8,6 +8,7 @@ using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.Playback.Hls namespace MediaBrowser.Api.Playback.Hls
{ {
@ -83,19 +84,22 @@ namespace MediaBrowser.Api.Playback.Hls
public class HlsSegmentService : BaseApiService public class HlsSegmentService : BaseApiService
{ {
private readonly IServerConfigurationManager _config;
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
public HlsSegmentService(IServerConfigurationManager config, IFileSystem fileSystem) public HlsSegmentService(
ILogger<HlsSegmentService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IFileSystem fileSystem)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_config = config;
_fileSystem = fileSystem; _fileSystem = fileSystem;
} }
public Task<object> Get(GetHlsPlaylistLegacy request) public Task<object> Get(GetHlsPlaylistLegacy request)
{ {
var file = request.PlaylistId + Path.GetExtension(Request.PathInfo); var file = request.PlaylistId + Path.GetExtension(Request.PathInfo);
file = Path.Combine(_config.GetTranscodePath(), file); file = Path.Combine(ServerConfigurationManager.GetTranscodePath(), file);
return GetFileResult(file, file); return GetFileResult(file, file);
} }
@ -113,7 +117,8 @@ namespace MediaBrowser.Api.Playback.Hls
public Task<object> Get(GetHlsVideoSegmentLegacy request) public Task<object> Get(GetHlsVideoSegmentLegacy request)
{ {
var file = request.SegmentId + Path.GetExtension(Request.PathInfo); var file = request.SegmentId + Path.GetExtension(Request.PathInfo);
var transcodeFolderPath = _config.GetTranscodePath(); var transcodeFolderPath = ServerConfigurationManager.GetTranscodePath();
file = Path.Combine(transcodeFolderPath, file); file = Path.Combine(transcodeFolderPath, file);
var normalizedPlaylistId = request.PlaylistId; var normalizedPlaylistId = request.PlaylistId;
@ -133,7 +138,7 @@ namespace MediaBrowser.Api.Playback.Hls
{ {
// TODO: Deprecate with new iOS app // TODO: Deprecate with new iOS app
var file = request.SegmentId + Path.GetExtension(Request.PathInfo); var file = request.SegmentId + Path.GetExtension(Request.PathInfo);
file = Path.Combine(_config.GetTranscodePath(), file); file = Path.Combine(ServerConfigurationManager.GetTranscodePath(), file);
return ResultFactory.GetStaticFileResult(Request, file, FileShareMode.ReadWrite); return ResultFactory.GetStaticFileResult(Request, file, FileShareMode.ReadWrite);
} }

View file

@ -12,6 +12,7 @@ using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.Playback.Hls namespace MediaBrowser.Api.Playback.Hls
{ {
@ -137,7 +138,9 @@ namespace MediaBrowser.Api.Playback.Hls
} }
public VideoHlsService( public VideoHlsService(
IServerConfigurationManager serverConfig, ILogger<VideoHlsService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager, IUserManager userManager,
ILibraryManager libraryManager, ILibraryManager libraryManager,
IIsoManager isoManager, IIsoManager isoManager,
@ -149,7 +152,10 @@ namespace MediaBrowser.Api.Playback.Hls
IMediaSourceManager mediaSourceManager, IMediaSourceManager mediaSourceManager,
IJsonSerializer jsonSerializer, IJsonSerializer jsonSerializer,
IAuthorizationContext authorizationContext) IAuthorizationContext authorizationContext)
: base(serverConfig, : base(
logger,
serverConfigurationManager,
httpResultFactory,
userManager, userManager,
libraryManager, libraryManager,
isoManager, isoManager,

View file

@ -69,36 +69,34 @@ namespace MediaBrowser.Api.Playback
private readonly IMediaSourceManager _mediaSourceManager; private readonly IMediaSourceManager _mediaSourceManager;
private readonly IDeviceManager _deviceManager; private readonly IDeviceManager _deviceManager;
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly IServerConfigurationManager _config;
private readonly INetworkManager _networkManager; private readonly INetworkManager _networkManager;
private readonly IMediaEncoder _mediaEncoder; private readonly IMediaEncoder _mediaEncoder;
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
private readonly IJsonSerializer _json; private readonly IJsonSerializer _json;
private readonly IAuthorizationContext _authContext; private readonly IAuthorizationContext _authContext;
private readonly ILogger _logger;
public MediaInfoService( public MediaInfoService(
ILogger logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IMediaSourceManager mediaSourceManager, IMediaSourceManager mediaSourceManager,
IDeviceManager deviceManager, IDeviceManager deviceManager,
ILibraryManager libraryManager, ILibraryManager libraryManager,
IServerConfigurationManager config,
INetworkManager networkManager, INetworkManager networkManager,
IMediaEncoder mediaEncoder, IMediaEncoder mediaEncoder,
IUserManager userManager, IUserManager userManager,
IJsonSerializer json, IJsonSerializer json,
IAuthorizationContext authContext, IAuthorizationContext authContext)
ILoggerFactory loggerFactory) : base(logger, serverConfigurationManager, httpResultFactory)
{ {
_mediaSourceManager = mediaSourceManager; _mediaSourceManager = mediaSourceManager;
_deviceManager = deviceManager; _deviceManager = deviceManager;
_libraryManager = libraryManager; _libraryManager = libraryManager;
_config = config;
_networkManager = networkManager; _networkManager = networkManager;
_mediaEncoder = mediaEncoder; _mediaEncoder = mediaEncoder;
_userManager = userManager; _userManager = userManager;
_json = json; _json = json;
_authContext = authContext; _authContext = authContext;
_logger = loggerFactory.CreateLogger(nameof(MediaInfoService));
} }
public object Get(GetBitrateTestBytes request) public object Get(GetBitrateTestBytes request)
@ -275,7 +273,7 @@ namespace MediaBrowser.Api.Playback
catch (Exception ex) catch (Exception ex)
{ {
mediaSources = new List<MediaSourceInfo>(); mediaSources = new List<MediaSourceInfo>();
_logger.LogError(ex, "Could not find media sources for item id {id}", id); Logger.LogError(ex, "Could not find media sources for item id {id}", id);
// TODO PlaybackException ?? // TODO PlaybackException ??
//result.ErrorCode = ex.ErrorCode; //result.ErrorCode = ex.ErrorCode;
} }
@ -533,7 +531,7 @@ namespace MediaBrowser.Api.Playback
if (remoteClientMaxBitrate <= 0) if (remoteClientMaxBitrate <= 0)
{ {
remoteClientMaxBitrate = _config.Configuration.RemoteClientBitrateLimit; remoteClientMaxBitrate = ServerConfigurationManager.Configuration.RemoteClientBitrateLimit;
} }
if (remoteClientMaxBitrate > 0) if (remoteClientMaxBitrate > 0)

View file

@ -10,6 +10,7 @@ using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.Playback.Progressive namespace MediaBrowser.Api.Playback.Progressive
{ {
@ -32,8 +33,10 @@ namespace MediaBrowser.Api.Playback.Progressive
public class AudioService : BaseProgressiveStreamingService public class AudioService : BaseProgressiveStreamingService
{ {
public AudioService( public AudioService(
ILogger logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IHttpClient httpClient, IHttpClient httpClient,
IServerConfigurationManager serverConfig,
IUserManager userManager, IUserManager userManager,
ILibraryManager libraryManager, ILibraryManager libraryManager,
IIsoManager isoManager, IIsoManager isoManager,
@ -45,19 +48,22 @@ namespace MediaBrowser.Api.Playback.Progressive
IMediaSourceManager mediaSourceManager, IMediaSourceManager mediaSourceManager,
IJsonSerializer jsonSerializer, IJsonSerializer jsonSerializer,
IAuthorizationContext authorizationContext) IAuthorizationContext authorizationContext)
: base(httpClient, : base(
serverConfig, logger,
userManager, serverConfigurationManager,
libraryManager, httpResultFactory,
isoManager, httpClient,
mediaEncoder, userManager,
fileSystem, libraryManager,
dlnaManager, isoManager,
subtitleEncoder, mediaEncoder,
deviceManager, fileSystem,
mediaSourceManager, dlnaManager,
jsonSerializer, subtitleEncoder,
authorizationContext) deviceManager,
mediaSourceManager,
jsonSerializer,
authorizationContext)
{ {
} }

View file

@ -15,6 +15,7 @@ using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo; using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace MediaBrowser.Api.Playback.Progressive namespace MediaBrowser.Api.Playback.Progressive
@ -27,8 +28,10 @@ namespace MediaBrowser.Api.Playback.Progressive
protected IHttpClient HttpClient { get; private set; } protected IHttpClient HttpClient { get; private set; }
public BaseProgressiveStreamingService( public BaseProgressiveStreamingService(
ILogger logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IHttpClient httpClient, IHttpClient httpClient,
IServerConfigurationManager serverConfig,
IUserManager userManager, IUserManager userManager,
ILibraryManager libraryManager, ILibraryManager libraryManager,
IIsoManager isoManager, IIsoManager isoManager,
@ -40,7 +43,10 @@ namespace MediaBrowser.Api.Playback.Progressive
IMediaSourceManager mediaSourceManager, IMediaSourceManager mediaSourceManager,
IJsonSerializer jsonSerializer, IJsonSerializer jsonSerializer,
IAuthorizationContext authorizationContext) IAuthorizationContext authorizationContext)
: base(serverConfig, : base(
logger,
serverConfigurationManager,
httpResultFactory,
userManager, userManager,
libraryManager, libraryManager,
isoManager, isoManager,

View file

@ -10,6 +10,7 @@ using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.Playback.Progressive namespace MediaBrowser.Api.Playback.Progressive
{ {
@ -69,8 +70,10 @@ namespace MediaBrowser.Api.Playback.Progressive
public class VideoService : BaseProgressiveStreamingService public class VideoService : BaseProgressiveStreamingService
{ {
public VideoService( public VideoService(
Logger<VideoService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IHttpClient httpClient, IHttpClient httpClient,
IServerConfigurationManager serverConfig,
IUserManager userManager, IUserManager userManager,
ILibraryManager libraryManager, ILibraryManager libraryManager,
IIsoManager isoManager, IIsoManager isoManager,
@ -82,8 +85,11 @@ namespace MediaBrowser.Api.Playback.Progressive
IMediaSourceManager mediaSourceManager, IMediaSourceManager mediaSourceManager,
IJsonSerializer jsonSerializer, IJsonSerializer jsonSerializer,
IAuthorizationContext authorizationContext) IAuthorizationContext authorizationContext)
: base(httpClient, : base(
serverConfig, logger,
serverConfigurationManager,
httpResultFactory,
httpClient,
userManager, userManager,
libraryManager, libraryManager,
isoManager, isoManager,

View file

@ -76,8 +76,10 @@ namespace MediaBrowser.Api.Playback
public class UniversalAudioService : BaseApiService public class UniversalAudioService : BaseApiService
{ {
public UniversalAudioService( public UniversalAudioService(
IHttpClient httpClient, ILogger<UniversalAudioService> logger,
IServerConfigurationManager serverConfigurationManager, IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IHttpClient httpClient,
IUserManager userManager, IUserManager userManager,
ILibraryManager libraryManager, ILibraryManager libraryManager,
IIsoManager isoManager, IIsoManager isoManager,
@ -87,15 +89,12 @@ namespace MediaBrowser.Api.Playback
IDeviceManager deviceManager, IDeviceManager deviceManager,
ISubtitleEncoder subtitleEncoder, ISubtitleEncoder subtitleEncoder,
IMediaSourceManager mediaSourceManager, IMediaSourceManager mediaSourceManager,
IZipClient zipClient,
IJsonSerializer jsonSerializer, IJsonSerializer jsonSerializer,
IAuthorizationContext authorizationContext, IAuthorizationContext authorizationContext,
IImageProcessor imageProcessor, INetworkManager networkManager)
INetworkManager networkManager, : base(logger, serverConfigurationManager, httpResultFactory)
ILoggerFactory loggerFactory)
{ {
HttpClient = httpClient; HttpClient = httpClient;
ServerConfigurationManager = serverConfigurationManager;
UserManager = userManager; UserManager = userManager;
LibraryManager = libraryManager; LibraryManager = libraryManager;
IsoManager = isoManager; IsoManager = isoManager;
@ -105,17 +104,12 @@ namespace MediaBrowser.Api.Playback
DeviceManager = deviceManager; DeviceManager = deviceManager;
SubtitleEncoder = subtitleEncoder; SubtitleEncoder = subtitleEncoder;
MediaSourceManager = mediaSourceManager; MediaSourceManager = mediaSourceManager;
ZipClient = zipClient;
JsonSerializer = jsonSerializer; JsonSerializer = jsonSerializer;
AuthorizationContext = authorizationContext; AuthorizationContext = authorizationContext;
ImageProcessor = imageProcessor;
NetworkManager = networkManager; NetworkManager = networkManager;
_loggerFactory = loggerFactory;
_logger = loggerFactory.CreateLogger(nameof(UniversalAudioService));
} }
protected IHttpClient HttpClient { get; private set; } protected IHttpClient HttpClient { get; private set; }
protected IServerConfigurationManager ServerConfigurationManager { get; private set; }
protected IUserManager UserManager { get; private set; } protected IUserManager UserManager { get; private set; }
protected ILibraryManager LibraryManager { get; private set; } protected ILibraryManager LibraryManager { get; private set; }
protected IIsoManager IsoManager { get; private set; } protected IIsoManager IsoManager { get; private set; }
@ -125,13 +119,9 @@ namespace MediaBrowser.Api.Playback
protected IDeviceManager DeviceManager { get; private set; } protected IDeviceManager DeviceManager { get; private set; }
protected ISubtitleEncoder SubtitleEncoder { get; private set; } protected ISubtitleEncoder SubtitleEncoder { get; private set; }
protected IMediaSourceManager MediaSourceManager { get; private set; } protected IMediaSourceManager MediaSourceManager { get; private set; }
protected IZipClient ZipClient { get; private set; }
protected IJsonSerializer JsonSerializer { get; private set; } protected IJsonSerializer JsonSerializer { get; private set; }
protected IAuthorizationContext AuthorizationContext { get; private set; } protected IAuthorizationContext AuthorizationContext { get; private set; }
protected IImageProcessor ImageProcessor { get; private set; }
protected INetworkManager NetworkManager { get; private set; } protected INetworkManager NetworkManager { get; private set; }
private ILoggerFactory _loggerFactory;
private ILogger _logger;
public Task<object> Get(GetUniversalAudioStream request) public Task<object> Get(GetUniversalAudioStream request)
{ {
@ -242,7 +232,18 @@ namespace MediaBrowser.Api.Playback
AuthorizationContext.GetAuthorizationInfo(Request).DeviceId = request.DeviceId; AuthorizationContext.GetAuthorizationInfo(Request).DeviceId = request.DeviceId;
var mediaInfoService = new MediaInfoService(MediaSourceManager, DeviceManager, LibraryManager, ServerConfigurationManager, NetworkManager, MediaEncoder, UserManager, JsonSerializer, AuthorizationContext, _loggerFactory) var mediaInfoService = new MediaInfoService(
Logger,
ServerConfigurationManager,
ResultFactory,
MediaSourceManager,
DeviceManager,
LibraryManager,
NetworkManager,
MediaEncoder,
UserManager,
JsonSerializer,
AuthorizationContext)
{ {
Request = Request Request = Request
}; };
@ -276,19 +277,22 @@ namespace MediaBrowser.Api.Playback
if (!isStatic && string.Equals(mediaSource.TranscodingSubProtocol, "hls", StringComparison.OrdinalIgnoreCase)) if (!isStatic && string.Equals(mediaSource.TranscodingSubProtocol, "hls", StringComparison.OrdinalIgnoreCase))
{ {
var service = new DynamicHlsService(ServerConfigurationManager, var service = new DynamicHlsService(
UserManager, Logger,
LibraryManager, ServerConfigurationManager,
IsoManager, ResultFactory,
MediaEncoder, UserManager,
FileSystem, LibraryManager,
DlnaManager, IsoManager,
SubtitleEncoder, MediaEncoder,
DeviceManager, FileSystem,
MediaSourceManager, DlnaManager,
JsonSerializer, SubtitleEncoder,
AuthorizationContext, DeviceManager,
NetworkManager) MediaSourceManager,
JsonSerializer,
AuthorizationContext,
NetworkManager)
{ {
Request = Request Request = Request
}; };
@ -322,8 +326,11 @@ namespace MediaBrowser.Api.Playback
} }
else else
{ {
var service = new AudioService(HttpClient, var service = new AudioService(
Logger,
ServerConfigurationManager, ServerConfigurationManager,
ResultFactory,
HttpClient,
UserManager, UserManager,
LibraryManager, LibraryManager,
IsoManager, IsoManager,
@ -360,6 +367,7 @@ namespace MediaBrowser.Api.Playback
{ {
return await service.Head(newRequest).ConfigureAwait(false); return await service.Head(newRequest).ConfigureAwait(false);
} }
return await service.Get(newRequest).ConfigureAwait(false); return await service.Get(newRequest).ConfigureAwait(false);
} }
} }

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
@ -9,6 +10,7 @@ using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Playlists; using MediaBrowser.Model.Playlists;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api namespace MediaBrowser.Api
{ {
@ -128,7 +130,16 @@ namespace MediaBrowser.Api
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly IAuthorizationContext _authContext; private readonly IAuthorizationContext _authContext;
public PlaylistService(IDtoService dtoService, IPlaylistManager playlistManager, IUserManager userManager, ILibraryManager libraryManager, IAuthorizationContext authContext) public PlaylistService(
ILogger<PlaylistService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IDtoService dtoService,
IPlaylistManager playlistManager,
IUserManager userManager,
ILibraryManager libraryManager,
IAuthorizationContext authContext)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_dtoService = dtoService; _dtoService = dtoService;
_playlistManager = playlistManager; _playlistManager = playlistManager;

View file

@ -3,14 +3,14 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Common; using MediaBrowser.Common;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.Updates; using MediaBrowser.Common.Updates;
using MediaBrowser.Controller.Devices; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Plugins; using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api namespace MediaBrowser.Api
{ {
@ -150,25 +150,18 @@ namespace MediaBrowser.Api
/// </summary> /// </summary>
private readonly IApplicationHost _appHost; private readonly IApplicationHost _appHost;
private readonly IInstallationManager _installationManager; private readonly IInstallationManager _installationManager;
private readonly INetworkManager _network;
private readonly IDeviceManager _deviceManager;
public PluginService(IJsonSerializer jsonSerializer, public PluginService(
ILogger<PluginService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IJsonSerializer jsonSerializer,
IApplicationHost appHost, IApplicationHost appHost,
IInstallationManager installationManager, IInstallationManager installationManager)
INetworkManager network, : base(logger, serverConfigurationManager, httpResultFactory)
IDeviceManager deviceManager)
: base()
{ {
if (jsonSerializer == null)
{
throw new ArgumentNullException(nameof(jsonSerializer));
}
_appHost = appHost; _appHost = appHost;
_installationManager = installationManager; _installationManager = installationManager;
_network = network;
_deviceManager = deviceManager;
_jsonSerializer = jsonSerializer; _jsonSerializer = jsonSerializer;
} }
@ -248,7 +241,7 @@ namespace MediaBrowser.Api
{ {
// We need to parse this manually because we told service stack not to with IRequiresRequestStream // We need to parse this manually because we told service stack not to with IRequiresRequestStream
// https://code.google.com/p/servicestack/source/browse/trunk/Common/ServiceStack.Text/ServiceStack.Text/Controller/PathInfo.cs // https://code.google.com/p/servicestack/source/browse/trunk/Common/ServiceStack.Text/ServiceStack.Text/Controller/PathInfo.cs
var id = new Guid(GetPathValue(1)); var id = Guid.Parse(GetPathValue(1));
var plugin = _appHost.Plugins.First(p => p.Id == id) as IHasPluginConfiguration; var plugin = _appHost.Plugins.First(p => p.Id == id) as IHasPluginConfiguration;

View file

@ -1,5 +1,6 @@
using System.Reflection; using System.Reflection;
using System.Resources; using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
@ -14,6 +15,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")] [assembly: NeutralResourcesLanguage("en")]
[assembly: InternalsVisibleTo("Jellyfin.Api.Tests")]
// Setting ComVisible to false makes the types in this assembly not visible // Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from // to COM components. If you need to access a type in this assembly from

View file

@ -6,6 +6,7 @@ using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using MediaBrowser.Model.Tasks; using MediaBrowser.Model.Tasks;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.ScheduledTasks namespace MediaBrowser.Api.ScheduledTasks
{ {
@ -85,27 +86,23 @@ namespace MediaBrowser.Api.ScheduledTasks
public class ScheduledTaskService : BaseApiService public class ScheduledTaskService : BaseApiService
{ {
/// <summary> /// <summary>
/// Gets or sets the task manager. /// The task manager.
/// </summary> /// </summary>
/// <value>The task manager.</value> private readonly ITaskManager _taskManager;
private ITaskManager TaskManager { get; set; }
private readonly IServerConfigurationManager _config;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ScheduledTaskService" /> class. /// Initializes a new instance of the <see cref="ScheduledTaskService" /> class.
/// </summary> /// </summary>
/// <param name="taskManager">The task manager.</param> /// <param name="taskManager">The task manager.</param>
/// <exception cref="ArgumentNullException">taskManager</exception> /// <exception cref="ArgumentNullException">taskManager</exception>
public ScheduledTaskService(ITaskManager taskManager, IServerConfigurationManager config) public ScheduledTaskService(
ILogger<ScheduledTaskService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
ITaskManager taskManager)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
if (taskManager == null) _taskManager = taskManager;
{
throw new ArgumentNullException(nameof(taskManager));
}
TaskManager = taskManager;
_config = config;
} }
/// <summary> /// <summary>
@ -115,7 +112,7 @@ namespace MediaBrowser.Api.ScheduledTasks
/// <returns>IEnumerable{TaskInfo}.</returns> /// <returns>IEnumerable{TaskInfo}.</returns>
public object Get(GetScheduledTasks request) public object Get(GetScheduledTasks request)
{ {
IEnumerable<IScheduledTaskWorker> result = TaskManager.ScheduledTasks IEnumerable<IScheduledTaskWorker> result = _taskManager.ScheduledTasks
.OrderBy(i => i.Name); .OrderBy(i => i.Name);
if (request.IsHidden.HasValue) if (request.IsHidden.HasValue)
@ -171,7 +168,7 @@ namespace MediaBrowser.Api.ScheduledTasks
/// <exception cref="ResourceNotFoundException">Task not found</exception> /// <exception cref="ResourceNotFoundException">Task not found</exception>
public object Get(GetScheduledTask request) public object Get(GetScheduledTask request)
{ {
var task = TaskManager.ScheduledTasks.FirstOrDefault(i => string.Equals(i.Id, request.Id)); var task = _taskManager.ScheduledTasks.FirstOrDefault(i => string.Equals(i.Id, request.Id));
if (task == null) if (task == null)
{ {
@ -190,14 +187,14 @@ namespace MediaBrowser.Api.ScheduledTasks
/// <exception cref="ResourceNotFoundException">Task not found</exception> /// <exception cref="ResourceNotFoundException">Task not found</exception>
public void Post(StartScheduledTask request) public void Post(StartScheduledTask request)
{ {
var task = TaskManager.ScheduledTasks.FirstOrDefault(i => string.Equals(i.Id, request.Id)); var task = _taskManager.ScheduledTasks.FirstOrDefault(i => string.Equals(i.Id, request.Id));
if (task == null) if (task == null)
{ {
throw new ResourceNotFoundException("Task not found"); throw new ResourceNotFoundException("Task not found");
} }
TaskManager.Execute(task, new TaskOptions()); _taskManager.Execute(task, new TaskOptions());
} }
/// <summary> /// <summary>
@ -207,14 +204,14 @@ namespace MediaBrowser.Api.ScheduledTasks
/// <exception cref="ResourceNotFoundException">Task not found</exception> /// <exception cref="ResourceNotFoundException">Task not found</exception>
public void Delete(StopScheduledTask request) public void Delete(StopScheduledTask request)
{ {
var task = TaskManager.ScheduledTasks.FirstOrDefault(i => string.Equals(i.Id, request.Id)); var task = _taskManager.ScheduledTasks.FirstOrDefault(i => string.Equals(i.Id, request.Id));
if (task == null) if (task == null)
{ {
throw new ResourceNotFoundException("Task not found"); throw new ResourceNotFoundException("Task not found");
} }
TaskManager.Cancel(task); _taskManager.Cancel(task);
} }
/// <summary> /// <summary>
@ -226,9 +223,9 @@ namespace MediaBrowser.Api.ScheduledTasks
{ {
// We need to parse this manually because we told service stack not to with IRequiresRequestStream // We need to parse this manually because we told service stack not to with IRequiresRequestStream
// https://code.google.com/p/servicestack/source/browse/trunk/Common/ServiceStack.Text/ServiceStack.Text/Controller/PathInfo.cs // https://code.google.com/p/servicestack/source/browse/trunk/Common/ServiceStack.Text/ServiceStack.Text/Controller/PathInfo.cs
var id = GetPathValue(1); var id = GetPathValue(1).ToString();
var task = TaskManager.ScheduledTasks.FirstOrDefault(i => string.Equals(i.Id, id, StringComparison.Ordinal)); var task = _taskManager.ScheduledTasks.FirstOrDefault(i => string.Equals(i.Id, id, StringComparison.Ordinal));
if (task == null) if (task == null)
{ {

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
@ -12,6 +13,7 @@ using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Search; using MediaBrowser.Model.Search;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api namespace MediaBrowser.Api
{ {
@ -122,7 +124,15 @@ namespace MediaBrowser.Api
/// <param name="libraryManager">The library manager.</param> /// <param name="libraryManager">The library manager.</param>
/// <param name="dtoService">The dto service.</param> /// <param name="dtoService">The dto service.</param>
/// <param name="imageProcessor">The image processor.</param> /// <param name="imageProcessor">The image processor.</param>
public SearchService(ISearchEngine searchEngine, ILibraryManager libraryManager, IDtoService dtoService, IImageProcessor imageProcessor) public SearchService(
ILogger<SearchService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
ISearchEngine searchEngine,
ILibraryManager libraryManager,
IDtoService dtoService,
IImageProcessor imageProcessor)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_searchEngine = searchEngine; _searchEngine = searchEngine;
_libraryManager = libraryManager; _libraryManager = libraryManager;

View file

@ -4,6 +4,7 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Controller; using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Devices; using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
@ -12,6 +13,7 @@ using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using MediaBrowser.Model.Session; using MediaBrowser.Model.Session;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.Session namespace MediaBrowser.Api.Session
{ {
@ -269,12 +271,12 @@ namespace MediaBrowser.Api.Session
} }
/// <summary> /// <summary>
/// Class SessionsService /// Class SessionsService.
/// </summary> /// </summary>
public class SessionsService : BaseApiService public class SessionsService : BaseApiService
{ {
/// <summary> /// <summary>
/// The _session manager /// The _session manager.
/// </summary> /// </summary>
private readonly ISessionManager _sessionManager; private readonly ISessionManager _sessionManager;
@ -283,9 +285,20 @@ namespace MediaBrowser.Api.Session
private readonly IAuthenticationRepository _authRepo; private readonly IAuthenticationRepository _authRepo;
private readonly IDeviceManager _deviceManager; private readonly IDeviceManager _deviceManager;
private readonly ISessionContext _sessionContext; private readonly ISessionContext _sessionContext;
private IServerApplicationHost _appHost; private readonly IServerApplicationHost _appHost;
public SessionsService(ISessionManager sessionManager, IServerApplicationHost appHost, IUserManager userManager, IAuthorizationContext authContext, IAuthenticationRepository authRepo, IDeviceManager deviceManager, ISessionContext sessionContext) public SessionsService(
ILogger<SessionsService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
ISessionManager sessionManager,
IServerApplicationHost appHost,
IUserManager userManager,
IAuthorizationContext authContext,
IAuthenticationRepository authRepo,
IDeviceManager deviceManager,
ISessionContext sessionContext)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_sessionManager = sessionManager; _sessionManager = sessionManager;
_userManager = userManager; _userManager = userManager;

View file

@ -6,6 +6,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Controller.MediaEncoding;
@ -130,7 +131,18 @@ namespace MediaBrowser.Api.Subtitles
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
private readonly IAuthorizationContext _authContext; private readonly IAuthorizationContext _authContext;
public SubtitleService(ILibraryManager libraryManager, ISubtitleManager subtitleManager, ISubtitleEncoder subtitleEncoder, IMediaSourceManager mediaSourceManager, IProviderManager providerManager, IFileSystem fileSystem, IAuthorizationContext authContext) public SubtitleService(
ILogger<SubtitleService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
ILibraryManager libraryManager,
ISubtitleManager subtitleManager,
ISubtitleEncoder subtitleEncoder,
IMediaSourceManager mediaSourceManager,
IProviderManager providerManager,
IFileSystem fileSystem,
IAuthorizationContext authContext)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_libraryManager = libraryManager; _libraryManager = libraryManager;
_subtitleManager = subtitleManager; _subtitleManager = subtitleManager;

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Linq; using System.Linq;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
@ -8,6 +9,7 @@ using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api namespace MediaBrowser.Api
{ {
@ -39,7 +41,15 @@ namespace MediaBrowser.Api
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
public SuggestionsService(IDtoService dtoService, IAuthorizationContext authContext, IUserManager userManager, ILibraryManager libraryManager) public SuggestionsService(
ILogger<SuggestionsService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IDtoService dtoService,
IAuthorizationContext authContext,
IUserManager userManager,
ILibraryManager libraryManager)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_dtoService = dtoService; _dtoService = dtoService;
_authContext = authContext; _authContext = authContext;

View file

@ -1,9 +1,11 @@
using System; using System;
using System.Globalization; using System.Globalization;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Activity; using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.System namespace MediaBrowser.Api.System
{ {
@ -35,7 +37,12 @@ namespace MediaBrowser.Api.System
{ {
private readonly IActivityManager _activityManager; private readonly IActivityManager _activityManager;
public ActivityLogService(IActivityManager activityManager) public ActivityLogService(
ILogger<ActivityLogService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IActivityManager activityManager)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_activityManager = activityManager; _activityManager = activityManager;
} }

View file

@ -7,6 +7,7 @@ using System.Threading.Tasks;
using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Controller; using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Net; using MediaBrowser.Model.Net;
@ -103,13 +104,19 @@ namespace MediaBrowser.Api.System
/// Initializes a new instance of the <see cref="SystemService" /> class. /// Initializes a new instance of the <see cref="SystemService" /> class.
/// </summary> /// </summary>
/// <param name="appHost">The app host.</param> /// <param name="appHost">The app host.</param>
/// <param name="appPaths">The application paths.</param>
/// <param name="fileSystem">The file system.</param> /// <param name="fileSystem">The file system.</param>
/// <exception cref="ArgumentNullException">jsonSerializer</exception> /// <exception cref="ArgumentNullException">jsonSerializer</exception>
public SystemService(IServerApplicationHost appHost, IApplicationPaths appPaths, IFileSystem fileSystem, INetworkManager network) public SystemService(
ILogger<SystemService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IServerApplicationHost appHost,
IFileSystem fileSystem,
INetworkManager network)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_appPaths = serverConfigurationManager.ApplicationPaths;
_appHost = appHost; _appHost = appHost;
_appPaths = appPaths;
_fileSystem = fileSystem; _fileSystem = fileSystem;
_network = network; _network = network;
} }

View file

@ -0,0 +1,160 @@
using System;
using System.Diagnostics;
using System.Threading;
using MediaBrowser.Api.Playback;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Model.Dto;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api
{
/// <summary>
/// Class TranscodingJob.
/// </summary>
public class TranscodingJob
{
/// <summary>
/// Gets or sets the play session identifier.
/// </summary>
/// <value>The play session identifier.</value>
public string PlaySessionId { get; set; }
/// <summary>
/// Gets or sets the live stream identifier.
/// </summary>
/// <value>The live stream identifier.</value>
public string LiveStreamId { get; set; }
public bool IsLiveOutput { get; set; }
/// <summary>
/// Gets or sets the path.
/// </summary>
/// <value>The path.</value>
public MediaSourceInfo MediaSource { get; set; }
public string Path { get; set; }
/// <summary>
/// Gets or sets the type.
/// </summary>
/// <value>The type.</value>
public TranscodingJobType Type { get; set; }
/// <summary>
/// Gets or sets the process.
/// </summary>
/// <value>The process.</value>
public Process Process { get; set; }
public ILogger Logger { get; private set; }
/// <summary>
/// Gets or sets the active request count.
/// </summary>
/// <value>The active request count.</value>
public int ActiveRequestCount { get; set; }
/// <summary>
/// Gets or sets the kill timer.
/// </summary>
/// <value>The kill timer.</value>
private Timer KillTimer { get; set; }
public string DeviceId { get; set; }
public CancellationTokenSource CancellationTokenSource { get; set; }
public object ProcessLock = new object();
public bool HasExited { get; set; }
public bool IsUserPaused { get; set; }
public string Id { get; set; }
public float? Framerate { get; set; }
public double? CompletionPercentage { get; set; }
public long? BytesDownloaded { get; set; }
public long? BytesTranscoded { get; set; }
public int? BitRate { get; set; }
public long? TranscodingPositionTicks { get; set; }
public long? DownloadPositionTicks { get; set; }
public TranscodingThrottler TranscodingThrottler { get; set; }
private readonly object _timerLock = new object();
public DateTime LastPingDate { get; set; }
public int PingTimeout { get; set; }
public TranscodingJob(ILogger logger)
{
Logger = logger;
}
public void StopKillTimer()
{
lock (_timerLock)
{
if (KillTimer != null)
{
KillTimer.Change(Timeout.Infinite, Timeout.Infinite);
}
}
}
public void DisposeKillTimer()
{
lock (_timerLock)
{
if (KillTimer != null)
{
KillTimer.Dispose();
KillTimer = null;
}
}
}
public void StartKillTimer(Action<object> callback)
{
StartKillTimer(callback, PingTimeout);
}
public void StartKillTimer(Action<object> callback, int intervalMs)
{
if (HasExited)
{
return;
}
lock (_timerLock)
{
if (KillTimer == null)
{
Logger.LogDebug("Starting kill timer at {0}ms. JobId {1} PlaySessionId {2}", intervalMs, Id, PlaySessionId);
KillTimer = new Timer(new TimerCallback(callback), this, intervalMs, Timeout.Infinite);
}
else
{
Logger.LogDebug("Changing kill timer to {0}ms. JobId {1} PlaySessionId {2}", intervalMs, Id, PlaySessionId);
KillTimer.Change(intervalMs, Timeout.Infinite);
}
}
}
public void ChangeKillTimerIfStarted()
{
if (HasExited)
{
return;
}
lock (_timerLock)
{
if (KillTimer != null)
{
var intervalMs = PingTimeout;
Logger.LogDebug("Changing kill timer to {0}ms. JobId {1} PlaySessionId {2}", intervalMs, Id, PlaySessionId);
KillTimer.Change(intervalMs, Timeout.Infinite);
}
}
}
}
}

View file

@ -3,17 +3,18 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.TV; using MediaBrowser.Controller.TV;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using MediaBrowser.Model.Querying;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api namespace MediaBrowser.Api
{ {
@ -252,16 +253,11 @@ namespace MediaBrowser.Api
/// </summary> /// </summary>
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
/// <summary>
/// The _user data repository
/// </summary>
private readonly IUserDataManager _userDataManager;
/// <summary> /// <summary>
/// The _library manager /// The _library manager
/// </summary> /// </summary>
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly IItemRepository _itemRepo;
private readonly IDtoService _dtoService; private readonly IDtoService _dtoService;
private readonly ITVSeriesManager _tvSeriesManager; private readonly ITVSeriesManager _tvSeriesManager;
private readonly IAuthorizationContext _authContext; private readonly IAuthorizationContext _authContext;
@ -272,12 +268,19 @@ namespace MediaBrowser.Api
/// <param name="userManager">The user manager.</param> /// <param name="userManager">The user manager.</param>
/// <param name="userDataManager">The user data repository.</param> /// <param name="userDataManager">The user data repository.</param>
/// <param name="libraryManager">The library manager.</param> /// <param name="libraryManager">The library manager.</param>
public TvShowsService(IUserManager userManager, IUserDataManager userDataManager, ILibraryManager libraryManager, IItemRepository itemRepo, IDtoService dtoService, ITVSeriesManager tvSeriesManager, IAuthorizationContext authContext) public TvShowsService(
ILogger<TvShowsService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager,
ILibraryManager libraryManager,
IDtoService dtoService,
ITVSeriesManager tvSeriesManager,
IAuthorizationContext authContext)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_userManager = userManager; _userManager = userManager;
_userDataManager = userDataManager;
_libraryManager = libraryManager; _libraryManager = libraryManager;
_itemRepo = itemRepo;
_dtoService = dtoService; _dtoService = dtoService;
_tvSeriesManager = tvSeriesManager; _tvSeriesManager = tvSeriesManager;
_authContext = authContext; _authContext = authContext;

View file

@ -1,14 +1,15 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.UserLibrary namespace MediaBrowser.Api.UserLibrary
{ {
@ -49,6 +50,27 @@ namespace MediaBrowser.Api.UserLibrary
[Authenticated] [Authenticated]
public class ArtistsService : BaseItemsByNameService<MusicArtist> public class ArtistsService : BaseItemsByNameService<MusicArtist>
{ {
public ArtistsService(
ILogger<GenresService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager,
ILibraryManager libraryManager,
IUserDataManager userDataRepository,
IDtoService dtoService,
IAuthorizationContext authorizationContext)
: base(
logger,
serverConfigurationManager,
httpResultFactory,
userManager,
libraryManager,
userDataRepository,
dtoService,
authorizationContext)
{
}
/// <summary> /// <summary>
/// Gets the specified request. /// Gets the specified request.
/// </summary> /// </summary>
@ -122,9 +144,5 @@ namespace MediaBrowser.Api.UserLibrary
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public ArtistsService(IUserManager userManager, ILibraryManager libraryManager, IUserDataManager userDataRepository, IItemRepository itemRepository, IDtoService dtoService, IAuthorizationContext authorizationContext) : base(userManager, libraryManager, userDataRepository, itemRepository, dtoService, authorizationContext)
{
}
} }
} }

View file

@ -1,14 +1,15 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.UserLibrary namespace MediaBrowser.Api.UserLibrary
{ {
@ -19,37 +20,47 @@ namespace MediaBrowser.Api.UserLibrary
public abstract class BaseItemsByNameService<TItemType> : BaseApiService public abstract class BaseItemsByNameService<TItemType> : BaseApiService
where TItemType : BaseItem, IItemByName where TItemType : BaseItem, IItemByName
{ {
/// <summary>
/// The _user manager
/// </summary>
protected readonly IUserManager UserManager;
/// <summary>
/// The library manager
/// </summary>
protected readonly ILibraryManager LibraryManager;
protected readonly IUserDataManager UserDataRepository;
protected readonly IItemRepository ItemRepository;
protected IDtoService DtoService { get; private set; }
protected IAuthorizationContext AuthorizationContext { get; private set; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BaseItemsByNameService{TItemType}" /> class. /// Initializes a new instance of the <see cref="BaseItemsByNameService{TItemType}" /> class.
/// </summary> /// </summary>
/// <param name="userManager">The user manager.</param> /// <param name="userManager">The user manager.</param>
/// <param name="libraryManager">The library manager.</param> /// <param name="libraryManager">The library manager.</param>
/// <param name="userDataRepository">The user data repository.</param> /// <param name="userDataRepository">The user data repository.</param>
/// <param name="itemRepository">The item repository.</param>
/// <param name="dtoService">The dto service.</param> /// <param name="dtoService">The dto service.</param>
protected BaseItemsByNameService(IUserManager userManager, ILibraryManager libraryManager, IUserDataManager userDataRepository, IItemRepository itemRepository, IDtoService dtoService, IAuthorizationContext authorizationContext) protected BaseItemsByNameService(
ILogger logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager,
ILibraryManager libraryManager,
IUserDataManager userDataRepository,
IDtoService dtoService,
IAuthorizationContext authorizationContext)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
UserManager = userManager; UserManager = userManager;
LibraryManager = libraryManager; LibraryManager = libraryManager;
UserDataRepository = userDataRepository; UserDataRepository = userDataRepository;
ItemRepository = itemRepository;
DtoService = dtoService; DtoService = dtoService;
AuthorizationContext = authorizationContext; AuthorizationContext = authorizationContext;
} }
/// <summary>
/// Gets the _user manager.
/// </summary>
protected IUserManager UserManager { get; }
/// <summary>
/// Gets the library manager
/// </summary>
protected ILibraryManager LibraryManager { get; }
protected IUserDataManager UserDataRepository { get; }
protected IDtoService DtoService { get; }
protected IAuthorizationContext AuthorizationContext { get; }
protected BaseItem GetParentItem(GetItemsByName request) protected BaseItem GetParentItem(GetItemsByName request)
{ {
BaseItem parentItem; BaseItem parentItem;

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
@ -9,6 +10,7 @@ using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.UserLibrary namespace MediaBrowser.Api.UserLibrary
{ {
@ -47,6 +49,27 @@ namespace MediaBrowser.Api.UserLibrary
[Authenticated] [Authenticated]
public class GenresService : BaseItemsByNameService<Genre> public class GenresService : BaseItemsByNameService<Genre>
{ {
public GenresService(
ILogger<GenresService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager,
ILibraryManager libraryManager,
IUserDataManager userDataRepository,
IDtoService dtoService,
IAuthorizationContext authorizationContext)
: base(
logger,
serverConfigurationManager,
httpResultFactory,
userManager,
libraryManager,
userDataRepository,
dtoService,
authorizationContext)
{
}
/// <summary> /// <summary>
/// Gets the specified request. /// Gets the specified request.
/// </summary> /// </summary>
@ -114,9 +137,5 @@ namespace MediaBrowser.Api.UserLibrary
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public GenresService(IUserManager userManager, ILibraryManager libraryManager, IUserDataManager userDataRepository, IItemRepository itemRepository, IDtoService dtoService, IAuthorizationContext authorizationContext) : base(userManager, libraryManager, userDataRepository, itemRepository, dtoService, authorizationContext)
{
}
} }
} }

View file

@ -1,8 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Audio;
@ -58,25 +58,17 @@ namespace MediaBrowser.Api.UserLibrary
/// <param name="libraryManager">The library manager.</param> /// <param name="libraryManager">The library manager.</param>
/// <param name="localization">The localization.</param> /// <param name="localization">The localization.</param>
/// <param name="dtoService">The dto service.</param> /// <param name="dtoService">The dto service.</param>
public ItemsService(IUserManager userManager, ILibraryManager libraryManager, ILocalizationManager localization, IDtoService dtoService, IAuthorizationContext authContext) public ItemsService(
ILogger logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager,
ILibraryManager libraryManager,
ILocalizationManager localization,
IDtoService dtoService,
IAuthorizationContext authContext)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
if (userManager == null)
{
throw new ArgumentNullException(nameof(userManager));
}
if (libraryManager == null)
{
throw new ArgumentNullException(nameof(libraryManager));
}
if (localization == null)
{
throw new ArgumentNullException(nameof(localization));
}
if (dtoService == null)
{
throw new ArgumentNullException(nameof(dtoService));
}
_userManager = userManager; _userManager = userManager;
_libraryManager = libraryManager; _libraryManager = libraryManager;
_localization = localization; _localization = localization;

View file

@ -1,14 +1,15 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.UserLibrary namespace MediaBrowser.Api.UserLibrary
{ {
@ -38,6 +39,27 @@ namespace MediaBrowser.Api.UserLibrary
[Authenticated] [Authenticated]
public class MusicGenresService : BaseItemsByNameService<MusicGenre> public class MusicGenresService : BaseItemsByNameService<MusicGenre>
{ {
public MusicGenresService(
ILogger<MusicGenresService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager,
ILibraryManager libraryManager,
IUserDataManager userDataRepository,
IDtoService dtoService,
IAuthorizationContext authorizationContext)
: base(
logger,
serverConfigurationManager,
httpResultFactory,
userManager,
libraryManager,
userDataRepository,
dtoService,
authorizationContext)
{
}
/// <summary> /// <summary>
/// Gets the specified request. /// Gets the specified request.
/// </summary> /// </summary>
@ -98,9 +120,5 @@ namespace MediaBrowser.Api.UserLibrary
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public MusicGenresService(IUserManager userManager, ILibraryManager libraryManager, IUserDataManager userDataRepository, IItemRepository itemRepository, IDtoService dtoService, IAuthorizationContext authorizationContext) : base(userManager, libraryManager, userDataRepository, itemRepository, dtoService, authorizationContext)
{
}
} }
} }

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
@ -9,6 +10,7 @@ using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.UserLibrary namespace MediaBrowser.Api.UserLibrary
{ {
@ -47,6 +49,27 @@ namespace MediaBrowser.Api.UserLibrary
[Authenticated] [Authenticated]
public class PersonsService : BaseItemsByNameService<Person> public class PersonsService : BaseItemsByNameService<Person>
{ {
public PersonsService(
ILogger<PersonsService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager,
ILibraryManager libraryManager,
IUserDataManager userDataRepository,
IDtoService dtoService,
IAuthorizationContext authorizationContext)
: base(
logger,
serverConfigurationManager,
httpResultFactory,
userManager,
libraryManager,
userDataRepository,
dtoService,
authorizationContext)
{
}
/// <summary> /// <summary>
/// Gets the specified request. /// Gets the specified request.
/// </summary> /// </summary>
@ -120,9 +143,5 @@ namespace MediaBrowser.Api.UserLibrary
Items = items.Take(query.Limit ?? int.MaxValue).Select(i => (i as BaseItem, new ItemCounts())).ToArray() Items = items.Take(query.Limit ?? int.MaxValue).Select(i => (i as BaseItem, new ItemCounts())).ToArray()
}; };
} }
public PersonsService(IUserManager userManager, ILibraryManager libraryManager, IUserDataManager userDataRepository, IItemRepository itemRepository, IDtoService dtoService, IAuthorizationContext authorizationContext) : base(userManager, libraryManager, userDataRepository, itemRepository, dtoService, authorizationContext)
{
}
} }
} }

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Globalization; using System.Globalization;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
@ -233,7 +234,17 @@ namespace MediaBrowser.Api.UserLibrary
private readonly ISessionContext _sessionContext; private readonly ISessionContext _sessionContext;
private readonly IAuthorizationContext _authContext; private readonly IAuthorizationContext _authContext;
public PlaystateService(IUserManager userManager, IUserDataManager userDataRepository, ILibraryManager libraryManager, ISessionManager sessionManager, ISessionContext sessionContext, IAuthorizationContext authContext) public PlaystateService(
ILogger<PlaystateService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager,
IUserDataManager userDataRepository,
ILibraryManager libraryManager,
ISessionManager sessionManager,
ISessionContext sessionContext,
IAuthorizationContext authContext)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_userManager = userManager; _userManager = userManager;
_userDataRepository = userDataRepository; _userDataRepository = userDataRepository;
@ -256,7 +267,7 @@ namespace MediaBrowser.Api.UserLibrary
private UserItemDataDto MarkPlayed(MarkPlayedItem request) private UserItemDataDto MarkPlayed(MarkPlayedItem request)
{ {
var user = _userManager.GetUserById(request.UserId); var user = _userManager.GetUserById(Guid.Parse(request.UserId));
DateTime? datePlayed = null; DateTime? datePlayed = null;
@ -406,7 +417,7 @@ namespace MediaBrowser.Api.UserLibrary
private UserItemDataDto MarkUnplayed(MarkUnplayedItem request) private UserItemDataDto MarkUnplayed(MarkUnplayedItem request)
{ {
var user = _userManager.GetUserById(request.UserId); var user = _userManager.GetUserById(Guid.Parse(request.UserId));
var session = GetSession(_sessionContext); var session = GetSession(_sessionContext);

View file

@ -1,13 +1,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.UserLibrary namespace MediaBrowser.Api.UserLibrary
{ {
@ -46,6 +47,27 @@ namespace MediaBrowser.Api.UserLibrary
[Authenticated] [Authenticated]
public class StudiosService : BaseItemsByNameService<Studio> public class StudiosService : BaseItemsByNameService<Studio>
{ {
public StudiosService(
ILogger<StudiosService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager,
ILibraryManager libraryManager,
IUserDataManager userDataRepository,
IDtoService dtoService,
IAuthorizationContext authorizationContext)
: base(
logger,
serverConfigurationManager,
httpResultFactory,
userManager,
libraryManager,
userDataRepository,
dtoService,
authorizationContext)
{
}
/// <summary> /// <summary>
/// Gets the specified request. /// Gets the specified request.
/// </summary> /// </summary>
@ -106,9 +128,5 @@ namespace MediaBrowser.Api.UserLibrary
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public StudiosService(IUserManager userManager, ILibraryManager libraryManager, IUserDataManager userDataRepository, IItemRepository itemRepository, IDtoService dtoService, IAuthorizationContext authorizationContext) : base(userManager, libraryManager, userDataRepository, itemRepository, dtoService, authorizationContext)
{
}
} }
} }

View file

@ -3,6 +3,7 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Audio;
@ -14,6 +15,7 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.UserLibrary namespace MediaBrowser.Api.UserLibrary
{ {
@ -270,7 +272,18 @@ namespace MediaBrowser.Api.UserLibrary
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
private readonly IAuthorizationContext _authContext; private readonly IAuthorizationContext _authContext;
public UserLibraryService(IUserManager userManager, ILibraryManager libraryManager, IUserDataManager userDataRepository, IDtoService dtoService, IUserViewManager userViewManager, IFileSystem fileSystem, IAuthorizationContext authContext) public UserLibraryService(
ILogger<UserLibraryService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager,
ILibraryManager libraryManager,
IUserDataManager userDataRepository,
IDtoService dtoService,
IUserViewManager userViewManager,
IFileSystem fileSystem,
IAuthorizationContext authContext)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_userManager = userManager; _userManager = userManager;
_libraryManager = libraryManager; _libraryManager = libraryManager;

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
@ -51,11 +52,15 @@ namespace MediaBrowser.Api.UserLibrary
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
public UserViewsService( public UserViewsService(
ILogger<UserViewsService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager, IUserManager userManager,
IUserViewManager userViewManager, IUserViewManager userViewManager,
IDtoService dtoService, IDtoService dtoService,
IAuthorizationContext authContext, IAuthorizationContext authContext,
ILibraryManager libraryManager) ILibraryManager libraryManager)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_userManager = userManager; _userManager = userManager;
_userViewManager = userViewManager; _userViewManager = userViewManager;

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
@ -8,6 +9,7 @@ using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.UserLibrary namespace MediaBrowser.Api.UserLibrary
{ {
@ -46,6 +48,27 @@ namespace MediaBrowser.Api.UserLibrary
[Authenticated] [Authenticated]
public class YearsService : BaseItemsByNameService<Year> public class YearsService : BaseItemsByNameService<Year>
{ {
public YearsService(
ILogger<YearsService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager,
ILibraryManager libraryManager,
IUserDataManager userDataRepository,
IDtoService dtoService,
IAuthorizationContext authorizationContext)
: base(
logger,
serverConfigurationManager,
httpResultFactory,
userManager,
libraryManager,
userDataRepository,
dtoService,
authorizationContext)
{
}
/// <summary> /// <summary>
/// Gets the specified request. /// Gets the specified request.
/// </summary> /// </summary>
@ -105,9 +128,5 @@ namespace MediaBrowser.Api.UserLibrary
.Distinct() .Distinct()
.Select(year => LibraryManager.GetYear(year)); .Select(year => LibraryManager.GetYear(year));
} }
public YearsService(IUserManager userManager, ILibraryManager libraryManager, IUserDataManager userDataRepository, IItemRepository itemRepository, IDtoService dtoService, IAuthorizationContext authorizationContext) : base(userManager, libraryManager, userDataRepository, itemRepository, dtoService, authorizationContext)
{
}
} }
} }

View file

@ -244,22 +244,23 @@ namespace MediaBrowser.Api
/// </summary> /// </summary>
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
private readonly ISessionManager _sessionMananger; private readonly ISessionManager _sessionMananger;
private readonly IServerConfigurationManager _config;
private readonly INetworkManager _networkManager; private readonly INetworkManager _networkManager;
private readonly IDeviceManager _deviceManager; private readonly IDeviceManager _deviceManager;
private readonly IAuthorizationContext _authContext; private readonly IAuthorizationContext _authContext;
public UserService( public UserService(
ILogger<UserService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IUserManager userManager, IUserManager userManager,
ISessionManager sessionMananger, ISessionManager sessionMananger,
IServerConfigurationManager config,
INetworkManager networkManager, INetworkManager networkManager,
IDeviceManager deviceManager, IDeviceManager deviceManager,
IAuthorizationContext authContext) IAuthorizationContext authContext)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_userManager = userManager; _userManager = userManager;
_sessionMananger = sessionMananger; _sessionMananger = sessionMananger;
_config = config;
_networkManager = networkManager; _networkManager = networkManager;
_deviceManager = deviceManager; _deviceManager = deviceManager;
_authContext = authContext; _authContext = authContext;
@ -268,7 +269,7 @@ namespace MediaBrowser.Api
public object Get(GetPublicUsers request) public object Get(GetPublicUsers request)
{ {
// If the startup wizard hasn't been completed then just return all users // If the startup wizard hasn't been completed then just return all users
if (!_config.Configuration.IsStartupWizardCompleted) if (!ServerConfigurationManager.Configuration.IsStartupWizardCompleted)
{ {
return Get(new GetUsers return Get(new GetUsers
{ {
@ -497,9 +498,9 @@ namespace MediaBrowser.Api
/// <param name="request">The request.</param> /// <param name="request">The request.</param>
public async Task Post(UpdateUser request) public async Task Post(UpdateUser request)
{ {
var id = GetPathValue(1); var id = Guid.Parse(GetPathValue(1));
AssertCanUpdateUser(_authContext, _userManager, new Guid(id), false); AssertCanUpdateUser(_authContext, _userManager, id, false);
var dtoUser = request; var dtoUser = request;

View file

@ -7,11 +7,10 @@ using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api namespace MediaBrowser.Api
{ {
@ -51,19 +50,21 @@ namespace MediaBrowser.Api
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
private readonly IDtoService _dtoService; private readonly IDtoService _dtoService;
private readonly IFileSystem _fileSystem;
private readonly IItemRepository _itemRepo;
private readonly IServerConfigurationManager _config;
private readonly IAuthorizationContext _authContext; private readonly IAuthorizationContext _authContext;
public VideosService(ILibraryManager libraryManager, IUserManager userManager, IDtoService dtoService, IItemRepository itemRepo, IFileSystem fileSystem, IServerConfigurationManager config, IAuthorizationContext authContext) public VideosService(
ILogger<VideosService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
ILibraryManager libraryManager,
IUserManager userManager,
IDtoService dtoService,
IAuthorizationContext authContext)
: base(logger, serverConfigurationManager, httpResultFactory)
{ {
_libraryManager = libraryManager; _libraryManager = libraryManager;
_userManager = userManager; _userManager = userManager;
_dtoService = dtoService; _dtoService = dtoService;
_itemRepo = itemRepo;
_fileSystem = fileSystem;
_config = config;
_authContext = authContext; _authContext = authContext;
} }
@ -84,9 +85,8 @@ namespace MediaBrowser.Api
var dtoOptions = GetDtoOptions(_authContext, request); var dtoOptions = GetDtoOptions(_authContext, request);
var video = item as Video;
BaseItemDto[] items; BaseItemDto[] items;
if (video != null) if (item is Video video)
{ {
items = video.GetAdditionalParts() items = video.GetAdditionalParts()
.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, video)) .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, video))
@ -94,7 +94,7 @@ namespace MediaBrowser.Api
} }
else else
{ {
items = new BaseItemDto[] { }; items = Array.Empty<BaseItemDto>();
} }
var result = new QueryResult<BaseItemDto> var result = new QueryResult<BaseItemDto>

View file

@ -9,7 +9,7 @@ using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.Library namespace MediaBrowser.Controller.Library
{ {
/// <summary> /// <summary>
/// Interface IUserDataManager /// Interface IUserDataManager.
/// </summary> /// </summary>
public interface IUserDataManager public interface IUserDataManager
{ {
@ -26,13 +26,11 @@ namespace MediaBrowser.Controller.Library
/// <param name="userData">The user data.</param> /// <param name="userData">The user data.</param>
/// <param name="reason">The reason.</param> /// <param name="reason">The reason.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
void SaveUserData(Guid userId, BaseItem item, UserItemData userData, UserDataSaveReason reason, CancellationToken cancellationToken); void SaveUserData(Guid userId, BaseItem item, UserItemData userData, UserDataSaveReason reason, CancellationToken cancellationToken);
void SaveUserData(User userId, BaseItem item, UserItemData userData, UserDataSaveReason reason, CancellationToken cancellationToken); void SaveUserData(User userId, BaseItem item, UserItemData userData, UserDataSaveReason reason, CancellationToken cancellationToken);
UserItemData GetUserData(User user, BaseItem item); UserItemData GetUserData(User user, BaseItem item);
UserItemData GetUserData(string userId, BaseItem item);
UserItemData GetUserData(Guid userId, BaseItem item); UserItemData GetUserData(Guid userId, BaseItem item);
/// <summary> /// <summary>

View file

@ -49,20 +49,13 @@ namespace MediaBrowser.Controller.Library
event EventHandler<GenericEventArgs<User>> UserLockedOut; event EventHandler<GenericEventArgs<User>> UserLockedOut;
/// <summary> /// <summary>
/// Gets a User by Id. /// Gets a user by Id.
/// </summary> /// </summary>
/// <param name="id">The id.</param> /// <param name="id">The id.</param>
/// <returns>The user with the specified Id, or <c>null</c> if the user doesn't exist.</returns> /// <returns>The user with the specified Id, or <c>null</c> if the user doesn't exist.</returns>
/// <exception cref="ArgumentException"><c>id</c> is an empty Guid.</exception> /// <exception cref="ArgumentException"><c>id</c> is an empty Guid.</exception>
User GetUserById(Guid id); User GetUserById(Guid id);
/// <summary>
/// Gets the user by identifier.
/// </summary>
/// <param name="id">The identifier.</param>
/// <returns>User.</returns>
User GetUserById(string id);
/// <summary> /// <summary>
/// Gets the name of the user by. /// Gets the name of the user by.
/// </summary> /// </summary>

View file

@ -172,16 +172,18 @@ namespace MediaBrowser.Model.Configuration
if (string.IsNullOrWhiteSpace(value)) if (string.IsNullOrWhiteSpace(value))
{ {
// If baseUrl is empty, set an empty prefix string // If baseUrl is empty, set an empty prefix string
value = string.Empty; _baseUrl = string.Empty;
return;
} }
else if (!value.StartsWith("/"))
if (value[0] != '/')
{ {
// If baseUrl was not configured with a leading slash, append one for consistency // If baseUrl was not configured with a leading slash, append one for consistency
value = "/" + value; value = "/" + value;
} }
// Normalize the end of the string // Normalize the end of the string
if (value.EndsWith("/")) if (value[value.Length - 1] == '/')
{ {
// If baseUrl was configured with a trailing slash, remove it for consistency // If baseUrl was configured with a trailing slash, remove it for consistency
value = value.Remove(value.Length - 1); value = value.Remove(value.Length - 1);

View file

@ -16,7 +16,6 @@ using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.XbmcMetadata.Configuration; using MediaBrowser.XbmcMetadata.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -856,7 +855,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
return; return;
} }
var user = userManager.GetUserById(userId); var user = userManager.GetUserById(Guid.Parse(userId));
if (user == null) if (user == null)
{ {

View file

@ -60,6 +60,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfin.MediaEncoding.Test
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfin.Naming.Tests", "tests\Jellyfin.Naming.Tests\Jellyfin.Naming.Tests.csproj", "{3998657B-1CCC-49DD-A19F-275DC8495F57}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfin.Naming.Tests", "tests\Jellyfin.Naming.Tests\Jellyfin.Naming.Tests.csproj", "{3998657B-1CCC-49DD-A19F-275DC8495F57}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfin.Api.Tests", "tests\Jellyfin.Api.Tests\Jellyfin.Api.Tests.csproj", "{A2FD0A10-8F62-4F9D-B171-FFDF9F0AFA9D}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -166,6 +168,10 @@ Global
{3998657B-1CCC-49DD-A19F-275DC8495F57}.Debug|Any CPU.Build.0 = Debug|Any CPU {3998657B-1CCC-49DD-A19F-275DC8495F57}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3998657B-1CCC-49DD-A19F-275DC8495F57}.Release|Any CPU.ActiveCfg = Release|Any CPU {3998657B-1CCC-49DD-A19F-275DC8495F57}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3998657B-1CCC-49DD-A19F-275DC8495F57}.Release|Any CPU.Build.0 = Release|Any CPU {3998657B-1CCC-49DD-A19F-275DC8495F57}.Release|Any CPU.Build.0 = Release|Any CPU
{A2FD0A10-8F62-4F9D-B171-FFDF9F0AFA9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A2FD0A10-8F62-4F9D-B171-FFDF9F0AFA9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A2FD0A10-8F62-4F9D-B171-FFDF9F0AFA9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A2FD0A10-8F62-4F9D-B171-FFDF9F0AFA9D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -195,5 +201,6 @@ Global
{DF194677-DFD3-42AF-9F75-D44D5A416478} = {FBBB5129-006E-4AD7-BAD5-8B7CA1D10ED6} {DF194677-DFD3-42AF-9F75-D44D5A416478} = {FBBB5129-006E-4AD7-BAD5-8B7CA1D10ED6}
{28464062-0939-4AA7-9F7B-24DDDA61A7C0} = {FBBB5129-006E-4AD7-BAD5-8B7CA1D10ED6} {28464062-0939-4AA7-9F7B-24DDDA61A7C0} = {FBBB5129-006E-4AD7-BAD5-8B7CA1D10ED6}
{3998657B-1CCC-49DD-A19F-275DC8495F57} = {FBBB5129-006E-4AD7-BAD5-8B7CA1D10ED6} {3998657B-1CCC-49DD-A19F-275DC8495F57} = {FBBB5129-006E-4AD7-BAD5-8B7CA1D10ED6}
{A2FD0A10-8F62-4F9D-B171-FFDF9F0AFA9D} = {FBBB5129-006E-4AD7-BAD5-8B7CA1D10ED6}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View file

@ -0,0 +1,45 @@
using MediaBrowser.Api;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;
namespace Jellyfin.Api.Tests
{
public class GetPathValueTests
{
[Theory]
[InlineData("https://localhost:8096/ScheduledTasks/1234/Triggers", "", 1, "1234")]
[InlineData("https://localhost:8096/emby/ScheduledTasks/1234/Triggers", "", 1, "1234")]
[InlineData("https://localhost:8096/mediabrowser/ScheduledTasks/1234/Triggers", "", 1, "1234")]
[InlineData("https://localhost:8096/jellyfin/2/ScheduledTasks/1234/Triggers", "jellyfin/2", 1, "1234")]
[InlineData("https://localhost:8096/jellyfin/2/emby/ScheduledTasks/1234/Triggers", "jellyfin/2", 1, "1234")]
[InlineData("https://localhost:8096/jellyfin/2/mediabrowser/ScheduledTasks/1234/Triggers", "jellyfin/2", 1, "1234")]
[InlineData("https://localhost:8096/JELLYFIN/2/ScheduledTasks/1234/Triggers", "jellyfin/2", 1, "1234")]
[InlineData("https://localhost:8096/JELLYFIN/2/Emby/ScheduledTasks/1234/Triggers", "jellyfin/2", 1, "1234")]
[InlineData("https://localhost:8096/JELLYFIN/2/MediaBrowser/ScheduledTasks/1234/Triggers", "jellyfin/2", 1, "1234")]
public void GetPathValueTest(string path, string baseUrl, int index, string value)
{
var reqMock = Mock.Of<IRequest>(x => x.PathInfo == path);
var conf = new ServerConfiguration()
{
BaseUrl = baseUrl
};
var confManagerMock = Mock.Of<IServerConfigurationManager>(x => x.Configuration == conf);
var service = new BrandingService(
new NullLogger<BrandingService>(),
confManagerMock,
Mock.Of<IHttpResultFactory>())
{
Request = reqMock
};
Assert.Equal(value, service.GetPathValue(index).ToString());
}
}
}

View file

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="coverlet.collector" Version="1.1.0" />
<PackageReference Include="Moq" Version="4.13.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../MediaBrowser.Api/MediaBrowser.Api.csproj" />
</ItemGroup>
</Project>