jellyfin/MediaBrowser.Dlna/ContentDirectory/ContentDirectory.cs

134 lines
4.4 KiB
C#
Raw Normal View History

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