Properly use DI to reference other controllers.

This commit is contained in:
crobibero 2020-08-03 13:15:21 -06:00
parent db36b9d501
commit 0f32beb75f
2 changed files with 22 additions and 132 deletions

View File

@ -1,14 +1,10 @@
using System;
using Jellyfin.Api.Constants;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Querying;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Api.Controllers
{
@ -18,32 +14,15 @@ namespace Jellyfin.Api.Controllers
[Authorize(Policy = Policies.DefaultAuthorization)]
public class TrailersController : BaseJellyfinApiController
{
private readonly IUserManager _userManager;
private readonly ILibraryManager _libraryManager;
private readonly ILogger<ItemsController> _logger;
private readonly IDtoService _dtoService;
private readonly ILocalizationManager _localizationManager;
private readonly ItemsController _itemsController;
/// <summary>
/// Initializes a new instance of the <see cref="TrailersController"/> class.
/// </summary>
/// <param name="loggerFactory">Instance of the <see cref="ILoggerFactory"/> interface.</param>
/// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
/// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param>
/// <param name="localizationManager">Instance of the <see cref="ILocalizationManager"/> interface.</param>
public TrailersController(
ILoggerFactory loggerFactory,
IUserManager userManager,
ILibraryManager libraryManager,
IDtoService dtoService,
ILocalizationManager localizationManager)
/// <param name="itemsController">Instance of <see cref="ItemsController"/>.</param>
public TrailersController(ItemsController itemsController)
{
_userManager = userManager;
_libraryManager = libraryManager;
_dtoService = dtoService;
_localizationManager = localizationManager;
_logger = loggerFactory.CreateLogger<ItemsController>();
_itemsController = itemsController;
}
/// <summary>
@ -214,12 +193,7 @@ namespace Jellyfin.Api.Controllers
{
var includeItemTypes = "Trailer";
return new ItemsController(
_userManager,
_libraryManager,
_localizationManager,
_dtoService,
_logger)
return _itemsController
.GetItems(
userId,
userId,

View File

@ -7,21 +7,12 @@ using System.Threading.Tasks;
using Jellyfin.Api.Constants;
using Jellyfin.Api.Helpers;
using Jellyfin.Api.Models.VideoDtos;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Api.Controllers
{
@ -30,72 +21,28 @@ namespace Jellyfin.Api.Controllers
/// </summary>
public class UniversalAudioController : BaseJellyfinApiController
{
private readonly ILoggerFactory _loggerFactory;
private readonly IUserManager _userManager;
private readonly ILibraryManager _libraryManager;
private readonly IDeviceManager _deviceManager;
private readonly IDlnaManager _dlnaManager;
private readonly IMediaEncoder _mediaEncoder;
private readonly IFileSystem _fileSystem;
private readonly IMediaSourceManager _mediaSourceManager;
private readonly IAuthorizationContext _authorizationContext;
private readonly INetworkManager _networkManager;
private readonly IServerConfigurationManager _serverConfigurationManager;
private readonly TranscodingJobHelper _transcodingJobHelper;
private readonly IConfiguration _configuration;
private readonly ISubtitleEncoder _subtitleEncoder;
private readonly IHttpClientFactory _httpClientFactory;
private readonly MediaInfoController _mediaInfoController;
private readonly DynamicHlsController _dynamicHlsController;
private readonly AudioController _audioController;
/// <summary>
/// Initializes a new instance of the <see cref="UniversalAudioController"/> class.
/// </summary>
/// <param name="loggerFactory">Instance of the <see cref="ILoggerFactory"/> interface.</param>
/// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</param>
/// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
/// <param name="mediaEncoder">Instance of the <see cref="IMediaEncoder"/> interface.</param>
/// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param>
/// <param name="dlnaManager">Instance of the <see cref="IDlnaManager"/> interface.</param>
/// <param name="deviceManager">Instance of the <see cref="IDeviceManager"/> interface.</param>
/// <param name="mediaSourceManager">Instance of the <see cref="IMediaSourceManager"/> interface.</param>
/// <param name="authorizationContext">Instance of the <see cref="IAuthorizationContext"/> interface.</param>
/// <param name="networkManager">Instance of the <see cref="INetworkManager"/> interface.</param>
/// <param name="transcodingJobHelper">Instance of the <see cref="TranscodingJobHelper"/> interface.</param>
/// <param name="configuration">Instance of the <see cref="IConfiguration"/> interface.</param>
/// <param name="subtitleEncoder">Instance of the <see cref="ISubtitleEncoder"/> interface.</param>
/// <param name="httpClientFactory">Instance of the <see cref="IHttpClientFactory"/> interface.</param>
/// <param name="mediaInfoController">Instance of the <see cref="MediaInfoController"/>.</param>
/// <param name="dynamicHlsController">Instance of the <see cref="DynamicHlsController"/>.</param>
/// <param name="audioController">Instance of the <see cref="AudioController"/>.</param>
public UniversalAudioController(
ILoggerFactory loggerFactory,
IServerConfigurationManager serverConfigurationManager,
IUserManager userManager,
ILibraryManager libraryManager,
IMediaEncoder mediaEncoder,
IFileSystem fileSystem,
IDlnaManager dlnaManager,
IDeviceManager deviceManager,
IMediaSourceManager mediaSourceManager,
IAuthorizationContext authorizationContext,
INetworkManager networkManager,
TranscodingJobHelper transcodingJobHelper,
IConfiguration configuration,
ISubtitleEncoder subtitleEncoder,
IHttpClientFactory httpClientFactory)
MediaInfoController mediaInfoController,
DynamicHlsController dynamicHlsController,
AudioController audioController)
{
_userManager = userManager;
_libraryManager = libraryManager;
_mediaEncoder = mediaEncoder;
_fileSystem = fileSystem;
_dlnaManager = dlnaManager;
_deviceManager = deviceManager;
_mediaSourceManager = mediaSourceManager;
_authorizationContext = authorizationContext;
_networkManager = networkManager;
_loggerFactory = loggerFactory;
_serverConfigurationManager = serverConfigurationManager;
_transcodingJobHelper = transcodingJobHelper;
_configuration = configuration;
_subtitleEncoder = subtitleEncoder;
_httpClientFactory = httpClientFactory;
_mediaInfoController = mediaInfoController;
_dynamicHlsController = dynamicHlsController;
_audioController = audioController;
}
/// <summary>
@ -151,8 +98,7 @@ namespace Jellyfin.Api.Controllers
var deviceProfile = GetDeviceProfile(container, transcodingContainer, audioCodec, transcodingProtocol, breakOnNonKeyFrames, transcodingAudioChannels, maxAudioSampleRate, maxAudioBitDepth, maxAudioChannels);
_authorizationContext.GetAuthorizationInfo(Request).DeviceId = deviceId;
var mediaInfoController = new MediaInfoController(_mediaSourceManager, _deviceManager, _libraryManager, _networkManager, _mediaEncoder, _userManager, _authorizationContext, _loggerFactory.CreateLogger<MediaInfoController>(), _serverConfigurationManager);
var playbackInfoResult = await mediaInfoController.GetPostedPlaybackInfo(
var playbackInfoResult = await _mediaInfoController.GetPostedPlaybackInfo(
itemId,
userId,
maxStreamingBitrate,
@ -180,21 +126,6 @@ namespace Jellyfin.Api.Controllers
var isStatic = mediaSource.SupportsDirectStream;
if (!isStatic && string.Equals(mediaSource.TranscodingSubProtocol, "hls", StringComparison.OrdinalIgnoreCase))
{
var dynamicHlsController = new DynamicHlsController(
_libraryManager,
_userManager,
_dlnaManager,
_authorizationContext,
_mediaSourceManager,
_serverConfigurationManager,
_mediaEncoder,
_fileSystem,
_subtitleEncoder,
_configuration,
_deviceManager,
_transcodingJobHelper,
_networkManager,
_loggerFactory.CreateLogger<DynamicHlsController>());
var transcodingProfile = deviceProfile.TranscodingProfiles[0];
// hls segment container can only be mpegts or fmp4 per ffmpeg documentation
@ -203,10 +134,10 @@ namespace Jellyfin.Api.Controllers
if (isHeadRequest)
{
dynamicHlsController.Request.Method = HttpMethod.Head.Method;
_dynamicHlsController.Request.Method = HttpMethod.Head.Method;
}
return await dynamicHlsController.GetMasterHlsAudioPlaylist(
return await _dynamicHlsController.GetMasterHlsAudioPlaylist(
itemId,
".m3u8",
isStatic,
@ -261,27 +192,12 @@ namespace Jellyfin.Api.Controllers
}
else
{
var audioController = new AudioController(
_dlnaManager,
_userManager,
_authorizationContext,
_libraryManager,
_mediaSourceManager,
_serverConfigurationManager,
_mediaEncoder,
_fileSystem,
_subtitleEncoder,
_configuration,
_deviceManager,
_transcodingJobHelper,
_httpClientFactory);
if (isHeadRequest)
{
audioController.Request.Method = HttpMethod.Head.Method;
_audioController.Request.Method = HttpMethod.Head.Method;
}
return await audioController.GetAudioStream(
return await _audioController.GetAudioStream(
itemId,
isStatic ? null : ("." + mediaSource.TranscodingContainer),
isStatic,