2014-05-21 03:15:46 +02:00
|
|
|
|
using MediaBrowser.Common.Net;
|
2014-07-30 05:31:35 +02: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-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;
|
|
|
|
|
|
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-07-30 05:31:35 +02:00
|
|
|
|
private readonly IUserViewManager _userViewManager;
|
|
|
|
|
private readonly IChannelManager _channelManager;
|
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,
|
2014-07-30 05:31:35 +02:00
|
|
|
|
IHttpClient httpClient, IUserViewManager userViewManager, IChannelManager channelManager)
|
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-07-30 05:31:35 +02:00
|
|
|
|
_userViewManager = userViewManager;
|
|
|
|
|
_channelManager = channelManager;
|
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));
|
|
|
|
|
|
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,
|
|
|
|
|
_imageProcessor,
|
|
|
|
|
_userDataManager,
|
|
|
|
|
user,
|
2014-05-01 05:24:55 +02:00
|
|
|
|
SystemUpdateId,
|
2014-07-30 05:31:35 +02:00
|
|
|
|
_config,
|
|
|
|
|
_userViewManager,
|
|
|
|
|
_channelManager)
|
2014-04-21 18:02:30 +02:00
|
|
|
|
.ProcessControlRequest(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private User GetUser(DeviceProfile profile)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(profile.UserId))
|
|
|
|
|
{
|
|
|
|
|
var user = _userManager.GetUserById(new Guid(profile.UserId));
|
|
|
|
|
|
|
|
|
|
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-06-29 19:35:05 +02:00
|
|
|
|
var user = _userManager.GetUserById(new Guid(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()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|