2020-01-22 20:00:07 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 19:54:44 +00:00
|
|
|
using System;
|
2020-05-13 02:10:35 +00:00
|
|
|
using System.Linq;
|
2020-08-31 17:26:42 +00:00
|
|
|
using System.Net.Http;
|
2020-01-21 16:59:41 +00:00
|
|
|
using System.Threading.Tasks;
|
2019-01-13 19:16:19 +00:00
|
|
|
using Emby.Dlna.Service;
|
2020-05-20 17:07:53 +00:00
|
|
|
using Jellyfin.Data.Entities;
|
2020-05-13 02:10:35 +00:00
|
|
|
using Jellyfin.Data.Enums;
|
2016-10-29 22:22:20 +00:00
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
using MediaBrowser.Controller.Dlna;
|
|
|
|
using MediaBrowser.Controller.Drawing;
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.MediaEncoding;
|
2017-08-02 07:30:17 +00:00
|
|
|
using MediaBrowser.Controller.TV;
|
2019-01-13 19:16:19 +00:00
|
|
|
using MediaBrowser.Model.Dlna;
|
2016-10-29 22:22:20 +00:00
|
|
|
using MediaBrowser.Model.Globalization;
|
2019-01-13 19:16:19 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
2016-10-29 22:22:20 +00:00
|
|
|
|
2016-10-29 22:34:54 +00:00
|
|
|
namespace Emby.Dlna.ContentDirectory
|
2016-10-29 22:22:20 +00:00
|
|
|
{
|
2020-09-13 13:31:12 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Defines the <see cref="ContentDirectoryService" />.
|
|
|
|
/// </summary>
|
2020-08-20 19:04:57 +00:00
|
|
|
public class ContentDirectoryService : BaseService, IContentDirectory
|
2016-10-29 22:22:20 +00:00
|
|
|
{
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
private readonly IImageProcessor _imageProcessor;
|
|
|
|
private readonly IUserDataManager _userDataManager;
|
|
|
|
private readonly IDlnaManager _dlna;
|
|
|
|
private readonly IServerConfigurationManager _config;
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
private readonly ILocalizationManager _localization;
|
|
|
|
private readonly IMediaSourceManager _mediaSourceManager;
|
|
|
|
private readonly IUserViewManager _userViewManager;
|
2018-09-12 17:26:21 +00:00
|
|
|
private readonly IMediaEncoder _mediaEncoder;
|
2017-08-02 07:30:17 +00:00
|
|
|
private readonly ITVSeriesManager _tvSeriesManager;
|
2016-10-29 22:22:20 +00:00
|
|
|
|
2020-09-13 13:31:12 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="ContentDirectoryService"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="dlna">The <see cref="IDlnaManager"/> to use in the <see cref="ContentDirectoryService"/> instance.</param>
|
|
|
|
/// <param name="userDataManager">The <see cref="IUserDataManager"/> to use in the <see cref="ContentDirectoryService"/> instance.</param>
|
|
|
|
/// <param name="imageProcessor">The <see cref="IImageProcessor"/> to use in the <see cref="ContentDirectoryService"/> instance.</param>
|
|
|
|
/// <param name="libraryManager">The <see cref="ILibraryManager"/> to use in the <see cref="ContentDirectoryService"/> instance.</param>
|
|
|
|
/// <param name="config">The <see cref="IServerConfigurationManager"/> to use in the <see cref="ContentDirectoryService"/> instance.</param>
|
|
|
|
/// <param name="userManager">The <see cref="IUserManager"/> to use in the <see cref="ContentDirectoryService"/> instance.</param>
|
|
|
|
/// <param name="logger">The <see cref="ILogger{ContentDirectoryService}"/> to use in the <see cref="ContentDirectoryService"/> instance.</param>
|
|
|
|
/// <param name="httpClient">The <see cref="IHttpClientFactory"/> to use in the <see cref="ContentDirectoryService"/> instance.</param>
|
|
|
|
/// <param name="localization">The <see cref="ILocalizationManager"/> to use in the <see cref="ContentDirectoryService"/> instance.</param>
|
|
|
|
/// <param name="mediaSourceManager">The <see cref="IMediaSourceManager"/> to use in the <see cref="ContentDirectoryService"/> instance.</param>
|
|
|
|
/// <param name="userViewManager">The <see cref="IUserViewManager"/> to use in the <see cref="ContentDirectoryService"/> instance.</param>
|
|
|
|
/// <param name="mediaEncoder">The <see cref="IMediaEncoder"/> to use in the <see cref="ContentDirectoryService"/> instance.</param>
|
|
|
|
/// <param name="tvSeriesManager">The <see cref="ITVSeriesManager"/> to use in the <see cref="ContentDirectoryService"/> instance.</param>
|
2020-08-20 19:04:57 +00:00
|
|
|
public ContentDirectoryService(
|
2020-05-20 17:07:53 +00:00
|
|
|
IDlnaManager dlna,
|
2016-10-29 22:22:20 +00:00
|
|
|
IUserDataManager userDataManager,
|
|
|
|
IImageProcessor imageProcessor,
|
|
|
|
ILibraryManager libraryManager,
|
|
|
|
IServerConfigurationManager config,
|
|
|
|
IUserManager userManager,
|
2020-08-20 19:04:57 +00:00
|
|
|
ILogger<ContentDirectoryService> logger,
|
2020-08-31 17:26:42 +00:00
|
|
|
IHttpClientFactory httpClient,
|
2019-02-01 16:43:31 +00:00
|
|
|
ILocalizationManager localization,
|
|
|
|
IMediaSourceManager mediaSourceManager,
|
|
|
|
IUserViewManager userViewManager,
|
|
|
|
IMediaEncoder mediaEncoder,
|
|
|
|
ITVSeriesManager tvSeriesManager)
|
2016-10-29 22:22:20 +00:00
|
|
|
: base(logger, httpClient)
|
|
|
|
{
|
|
|
|
_dlna = dlna;
|
|
|
|
_userDataManager = userDataManager;
|
|
|
|
_imageProcessor = imageProcessor;
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
_config = config;
|
|
|
|
_userManager = userManager;
|
|
|
|
_localization = localization;
|
|
|
|
_mediaSourceManager = mediaSourceManager;
|
|
|
|
_userViewManager = userViewManager;
|
|
|
|
_mediaEncoder = mediaEncoder;
|
2017-08-02 07:30:17 +00:00
|
|
|
_tvSeriesManager = tvSeriesManager;
|
2016-10-29 22:22:20 +00:00
|
|
|
}
|
|
|
|
|
2020-09-13 13:31:12 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the system id. (A unique id which changes on when our definition changes.)
|
|
|
|
/// </summary>
|
|
|
|
private static int SystemUpdateId
|
2016-10-29 22:22:20 +00:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
var now = DateTime.UtcNow;
|
|
|
|
|
|
|
|
return now.Year + now.DayOfYear + now.Hour;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-21 16:59:41 +00:00
|
|
|
/// <inheritdoc />
|
2019-02-27 13:23:39 +00:00
|
|
|
public string GetServiceXml()
|
2016-10-29 22:22:20 +00:00
|
|
|
{
|
2020-09-13 13:31:12 +00:00
|
|
|
return ContentDirectoryXmlBuilder.GetXml();
|
2016-10-29 22:22:20 +00:00
|
|
|
}
|
|
|
|
|
2020-01-21 16:59:41 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
public Task<ControlResponse> ProcessControlRequestAsync(ControlRequest request)
|
2016-10-29 22:22:20 +00:00
|
|
|
{
|
2022-10-06 18:21:23 +00:00
|
|
|
ArgumentNullException.ThrowIfNull(request);
|
2020-09-13 13:31:12 +00:00
|
|
|
|
|
|
|
var profile = _dlna.GetProfile(request.Headers) ?? _dlna.GetDefaultProfile();
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
|
|
var serverAddress = request.RequestedUrl.Substring(0, request.RequestedUrl.IndexOf("/dlna", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
var user = GetUser(profile);
|
|
|
|
|
|
|
|
return new ControlHandler(
|
|
|
|
Logger,
|
|
|
|
_libraryManager,
|
|
|
|
profile,
|
|
|
|
serverAddress,
|
2019-01-25 20:52:10 +00:00
|
|
|
null,
|
2016-10-29 22:22:20 +00:00
|
|
|
_imageProcessor,
|
|
|
|
_userDataManager,
|
|
|
|
user,
|
|
|
|
SystemUpdateId,
|
|
|
|
_config,
|
|
|
|
_localization,
|
|
|
|
_mediaSourceManager,
|
|
|
|
_userViewManager,
|
2018-09-12 17:26:21 +00:00
|
|
|
_mediaEncoder,
|
2017-08-02 07:30:17 +00:00
|
|
|
_tvSeriesManager)
|
2020-01-21 16:59:41 +00:00
|
|
|
.ProcessControlRequestAsync(request);
|
2016-10-29 22:22:20 +00:00
|
|
|
}
|
|
|
|
|
2020-09-13 13:31:12 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Get the user stored in the device profile.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="profile">The <see cref="DeviceProfile"/>.</param>
|
|
|
|
/// <returns>The <see cref="User"/>.</returns>
|
2021-07-26 21:02:32 +00:00
|
|
|
private User? GetUser(DeviceProfile profile)
|
2016-10-29 22:22:20 +00:00
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(profile.UserId))
|
|
|
|
{
|
2019-11-17 22:05:39 +00:00
|
|
|
var user = _userManager.GetUserById(Guid.Parse(profile.UserId));
|
2016-10-29 22:22:20 +00:00
|
|
|
|
2022-12-05 14:01:13 +00:00
|
|
|
if (user is not null)
|
2016-10-29 22:22:20 +00:00
|
|
|
{
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var userId = _config.GetDlnaConfiguration().DefaultUserId;
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(userId))
|
|
|
|
{
|
2019-11-17 22:05:39 +00:00
|
|
|
var user = _userManager.GetUserById(Guid.Parse(userId));
|
2016-10-29 22:22:20 +00:00
|
|
|
|
2022-12-05 14:01:13 +00:00
|
|
|
if (user is not null)
|
2016-10-29 22:22:20 +00:00
|
|
|
{
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-24 19:52:19 +00:00
|
|
|
foreach (var user in _userManager.Users)
|
|
|
|
{
|
2020-05-13 02:10:35 +00:00
|
|
|
if (user.HasPermission(PermissionKind.IsAdministrator))
|
2017-08-24 19:52:19 +00:00
|
|
|
{
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-13 02:10:35 +00:00
|
|
|
return _userManager.Users.FirstOrDefault();
|
2016-10-29 22:22:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|