Skip to content

Commit

Permalink
Merge pull request #3231 from MediaBrowser/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
LukePulverenti authored Apr 9, 2018
2 parents 1786ada + 2157cd4 commit 904321b
Show file tree
Hide file tree
Showing 94 changed files with 549 additions and 244 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +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 @@ -107,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 @@ -117,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 @@ -136,49 +144,49 @@ public object Get(GetDescriptionXml request)
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)));
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 @@ -194,6 +202,38 @@ 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))
Expand All @@ -210,7 +250,7 @@ public object Get(GetIcon request)
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.GetStaticResult(Request, cacheKey, null, cacheLength, contentType, ()=> Task.FromResult<Stream>(new MemoryStream(bytes)));
//return ResultFactory.GetResult(bytes, contentType);
}
}
Expand Down Expand Up @@ -270,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 Down
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
2 changes: 1 addition & 1 deletion 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 Down
2 changes: 1 addition & 1 deletion Emby.Dlna/Didl/DidlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
using System.Threading.Tasks;
using System.Xml;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Model.Configuration;
using Emby.Dlna.Configuration;
using MediaBrowser.Model.Globalization;

namespace Emby.Dlna.Didl
Expand Down
1 change: 1 addition & 0 deletions Emby.Dlna/Emby.Dlna.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<Compile Include="Common\ServiceAction.cs" />
<Compile Include="Common\StateVariable.cs" />
<Compile Include="ConfigurationExtension.cs" />
<Compile Include="Configuration\DlnaOptions.cs" />
<Compile Include="ConnectionManager\ConnectionManager.cs" />
<Compile Include="ConnectionManager\ConnectionManagerXmlBuilder.cs" />
<Compile Include="ConnectionManager\ControlHandler.cs" />
Expand Down
5 changes: 5 additions & 0 deletions Emby.Server.Implementations/Channels/ChannelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public bool EnableMediaProbe(BaseItem item)
public Task DeleteItem(BaseItem item)
{
var internalChannel = _libraryManager.GetItemById(item.ChannelId);
if (internalChannel == null)
{
throw new ArgumentException();
}

var channel = Channels.FirstOrDefault(i => GetInternalChannelId(i.Name).Equals(internalChannel.Id));

var supportsDelete = channel as ISupportsDelete;
Expand Down
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/Library/MediaSourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public async Task<LiveStreamResponse> OpenLiveStream(LiveStreamRequest request,
_openStreams[mediaSource.LiveStreamId] = info;

var json = _jsonSerializer.SerializeToString(mediaSource);
_logger.Debug("Live stream opened: " + json);
_logger.Info("Live stream opened: " + json);
var clone = _jsonSerializer.DeserializeFromString<MediaSourceInfo>(json);

if (!string.IsNullOrEmpty(request.UserId))
Expand Down
11 changes: 6 additions & 5 deletions Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ public Task<SeriesTimerInfo> GetNewTimerDefaultsAsync(CancellationToken cancella
defaults.SeriesId = program.SeriesId;
defaults.ProgramId = program.Id;
defaults.RecordNewOnly = !program.IsRepeat;
defaults.Name = program.Name;
}

defaults.SkipEpisodesInLibrary = defaults.RecordNewOnly;
Expand Down Expand Up @@ -2574,11 +2575,6 @@ private IEnumerable<TimerInfo> GetTimersForSeries(SeriesTimerInfo seriesTimer)
throw new ArgumentNullException("seriesTimer");
}

if (string.IsNullOrWhiteSpace(seriesTimer.SeriesId))
{
return new List<TimerInfo>();
}

var query = new InternalItemsQuery
{
IncludeItemTypes = new string[] { typeof(LiveTvProgram).Name },
Expand All @@ -2590,6 +2586,11 @@ private IEnumerable<TimerInfo> GetTimersForSeries(SeriesTimerInfo seriesTimer)
MinEndDate = DateTime.UtcNow
};

if (string.IsNullOrEmpty(seriesTimer.SeriesId))
{
query.Name = seriesTimer.Name;
}

if (!seriesTimer.RecordAnyChannel)
{
query.ChannelIds = new[] { _liveTvManager.GetInternalChannelId(Name, seriesTimer.ChannelId) };
Expand Down
Loading

0 comments on commit 904321b

Please sign in to comment.