jellyfin/MediaBrowser.Dlna/ContentDirectory/ContentDirectory.cs

134 lines
4.4 KiB
C#
Raw Normal View History

2014-05-21 01:15:46 +00:00
using MediaBrowser.Common.Net;
2014-12-01 12:43:34 +00:00
using MediaBrowser.Controller.Channels;
2014-05-21 01:15:46 +00:00
using MediaBrowser.Controller.Configuration;
2014-04-21 16:02:30 +00:00
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
2014-05-21 01:15:46 +00:00
using MediaBrowser.Dlna.Service;
2014-04-21 16:02:30 +00:00
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Controller.MediaEncoding;
2016-10-24 02:45:23 +00:00
using MediaBrowser.Model.Globalization;
2014-04-21 16:02:30 +00:00
2014-05-21 00:56:24 +00:00
namespace MediaBrowser.Dlna.ContentDirectory
2014-04-21 16:02:30 +00:00
{
2014-05-21 01:15:46 +00:00
public class ContentDirectory : BaseService, IContentDirectory, IDisposable
2014-04-21 16:02:30 +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;
2014-09-24 01:44:05 +00:00
private readonly ILocalizationManager _localization;
2014-12-01 12:43:34 +00:00
private readonly IChannelManager _channelManager;
2015-03-08 04:44:31 +00:00
private readonly IMediaSourceManager _mediaSourceManager;
2015-11-17 18:17:52 +00:00
private readonly IUserViewManager _userViewManager;
private readonly Func<IMediaEncoder> _mediaEncoder;
2014-04-21 16:02:30 +00:00
public ContentDirectory(IDlnaManager dlna,
IUserDataManager userDataManager,
IImageProcessor imageProcessor,
ILibraryManager libraryManager,
IServerConfigurationManager config,
IUserManager userManager,
2014-05-21 01:15:46 +00:00
ILogger logger,
IHttpClient httpClient, ILocalizationManager localization, IChannelManager channelManager, IMediaSourceManager mediaSourceManager, IUserViewManager userViewManager, Func<IMediaEncoder> mediaEncoder)
2014-05-21 01:15:46 +00:00
: base(logger, httpClient)
2014-04-21 16:02:30 +00:00
{
_dlna = dlna;
_userDataManager = userDataManager;
_imageProcessor = imageProcessor;
_libraryManager = libraryManager;
_config = config;
_userManager = userManager;
2014-09-24 01:44:05 +00:00
_localization = localization;
2014-12-01 12:43:34 +00:00
_channelManager = channelManager;
2015-03-08 04:44:31 +00:00
_mediaSourceManager = mediaSourceManager;
2015-11-17 18:17:52 +00:00
_userViewManager = userViewManager;
_mediaEncoder = mediaEncoder;
2014-04-25 20:15:50 +00:00
}
private int SystemUpdateId
{
get
{
var now = DateTime.UtcNow;
2014-04-21 16:02:30 +00:00
2014-04-25 20:15:50 +00:00
return now.Year + now.DayOfYear + now.Hour;
}
2014-04-21 16:02:30 +00:00
}
2014-05-21 00:56:24 +00:00
public string GetServiceXml(IDictionary<string, string> headers)
2014-04-21 16:02:30 +00:00
{
2014-05-21 00:56:24 +00:00
return new ContentDirectoryXmlBuilder().GetXml();
2014-04-21 16:02:30 +00:00
}
public ControlResponse ProcessControlRequest(ControlRequest request)
{
var profile = _dlna.GetProfile(request.Headers) ??
_dlna.GetDefaultProfile();
2014-04-25 17:30:41 +00:00
var serverAddress = request.RequestedUrl.Substring(0, request.RequestedUrl.IndexOf("/dlna", StringComparison.OrdinalIgnoreCase));
string accessToken = null;
2014-04-21 16:02:30 +00:00
var user = GetUser(profile);
return new ControlHandler(
2014-05-21 01:15:46 +00:00
Logger,
2014-04-21 16:02:30 +00:00
_libraryManager,
profile,
serverAddress,
accessToken,
2014-04-21 16:02:30 +00:00
_imageProcessor,
_userDataManager,
user,
2014-05-01 03:24:55 +00:00
SystemUpdateId,
2014-09-24 01:44:05 +00:00
_config,
2014-12-01 12:43:34 +00:00
_localization,
2015-03-08 04:44:31 +00:00
_channelManager,
2015-11-17 18:17:52 +00:00
_mediaSourceManager,
_userViewManager,
_mediaEncoder())
2014-04-21 16:02:30 +00:00
.ProcessControlRequest(request);
}
private User GetUser(DeviceProfile profile)
{
if (!string.IsNullOrEmpty(profile.UserId))
{
2014-09-14 15:10:51 +00:00
var user = _userManager.GetUserById(profile.UserId);
2014-04-21 16:02:30 +00:00
if (user != null)
{
return user;
}
}
2014-06-29 17:35:05 +00:00
var userId = _config.GetDlnaConfiguration().DefaultUserId;
if (!string.IsNullOrEmpty(userId))
2014-04-21 16:02:30 +00:00
{
2014-09-14 15:10:51 +00:00
var user = _userManager.GetUserById(userId);
2014-04-21 16:02:30 +00:00
if (user != null)
{
return user;
}
}
// No configuration so it's going to be pretty arbitrary
return _userManager.Users.First();
}
public void Dispose()
{
}
}
}