diff --git a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj
index d7e5886d5..967cf54a6 100644
--- a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj
+++ b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj
@@ -48,9 +48,9 @@
Always
-
+
False
- ..\packages\NLog.3.2.0.0\lib\net45\NLog.dll
+ ..\packages\NLog.3.2.1\lib\net45\NLog.dll
False
diff --git a/MediaBrowser.Common.Implementations/packages.config b/MediaBrowser.Common.Implementations/packages.config
index 825b6662b..56cb78031 100644
--- a/MediaBrowser.Common.Implementations/packages.config
+++ b/MediaBrowser.Common.Implementations/packages.config
@@ -1,5 +1,5 @@
-
+
diff --git a/MediaBrowser.Controller/Dlna/ISsdpHandler.cs b/MediaBrowser.Controller/Dlna/ISsdpHandler.cs
new file mode 100644
index 000000000..e4126ddcf
--- /dev/null
+++ b/MediaBrowser.Controller/Dlna/ISsdpHandler.cs
@@ -0,0 +1,9 @@
+using System;
+
+namespace MediaBrowser.Controller.Dlna
+{
+ public interface ISsdpHandler
+ {
+ event EventHandler MessageReceived;
+ }
+}
diff --git a/MediaBrowser.Dlna/Ssdp/SsdpMessageEventArgs.cs b/MediaBrowser.Controller/Dlna/SsdpMessageEventArgs.cs
similarity index 85%
rename from MediaBrowser.Dlna/Ssdp/SsdpMessageEventArgs.cs
rename to MediaBrowser.Controller/Dlna/SsdpMessageEventArgs.cs
index 602a5bfc1..63f3a67aa 100644
--- a/MediaBrowser.Dlna/Ssdp/SsdpMessageEventArgs.cs
+++ b/MediaBrowser.Controller/Dlna/SsdpMessageEventArgs.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Net;
-namespace MediaBrowser.Dlna.Ssdp
+namespace MediaBrowser.Controller.Dlna
{
public class SsdpMessageEventArgs
{
@@ -13,6 +13,7 @@ namespace MediaBrowser.Dlna.Ssdp
public Dictionary Headers { get; set; }
public IPAddress LocalIp { get; set; }
+ public byte[] Message { get; set; }
public SsdpMessageEventArgs()
{
diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj
index 64490a74f..b66e6b9c8 100644
--- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj
+++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj
@@ -116,7 +116,9 @@
+
+
diff --git a/MediaBrowser.Dlna/Channels/DlnaChannelFactory.cs b/MediaBrowser.Dlna/Channels/DlnaChannelFactory.cs
index 78db68f63..7e896492d 100644
--- a/MediaBrowser.Dlna/Channels/DlnaChannelFactory.cs
+++ b/MediaBrowser.Dlna/Channels/DlnaChannelFactory.cs
@@ -2,6 +2,7 @@
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Dlna.ContentDirectory;
using MediaBrowser.Dlna.PlayTo;
diff --git a/MediaBrowser.Dlna/Main/DlnaEntryPoint.cs b/MediaBrowser.Dlna/Main/DlnaEntryPoint.cs
index 4a8baf0fe..f9f9c3f18 100644
--- a/MediaBrowser.Dlna/Main/DlnaEntryPoint.cs
+++ b/MediaBrowser.Dlna/Main/DlnaEntryPoint.cs
@@ -37,13 +37,26 @@ namespace MediaBrowser.Dlna.Main
private readonly ILocalizationManager _localization;
private readonly IMediaSourceManager _mediaSourceManager;
- private SsdpHandler _ssdpHandler;
+ private readonly SsdpHandler _ssdpHandler;
private DeviceDiscovery _deviceDiscovery;
private readonly List _registeredServerIds = new List();
private bool _dlnaServerStarted;
- public DlnaEntryPoint(IServerConfigurationManager config, ILogManager logManager, IServerApplicationHost appHost, INetworkManager network, ISessionManager sessionManager, IHttpClient httpClient, ILibraryManager libraryManager, IUserManager userManager, IDlnaManager dlnaManager, IImageProcessor imageProcessor, IUserDataManager userDataManager, ILocalizationManager localization, IMediaSourceManager mediaSourceManager)
+ public DlnaEntryPoint(IServerConfigurationManager config,
+ ILogManager logManager,
+ IServerApplicationHost appHost,
+ INetworkManager network,
+ ISessionManager sessionManager,
+ IHttpClient httpClient,
+ ILibraryManager libraryManager,
+ IUserManager userManager,
+ IDlnaManager dlnaManager,
+ IImageProcessor imageProcessor,
+ IUserDataManager userDataManager,
+ ILocalizationManager localization,
+ IMediaSourceManager mediaSourceManager,
+ ISsdpHandler ssdpHandler)
{
_config = config;
_appHost = appHost;
@@ -57,6 +70,7 @@ namespace MediaBrowser.Dlna.Main
_userDataManager = userDataManager;
_localization = localization;
_mediaSourceManager = mediaSourceManager;
+ _ssdpHandler = (SsdpHandler)ssdpHandler;
_logger = logManager.GetLogger("Dlna");
}
@@ -109,8 +123,6 @@ namespace MediaBrowser.Dlna.Main
{
try
{
- _ssdpHandler = new SsdpHandler(_logger, _config, GenerateServerSignature());
-
_ssdpHandler.Start();
_deviceDiscovery = new DeviceDiscovery(_logger, _config, _ssdpHandler, _appHost);
@@ -123,7 +135,7 @@ namespace MediaBrowser.Dlna.Main
}
}
- private void DisposeSsdpHandler()
+ private void DisposeDeviceDiscovery()
{
try
{
@@ -133,15 +145,6 @@ namespace MediaBrowser.Dlna.Main
{
_logger.ErrorException("Error disposing device discovery", ex);
}
-
- try
- {
- _ssdpHandler.Dispose();
- }
- catch (Exception ex)
- {
- _logger.ErrorException("Error disposing ssdp handler", ex);
- }
}
public void StartDlnaServer()
@@ -184,29 +187,6 @@ namespace MediaBrowser.Dlna.Main
}
}
- private string GenerateServerSignature()
- {
- var os = Environment.OSVersion;
- var pstring = os.Platform.ToString();
- switch (os.Platform)
- {
- case PlatformID.Win32NT:
- case PlatformID.Win32S:
- case PlatformID.Win32Windows:
- pstring = "WIN";
- break;
- }
-
- return String.Format(
- "{0}{1}/{2}.{3} UPnP/1.0 DLNADOC/1.5 MediaBrowser/{4}",
- pstring,
- IntPtr.Size * 8,
- os.Version.Major,
- os.Version.Minor,
- _appHost.ApplicationVersion
- );
- }
-
private readonly object _syncLock = new object();
private void StartPlayToManager()
{
@@ -260,7 +240,7 @@ namespace MediaBrowser.Dlna.Main
{
DisposeDlnaServer();
DisposePlayToManager();
- DisposeSsdpHandler();
+ DisposeDeviceDiscovery();
}
public void DisposeDlnaServer()
diff --git a/MediaBrowser.Dlna/MediaBrowser.Dlna.csproj b/MediaBrowser.Dlna/MediaBrowser.Dlna.csproj
index adb096ec7..b4e93ed68 100644
--- a/MediaBrowser.Dlna/MediaBrowser.Dlna.csproj
+++ b/MediaBrowser.Dlna/MediaBrowser.Dlna.csproj
@@ -135,7 +135,6 @@
-
diff --git a/MediaBrowser.Dlna/Ssdp/DeviceDiscovery.cs b/MediaBrowser.Dlna/Ssdp/DeviceDiscovery.cs
index cac1ffe7e..3dd482e64 100644
--- a/MediaBrowser.Dlna/Ssdp/DeviceDiscovery.cs
+++ b/MediaBrowser.Dlna/Ssdp/DeviceDiscovery.cs
@@ -2,6 +2,7 @@
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Controller.Dlna;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
@@ -183,7 +184,6 @@ namespace MediaBrowser.Dlna.Ssdp
}
}, _tokenSource.Token, TaskCreationOptions.LongRunning);
-
}
private Socket GetMulticastSocket(IPAddress localIpAddress, EndPoint localEndpoint)
diff --git a/MediaBrowser.Dlna/Ssdp/SsdpHandler.cs b/MediaBrowser.Dlna/Ssdp/SsdpHandler.cs
index 142fdf5fe..e4baaf2df 100644
--- a/MediaBrowser.Dlna/Ssdp/SsdpHandler.cs
+++ b/MediaBrowser.Dlna/Ssdp/SsdpHandler.cs
@@ -1,6 +1,8 @@
-using MediaBrowser.Common.Configuration;
+using MediaBrowser.Common;
+using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Events;
using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Controller.Dlna;
using MediaBrowser.Dlna.Server;
using MediaBrowser.Model.Logging;
using System;
@@ -16,7 +18,7 @@ using System.Threading.Tasks;
namespace MediaBrowser.Dlna.Ssdp
{
- public class SsdpHandler : IDisposable
+ public class SsdpHandler : IDisposable, ISsdpHandler
{
private Socket _socket;
@@ -39,13 +41,39 @@ namespace MediaBrowser.Dlna.Ssdp
private bool _isDisposed;
private readonly ConcurrentDictionary> _devices = new ConcurrentDictionary>();
- public SsdpHandler(ILogger logger, IServerConfigurationManager config, string serverSignature)
+ private readonly IApplicationHost _appHost;
+
+ public SsdpHandler(ILogger logger, IServerConfigurationManager config, IApplicationHost appHost)
{
_logger = logger;
_config = config;
- _serverSignature = serverSignature;
+ _appHost = appHost;
_config.NamedConfigurationUpdated += _config_ConfigurationUpdated;
+ _serverSignature = GenerateServerSignature();
+ }
+
+ private string GenerateServerSignature()
+ {
+ var os = Environment.OSVersion;
+ var pstring = os.Platform.ToString();
+ switch (os.Platform)
+ {
+ case PlatformID.Win32NT:
+ case PlatformID.Win32S:
+ case PlatformID.Win32Windows:
+ pstring = "WIN";
+ break;
+ }
+
+ return String.Format(
+ "{0}{1}/{2}.{3} UPnP/1.0 DLNADOC/1.5 MediaBrowser/{4}",
+ pstring,
+ IntPtr.Size * 8,
+ os.Version.Major,
+ os.Version.Minor,
+ _appHost.ApplicationVersion
+ );
}
void _config_ConfigurationUpdated(object sender, ConfigurationUpdateEventArgs e)
diff --git a/MediaBrowser.Dlna/Ssdp/SsdpHelper.cs b/MediaBrowser.Dlna/Ssdp/SsdpHelper.cs
index 707f0b877..d196e9851 100644
--- a/MediaBrowser.Dlna/Ssdp/SsdpHelper.cs
+++ b/MediaBrowser.Dlna/Ssdp/SsdpHelper.cs
@@ -1,4 +1,5 @@
-using System;
+using MediaBrowser.Controller.Dlna;
+using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
@@ -34,7 +35,8 @@ namespace MediaBrowser.Dlna.Ssdp
return new SsdpMessageEventArgs
{
Method = method,
- Headers = headers
+ Headers = headers,
+ Message = data
};
}
}
diff --git a/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs b/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs
index 06cbb9317..b5b63181a 100644
--- a/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs
+++ b/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs
@@ -1,5 +1,6 @@
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.Logging;
using Mono.Nat;
@@ -7,6 +8,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
+using System.Net;
using System.Text;
using System.Threading;
@@ -17,15 +19,17 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
private readonly IServerApplicationHost _appHost;
private readonly ILogger _logger;
private readonly IServerConfigurationManager _config;
+ private readonly ISsdpHandler _ssdp;
private Timer _timer;
private bool _isStarted;
- public ExternalPortForwarding(ILogManager logmanager, IServerApplicationHost appHost, IServerConfigurationManager config)
+ public ExternalPortForwarding(ILogManager logmanager, IServerApplicationHost appHost, IServerConfigurationManager config, ISsdpHandler ssdp)
{
_logger = logmanager.GetLogger("PortMapper");
_appHost = appHost;
_config = config;
+ _ssdp = ssdp;
}
private string _lastConfigIdentifier;
@@ -75,10 +79,10 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
private void Start()
{
_logger.Debug("Starting NAT discovery");
- //NatUtility.EnabledProtocols = new List
- //{
- // NatProtocol.Pmp
- //};
+ NatUtility.EnabledProtocols = new List
+ {
+ NatProtocol.Pmp
+ };
NatUtility.DeviceFound += NatUtility_DeviceFound;
// Mono.Nat does never rise this event. The event is there however it is useless.
@@ -93,11 +97,23 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
_timer = new Timer(s => _createdRules = new List(), null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));
+ _ssdp.MessageReceived += _ssdp_MessageReceived;
+
_lastConfigIdentifier = GetConfigIdentifier();
_isStarted = true;
}
+ void _ssdp_MessageReceived(object sender, SsdpMessageEventArgs e)
+ {
+ var endpoint = e.EndPoint as IPEndPoint;
+
+ if (endpoint != null && e.LocalIp != null)
+ {
+ NatUtility.Handle(e.LocalIp, e.Message, endpoint, NatProtocol.Upnp);
+ }
+ }
+
void NatUtility_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var ex = e.ExceptionObject as Exception;
@@ -183,6 +199,8 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
_timer = null;
}
+ _ssdp.MessageReceived -= _ssdp_MessageReceived;
+
try
{
// This is not a significant improvement
diff --git a/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs b/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs
index 106e3c76b..e134670e3 100644
--- a/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs
+++ b/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs
@@ -8,7 +8,6 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.FileOrganization;
using MediaBrowser.Model.Logging;
-using MediaBrowser.Naming.IO;
using MediaBrowser.Server.Implementations.Library;
using MediaBrowser.Server.Implementations.Logging;
using System;
@@ -60,7 +59,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
var namingOptions = ((LibraryManager) _libraryManager).GetNamingOptions();
var resolver = new Naming.TV.EpisodeResolver(namingOptions, new PatternsLogger());
- var episodeInfo = resolver.Resolve(path, FileInfoType.File) ??
+ var episodeInfo = resolver.Resolve(path, false) ??
new Naming.TV.EpisodeInfo();
var seriesName = episodeInfo.SeriesName;
diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
index dcdf2aa7d..bafbecbc5 100644
--- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
+++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
@@ -1,4 +1,5 @@
-using MediaBrowser.Common.Extensions;
+using Interfaces.IO;
+using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Progress;
using MediaBrowser.Common.ScheduledTasks;
@@ -17,7 +18,6 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Naming.Audio;
using MediaBrowser.Naming.Common;
-using MediaBrowser.Naming.IO;
using MediaBrowser.Naming.TV;
using MediaBrowser.Naming.Video;
using MediaBrowser.Server.Implementations.Library.Validators;
@@ -1767,14 +1767,13 @@ namespace MediaBrowser.Server.Implementations.Library
var resolver = new EpisodeResolver(GetNamingOptions(),
new PatternsLogger());
- var fileType = episode.VideoType == VideoType.BluRay || episode.VideoType == VideoType.Dvd || episode.VideoType == VideoType.HdDvd ?
- FileInfoType.Directory :
- FileInfoType.File;
+ var isFolder = episode.VideoType == VideoType.BluRay || episode.VideoType == VideoType.Dvd ||
+ episode.VideoType == VideoType.HdDvd;
var locationType = episode.LocationType;
var episodeInfo = locationType == LocationType.FileSystem || locationType == LocationType.Offline ?
- resolver.Resolve(episode.Path, fileType) :
+ resolver.Resolve(episode.Path, isFolder) :
new Naming.TV.EpisodeInfo();
if (episodeInfo == null)
@@ -1928,10 +1927,10 @@ namespace MediaBrowser.Server.Implementations.Library
var videoListResolver = new VideoListResolver(GetNamingOptions(), new PatternsLogger());
- var videos = videoListResolver.Resolve(fileSystemChildren.Select(i => new PortableFileInfo
+ var videos = videoListResolver.Resolve(fileSystemChildren.Select(i => new FileMetadata
{
- FullName = i.FullName,
- Type = GetFileType(i)
+ Id = i.FullName,
+ IsFolder = ((i.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
}).ToList());
@@ -1962,16 +1961,6 @@ namespace MediaBrowser.Server.Implementations.Library
}).OrderBy(i => i.Path).ToList();
}
- private FileInfoType GetFileType(FileSystemInfo info)
- {
- if ((info.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
- {
- return FileInfoType.Directory;
- }
-
- return FileInfoType.File;
- }
-
public IEnumerable