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