Skip to content

Commit

Permalink
Merge pull request #3256 from MediaBrowser/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
LukePulverenti authored May 2, 2018
2 parents 8b4724b + aab1b82 commit 7136f54
Show file tree
Hide file tree
Showing 977 changed files with 14,815 additions and 13,374 deletions.
52 changes: 0 additions & 52 deletions Docker/Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions Docker/LICENSE

This file was deleted.

26 changes: 0 additions & 26 deletions Docker/README.md

This file was deleted.

6 changes: 0 additions & 6 deletions Docker/start.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using MediaBrowser.Controller.Dlna;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Threading.Tasks;

using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Services;
using MediaBrowser.Common.Extensions;
using System.Text;
using MediaBrowser.Controller.Net;
using System.Linq;

namespace MediaBrowser.Api.Dlna
namespace Emby.Dlna.Api
{
[Route("/Dlna/{UuId}/description.xml", "GET", Summary = "Gets dlna server info")]
[Route("/Dlna/{UuId}/description", "GET", Summary = "Gets dlna server info")]
Expand Down Expand Up @@ -105,7 +106,7 @@ public class GetIcon
public string Filename { get; set; }
}

public class DlnaServerService : BaseApiService
public class DlnaServerService : IService, IRequiresRequest
{
private readonly IDlnaManager _dlnaManager;
private readonly IContentDirectory _contentDirectory;
Expand All @@ -115,13 +116,22 @@ public class DlnaServerService : BaseApiService
private const string XMLContentType = "text/xml; charset=UTF-8";
private readonly IMemoryStreamFactory _memoryStreamProvider;

public DlnaServerService(IDlnaManager dlnaManager, IContentDirectory contentDirectory, IConnectionManager connectionManager, IMediaReceiverRegistrar mediaReceiverRegistrar, IMemoryStreamFactory memoryStreamProvider)
public IRequest Request { get; set; }
private IHttpResultFactory _resultFactory;

public DlnaServerService(IDlnaManager dlnaManager, IHttpResultFactory httpResultFactory, IContentDirectory contentDirectory, IConnectionManager connectionManager, IMediaReceiverRegistrar mediaReceiverRegistrar, IMemoryStreamFactory memoryStreamProvider)
{
_dlnaManager = dlnaManager;
_contentDirectory = contentDirectory;
_connectionManager = connectionManager;
_mediaReceiverRegistrar = mediaReceiverRegistrar;
_memoryStreamProvider = memoryStreamProvider;
_resultFactory = httpResultFactory;
}

private string GetHeader(string name)
{
return Request.Headers[name];
}

public object Get(GetDescriptionXml request)
Expand All @@ -130,49 +140,53 @@ public object Get(GetDescriptionXml request)
var serverAddress = url.Substring(0, url.IndexOf("/dlna/", StringComparison.OrdinalIgnoreCase));
var xml = _dlnaManager.GetServerDescriptionXml(Request.Headers.ToDictionary(), request.UuId, serverAddress);

return ResultFactory.GetResult(xml, XMLContentType);
var cacheLength = TimeSpan.FromDays(1);
var cacheKey = Request.RawUrl.GetMD5();
var bytes = Encoding.UTF8.GetBytes(xml);

return _resultFactory.GetStaticResult(Request, cacheKey, null, cacheLength, XMLContentType, () => Task.FromResult<Stream>(new MemoryStream(bytes)));
}

public object Get(GetContentDirectory request)
{
var xml = _contentDirectory.GetServiceXml(Request.Headers.ToDictionary());

return ResultFactory.GetResult(xml, XMLContentType);
return _resultFactory.GetResult(xml, XMLContentType);
}

public object Get(GetMediaReceiverRegistrar request)
{
var xml = _mediaReceiverRegistrar.GetServiceXml(Request.Headers.ToDictionary());

return ResultFactory.GetResult(xml, XMLContentType);
return _resultFactory.GetResult(xml, XMLContentType);
}

public object Get(GetConnnectionManager request)
{
var xml = _connectionManager.GetServiceXml(Request.Headers.ToDictionary());

return ResultFactory.GetResult(xml, XMLContentType);
return _resultFactory.GetResult(xml, XMLContentType);
}

public object Post(ProcessMediaReceiverRegistrarControlRequest request)
{
var response = PostAsync(request.RequestStream, _mediaReceiverRegistrar);

return ResultFactory.GetResult(response.Xml, XMLContentType);
return _resultFactory.GetResult(response.Xml, XMLContentType);
}

public object Post(ProcessContentDirectoryControlRequest request)
{
var response = PostAsync(request.RequestStream, _contentDirectory);

return ResultFactory.GetResult(response.Xml, XMLContentType);
return _resultFactory.GetResult(response.Xml, XMLContentType);
}

public object Post(ProcessConnectionManagerControlRequest request)
{
var response = PostAsync(request.RequestStream, _connectionManager);

return ResultFactory.GetResult(response.Xml, XMLContentType);
return _resultFactory.GetResult(response.Xml, XMLContentType);
}

