2019-01-13 14:16:19 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Emby.Dlna.Service;
|
|
|
|
|
using MediaBrowser.Common.Net;
|
2016-10-29 18:22:20 -04:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
|
using MediaBrowser.Controller.Dlna;
|
|
|
|
|
using MediaBrowser.Controller.Drawing;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.MediaEncoding;
|
2017-08-02 03:30:17 -04:00
|
|
|
|
using MediaBrowser.Controller.TV;
|
2019-01-13 14:16:19 -05:00
|
|
|
|
using MediaBrowser.Model.Dlna;
|
2016-10-29 18:22:20 -04:00
|
|
|
|
using MediaBrowser.Model.Globalization;
|
2016-11-04 04:31:05 -04:00
|
|
|
|
using MediaBrowser.Model.Xml;
|
2019-01-13 14:16:19 -05:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2016-10-29 18:22:20 -04:00
|
|
|
|
|
2016-10-29 18:34:54 -04:00
|
|
|
|
namespace Emby.Dlna.ContentDirectory
|
2016-10-29 18:22:20 -04:00
|
|
|
|
{
|
2017-09-05 15:49:02 -04:00
|
|
|
|
public class ContentDirectory : BaseService, IContentDirectory
|
2016-10-29 18:22:20 -04: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 13:26:21 -04:00
|
|
|
|
private readonly IMediaEncoder _mediaEncoder;
|
2016-11-04 04:31:05 -04:00
|
|
|
|
protected readonly IXmlReaderSettingsFactory XmlReaderSettingsFactory;
|
2017-08-02 03:30:17 -04:00
|
|
|
|
private readonly ITVSeriesManager _tvSeriesManager;
|
2016-10-29 18:22:20 -04:00
|
|
|
|
|
|
|
|
|
public ContentDirectory(IDlnaManager dlna,
|
|
|
|
|
IUserDataManager userDataManager,
|
|
|
|
|
IImageProcessor imageProcessor,
|
|
|
|
|
ILibraryManager libraryManager,
|
|
|
|
|
IServerConfigurationManager config,
|
|
|
|
|
IUserManager userManager,
|
|
|
|
|
ILogger logger,
|
2018-09-12 13:26:21 -04:00
|
|
|
|
IHttpClient httpClient, ILocalizationManager localization, IMediaSourceManager mediaSourceManager, IUserViewManager userViewManager, IMediaEncoder mediaEncoder, IXmlReaderSettingsFactory xmlReaderSettingsFactory, ITVSeriesManager tvSeriesManager)
|
2016-10-29 18:22:20 -04:00
|
|
|
|
: base(logger, httpClient)
|
|
|
|
|
{
|
|
|
|
|
_dlna = dlna;
|
|
|
|
|
_userDataManager = userDataManager;
|
|
|
|
|
_imageProcessor = imageProcessor;
|
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
|
_config = config;
|
|
|
|
|
_userManager = userManager;
|
|
|
|
|
_localization = localization;
|
|
|
|
|
_mediaSourceManager = mediaSourceManager;
|
|
|
|
|
_userViewManager = userViewManager;
|
|
|
|
|
_mediaEncoder = mediaEncoder;
|
2016-11-04 04:31:05 -04:00
|
|
|
|
XmlReaderSettingsFactory = xmlReaderSettingsFactory;
|
2017-08-02 03:30:17 -04:00
|
|
|
|
_tvSeriesManager = tvSeriesManager;
|
2016-10-29 18:22:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int SystemUpdateId
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var now = DateTime.UtcNow;
|
|
|
|
|
|
|
|
|
|
return now.Year + now.DayOfYear + now.Hour;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetServiceXml(IDictionary<string, string> headers)
|
|
|
|
|
{
|
|
|
|
|
return new ContentDirectoryXmlBuilder().GetXml();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ControlResponse ProcessControlRequest(ControlRequest request)
|
|
|
|
|
{
|
|
|
|
|
var profile = _dlna.GetProfile(request.Headers) ??
|
|
|
|
|
_dlna.GetDefaultProfile();
|
|
|
|
|
|
|
|
|
|
var serverAddress = request.RequestedUrl.Substring(0, request.RequestedUrl.IndexOf("/dlna", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
string accessToken = null;
|
|
|
|
|
|
|
|
|
|
var user = GetUser(profile);
|
|
|
|
|
|
|
|
|
|
return new ControlHandler(
|
|
|
|
|
Logger,
|
|
|
|
|
_libraryManager,
|
|
|
|
|
profile,
|
|
|
|
|
serverAddress,
|
|
|
|
|
accessToken,
|
|
|
|
|
_imageProcessor,
|
|
|
|
|
_userDataManager,
|
|
|
|
|
user,
|
|
|
|
|
SystemUpdateId,
|
|
|
|
|
_config,
|
|
|
|
|
_localization,
|
|
|
|
|
_mediaSourceManager,
|
|
|
|
|
_userViewManager,
|
2018-09-12 13:26:21 -04:00
|
|
|
|
_mediaEncoder,
|
2017-08-02 03:30:17 -04:00
|
|
|
|
XmlReaderSettingsFactory,
|
|
|
|
|
_tvSeriesManager)
|
2016-10-29 18:22:20 -04:00
|
|
|
|
.ProcessControlRequest(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private User GetUser(DeviceProfile profile)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(profile.UserId))
|
|
|
|
|
{
|
|
|
|
|
var user = _userManager.GetUserById(profile.UserId);
|
|
|
|
|
|
|
|
|
|
if (user != null)
|
|
|
|
|
{
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var userId = _config.GetDlnaConfiguration().DefaultUserId;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(userId))
|
|
|
|
|
{
|
|
|
|
|
var user = _userManager.GetUserById(userId);
|
|
|
|
|
|
|
|
|
|
if (user != null)
|
|
|
|
|
{
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-24 15:52:19 -04:00
|
|
|
|
foreach (var user in _userManager.Users)
|
|
|
|
|
{
|
|
|
|
|
if (user.Policy.IsAdministrator)
|
|
|
|
|
{
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var user in _userManager.Users)
|
|
|
|
|
{
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
2016-10-29 18:22:20 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|