2014-05-21 01:15:46 +00:00
|
|
|
|
using MediaBrowser.Common.Net;
|
|
|
|
|
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-09-24 01:44:05 +00:00
|
|
|
|
using MediaBrowser.Controller.Localization;
|
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;
|
|
|
|
|
|
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-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,
|
2014-09-24 01:44:05 +00:00
|
|
|
|
IHttpClient httpClient, ILocalizationManager localization)
|
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-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));
|
|
|
|
|
|
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,
|
|
|
|
|
_imageProcessor,
|
|
|
|
|
_userDataManager,
|
|
|
|
|
user,
|
2014-05-01 03:24:55 +00:00
|
|
|
|
SystemUpdateId,
|
2014-09-24 01:44:05 +00:00
|
|
|
|
_config,
|
|
|
|
|
_localization)
|
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()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|