private ControlResponse PostAsync(Stream requestStream, IUpnpService service)
Expand All @@ -188,17 +202,56 @@ private ControlResponse PostAsync(Stream requestStream, IUpnpService service)
});
}

protected string GetPathValue(int index)
{
var pathInfo = Parse(Request.PathInfo);
var first = pathInfo[0];

// backwards compatibility
if (string.Equals(first, "mediabrowser", StringComparison.OrdinalIgnoreCase) ||
string.Equals(first, "emby", StringComparison.OrdinalIgnoreCase))
{
index++;
}

return pathInfo[index];
}

private List<string> Parse(string pathUri)
{
var actionParts = pathUri.Split(new[] { "://" }, StringSplitOptions.None);

var pathInfo = actionParts[actionParts.Length - 1];

var optionsPos = pathInfo.LastIndexOf('?');
if (optionsPos != -1)
{
pathInfo = pathInfo.Substring(0, optionsPos);
}

var args = pathInfo.Split('/');

return args.Skip(1).ToList();
}

public object Get(GetIcon request)
{
using (var response = _dlnaManager.GetIcon(request.Filename))
{
using (var ms = _memoryStreamProvider.CreateNew())
using (var ms = new MemoryStream())
{
response.Stream.CopyTo(ms);

ms.Position = 0;
var bytes = ms.ToArray();
return ResultFactory.GetResult(bytes, "image/" + response.Format.ToString().ToLower());

var contentType = "image/" + response.Format.ToString().ToLower();

var cacheLength = TimeSpan.FromDays(365);
var cacheKey = Request.RawUrl.GetMD5();

return _resultFactory.GetStaticResult(Request, cacheKey, null, cacheLength, contentType, ()=> Task.FromResult<Stream>(new MemoryStream(bytes)));
//return ResultFactory.GetResult(bytes, contentType);
}
}
}
Expand Down Expand Up @@ -257,7 +310,7 @@ private object ProcessEventRequest(IEventManager eventManager)

private object GetSubscriptionResponse(EventSubscriptionResponse response)
{
return ResultFactory.GetResult(response.Content, response.ContentType, response.Headers);
return _resultFactory.GetResult(response.Content, response.ContentType, response.Headers);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Services;

namespace MediaBrowser.Api.Dlna
namespace Emby.Dlna.Api
{
[Route("/Dlna/ProfileInfos", "GET", Summary = "Gets a list of profiles")]
public class GetProfileInfos : IReturn<DeviceProfileInfo[]>
Expand Down Expand Up @@ -41,7 +41,7 @@ public class CreateProfile : DeviceProfile, IReturnVoid
}

[Authenticated(Roles = "Admin")]
public class DlnaService : BaseApiService
public class DlnaService : IService
{
private readonly IDlnaManager _dlnaManager;

Expand All @@ -52,23 +52,17 @@ public DlnaService(IDlnaManager dlnaManager)

public object Get(GetProfileInfos request)
{
var result = _dlnaManager.GetProfileInfos().ToArray();

return ToOptimizedResult(result);
return _dlnaManager.GetProfileInfos().ToArray();
}

public object Get(GetProfile request)
{
var result = _dlnaManager.GetProfile(request.Id);

return ToOptimizedResult(result);
return _dlnaManager.GetProfile(request.Id);
}

public object Get(GetDefaultProfile request)
{
var result = _dlnaManager.GetDefaultProfile();

return ToOptimizedResult(result);
return _dlnaManager.GetDefaultProfile();
}

public void Delete(DeleteProfile request)
Expand Down
5 changes: 3 additions & 2 deletions Emby.Dlna/Common/StateVariable.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;

namespace Emby.Dlna.Common
{
Expand All @@ -10,7 +11,7 @@ public class StateVariable

public bool SendsEvents { get; set; }

public List<string> AllowedValues { get; set; }
public string[] AllowedValues { get; set; }

public override string ToString()
{
Expand All @@ -19,7 +20,7 @@ public override string ToString()

public StateVariable()
{
AllowedValues = new List<string>();
AllowedValues = Array.Empty<string>();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

namespace MediaBrowser.Model.Configuration
namespace Emby.Dlna.Configuration
{
public class DlnaOptions
{
Expand Down
4 changes: 2 additions & 2 deletions Emby.Dlna/ConfigurationExtension.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Model.Configuration;
using Emby.Dlna.Configuration;
using System.Collections.Generic;

namespace Emby.Dlna
Expand All @@ -16,7 +16,7 @@ public class DlnaConfigurationFactory : IConfigurationFactory
{
public IEnumerable<ConfigurationStore> GetConfigurations()
{
return new List<ConfigurationStore>
return new ConfigurationStore[]
{
new ConfigurationStore
{
Expand Down
Loading

0 comments on commit 7136f54

Please sign in to comment.