diff --git a/MediaBrowser.Dlna/PlayTo/Configuration/DlnaProfile.cs b/MediaBrowser.Dlna/PlayTo/Configuration/DlnaProfile.cs
index e75cea5a9..70bda7238 100644
--- a/MediaBrowser.Dlna/PlayTo/Configuration/DlnaProfile.cs
+++ b/MediaBrowser.Dlna/PlayTo/Configuration/DlnaProfile.cs
@@ -48,6 +48,6 @@
///
/// The transcode settings.
///
- public TranscodeSettings[] TranscodeSettings { get; set; }
+ public TranscodeSetting[] TranscodeSettings { get; set; }
}
}
diff --git a/MediaBrowser.Dlna/PlayTo/Configuration/PlayToConfiguration.cs b/MediaBrowser.Dlna/PlayTo/Configuration/PlayToConfiguration.cs
index d3fcb24ad..927d8805b 100644
--- a/MediaBrowser.Dlna/PlayTo/Configuration/PlayToConfiguration.cs
+++ b/MediaBrowser.Dlna/PlayTo/Configuration/PlayToConfiguration.cs
@@ -1,9 +1,22 @@
-namespace MediaBrowser.Dlna.PlayTo.Configuration
+using MediaBrowser.Model.Logging;
+using System;
+using System.IO;
+using System.Xml.Serialization;
+namespace MediaBrowser.Dlna.PlayTo.Configuration
{
public class PlayToConfiguration
{
- private static readonly string[] _supportedStaticFormats = { "mp3", "flac", "m4a", "wma", "avi", "mp4", "mkv", "ts" };
- public static string[] SupportedStaticFormats
+ [XmlIgnore]
+ public static PlayToConfiguration Instance
+ {
+ get;
+ private set;
+ }
+
+ private static readonly string[] _supportedStaticFormats = { "mp3", "flac", "m4a", "wma", "avi", "mp4", "mkv", "ts" };
+
+ [XmlIgnore]
+ public string[] SupportedStaticFormats
{
get
{
@@ -11,16 +24,10 @@
}
}
- private static readonly DlnaProfile[] _profiles = GetDefaultProfiles();
- public static DlnaProfile[] Profiles
- {
- get
- {
- return _profiles;
- }
- }
+ public DlnaProfile[] Profiles
+ { get; set; }
- private static DlnaProfile[] GetDefaultProfiles()
+ public static DlnaProfile[] GetDefaultProfiles()
{
var profile0 = new DlnaProfile
{
@@ -31,9 +38,9 @@
ModelName = "Samsung DTV DMR",
TranscodeSettings = new[]
{
- new TranscodeSettings {Container = "mkv", MimeType = "x-mkv"},
- new TranscodeSettings {Container = "flac", TargetContainer = "mp3"},
- new TranscodeSettings {Container = "m4a", TargetContainer = "mp3"}
+ new TranscodeSetting {Container = "mkv", MimeType = "x-mkv"},
+ new TranscodeSetting {Container = "flac", TargetContainer = "mp3"},
+ new TranscodeSetting {Container = "m4a", TargetContainer = "mp3"}
}
};
@@ -45,9 +52,9 @@
ModelNumber = @"(1\.0)|(AllShare1\.0)",
TranscodeSettings = new[]
{
- new TranscodeSettings {Container = "mkv", MimeType = "x-mkv"},
- new TranscodeSettings {Container = "flac", TargetContainer = "mp3"},
- new TranscodeSettings {Container = "m4a", TargetContainer = "mp3"}
+ new TranscodeSetting {Container = "mkv", MimeType = "x-mkv"},
+ new TranscodeSetting {Container = "flac", TargetContainer = "mp3"},
+ new TranscodeSetting {Container = "m4a", TargetContainer = "mp3"}
}
};
@@ -59,9 +66,9 @@
ModelNumber = @"(1\.0)|(AllShare1\.0)",
TranscodeSettings = new[]
{
- new TranscodeSettings {Container = "mkv", MimeType = "x-mkv"},
- new TranscodeSettings {Container = "flac", TargetContainer = "mp3"},
- new TranscodeSettings {Container = "m4a", TargetContainer = "mp3"}
+ new TranscodeSetting {Container = "mkv", MimeType = "x-mkv"},
+ new TranscodeSetting {Container = "flac", TargetContainer = "mp3"},
+ new TranscodeSetting {Container = "m4a", TargetContainer = "mp3"}
}
};
@@ -72,9 +79,9 @@
ModelName = "Xbox 360",
TranscodeSettings = new[]
{
- new TranscodeSettings {Container = "mkv", TargetContainer = "ts"},
- new TranscodeSettings {Container = "flac", TargetContainer = "mp3"},
- new TranscodeSettings {Container = "m4a", TargetContainer = "mp3"}
+ new TranscodeSetting {Container = "mkv", TargetContainer = "ts"},
+ new TranscodeSetting {Container = "flac", TargetContainer = "mp3"},
+ new TranscodeSetting {Container = "m4a", TargetContainer = "mp3"}
}
};
@@ -86,9 +93,9 @@
FriendlyName = "Xbox-SystemOS",
TranscodeSettings = new[]
{
- new TranscodeSettings {Container = "mkv", TargetContainer = "ts"},
- new TranscodeSettings {Container = "flac", TargetContainer = "mp3"},
- new TranscodeSettings {Container = "m4a", TargetContainer = "mp3"}
+ new TranscodeSetting {Container = "mkv", TargetContainer = "ts"},
+ new TranscodeSetting {Container = "flac", TargetContainer = "mp3"},
+ new TranscodeSetting {Container = "m4a", TargetContainer = "mp3"}
}
};
@@ -97,7 +104,7 @@
Name = "Sony Bravia TV (2012)",
ClientType = "TV",
FriendlyName = @"BRAVIA KDL-\d{2}[A-Z]X\d5(\d|G).*",
- TranscodeSettings = TranscodeSettings.GetDefaultTranscodingSettings()
+ TranscodeSettings = TranscodeSetting.GetDefaultTranscodingSettings()
};
//WDTV does not need any transcoding of the formats we support statically
@@ -106,7 +113,7 @@
Name = "WDTV Live [Profile]",
ClientType = "DLNA",
ModelName = "WD TV HD Live",
- TranscodeSettings = new TranscodeSettings[] { }
+ TranscodeSettings = new TranscodeSetting[] { }
};
var profile7 = new DlnaProfile
@@ -115,7 +122,7 @@
Name = "Linksys DMA2100 [Profile]",
ClientType = "DLNA",
ModelName = "DMA2100us",
- TranscodeSettings = new TranscodeSettings[] { }
+ TranscodeSettings = new TranscodeSetting[] { }
};
return new[]
@@ -130,5 +137,62 @@
profile7
};
}
+
+ public static void Load(string path, ILogger logger)
+ {
+ if (!File.Exists(path))
+ {
+ Instance = CreateNewSettingsFile(path, logger);
+
+ }
+ else
+ {
+ try
+ {
+ XmlSerializer deserializer = new XmlSerializer(typeof(PlayToConfiguration));
+ using (var textReader = new StreamReader(path))
+ {
+ var configuration = (PlayToConfiguration)deserializer.Deserialize(textReader);
+ Instance = configuration;
+ textReader.Close();
+ }
+ }
+ catch (Exception e)
+ {
+ // Something went wrong with the loading of the file
+ // Maybe a user created a faulty config?
+ // Delete the file and use default settings
+ logger.ErrorException("Error loading PlayTo configuration", e);
+ Instance = CreateNewSettingsFile(path, logger);
+ }
+ }
+ }
+
+ private static PlayToConfiguration CreateNewSettingsFile(string path, ILogger logger)
+ {
+ var defaultConfig = new PlayToConfiguration();
+ defaultConfig.Profiles = PlayToConfiguration.GetDefaultProfiles();
+
+ try
+ {
+ if (File.Exists(path))
+ File.Delete(path);
+
+ XmlSerializer serializer = new XmlSerializer(typeof(PlayToConfiguration));
+
+ using (var fileStream = new StreamWriter(path))
+ {
+ serializer.Serialize(fileStream, defaultConfig);
+ fileStream.Close();
+ }
+ }
+ catch(Exception e)
+ {
+ //Something went wrong deleting or creating the file, Log and continue with the default profile unsaved
+ logger.ErrorException("Error creating default PlayTo configuration", e);
+ }
+ return defaultConfig;
+ }
+
}
}
diff --git a/MediaBrowser.Dlna/PlayTo/Configuration/TranscodeSetting.cs b/MediaBrowser.Dlna/PlayTo/Configuration/TranscodeSetting.cs
index 4713dc385..83ff92154 100644
--- a/MediaBrowser.Dlna/PlayTo/Configuration/TranscodeSetting.cs
+++ b/MediaBrowser.Dlna/PlayTo/Configuration/TranscodeSetting.cs
@@ -1,9 +1,10 @@
using System;
using System.Text.RegularExpressions;
+
namespace MediaBrowser.Dlna.PlayTo.Configuration
{
- public class TranscodeSettings
+ public class TranscodeSetting
{
///
/// Gets or sets the container.
@@ -32,14 +33,14 @@ namespace MediaBrowser.Dlna.PlayTo.Configuration
///
/// The default transcoding settings
///
- private static readonly TranscodeSettings[] DefaultTranscodingSettings =
+ private static readonly TranscodeSetting[] DefaultTranscodingSettings =
{
- new TranscodeSettings { Container = "mkv", TargetContainer = "ts" },
- new TranscodeSettings { Container = "flac", TargetContainer = "mp3" },
- new TranscodeSettings { Container = "m4a", TargetContainer = "mp3" }
+ new TranscodeSetting { Container = "mkv", TargetContainer = "ts" },
+ new TranscodeSetting { Container = "flac", TargetContainer = "mp3" },
+ new TranscodeSetting { Container = "m4a", TargetContainer = "mp3" }
};
- public static TranscodeSettings[] GetDefaultTranscodingSettings()
+ public static TranscodeSetting[] GetDefaultTranscodingSettings()
{
return DefaultTranscodingSettings;
}
@@ -49,9 +50,9 @@ namespace MediaBrowser.Dlna.PlayTo.Configuration
///
/// The device properties.
/// The TranscodeSettings for the device
- public static TranscodeSettings[] GetProfileSettings(DeviceProperties deviceProperties)
+ public static TranscodeSetting[] GetProfileSettings(DeviceProperties deviceProperties)
{
- foreach (var profile in PlayToConfiguration.Profiles)
+ foreach (var profile in PlayToConfiguration.Instance.Profiles)
{
if (!string.IsNullOrEmpty(profile.FriendlyName))
{
diff --git a/MediaBrowser.Dlna/PlayTo/DlnaController.cs b/MediaBrowser.Dlna/PlayTo/DlnaController.cs
index 2be82b985..8892a03f1 100644
--- a/MediaBrowser.Dlna/PlayTo/DlnaController.cs
+++ b/MediaBrowser.Dlna/PlayTo/DlnaController.cs
@@ -21,7 +21,7 @@ namespace MediaBrowser.Dlna.PlayTo
{
private Device _device;
private BaseItem _currentItem = null;
- private TranscodeSettings[] _transcodeSettings;
+ private TranscodeSetting[] _transcodeSettings;
private readonly SessionInfo _session;
private readonly ISessionManager _sessionManager;
private readonly IItemRepository _itemRepository;
@@ -56,7 +56,7 @@ namespace MediaBrowser.Dlna.PlayTo
_logger = logger;
}
- public void Init(Device device, TranscodeSettings[] transcodeSettings)
+ public void Init(Device device, TranscodeSetting[] transcodeSettings)
{
_transcodeSettings = transcodeSettings;
_device = device;
diff --git a/MediaBrowser.Dlna/PlayTo/PlayToManager.cs b/MediaBrowser.Dlna/PlayTo/PlayToManager.cs
index 59827b810..dfbbb4f80 100644
--- a/MediaBrowser.Dlna/PlayTo/PlayToManager.cs
+++ b/MediaBrowser.Dlna/PlayTo/PlayToManager.cs
@@ -1,4 +1,5 @@
using MediaBrowser.Common.Net;
+using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
@@ -7,6 +8,7 @@ using MediaBrowser.Dlna.PlayTo.Configuration;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Concurrent;
+using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
@@ -14,6 +16,7 @@ using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
+using System.Xml.Serialization;
namespace MediaBrowser.Dlna.PlayTo
{
@@ -29,9 +32,9 @@ namespace MediaBrowser.Dlna.PlayTo
private readonly IItemRepository _itemRepository;
private readonly ILibraryManager _libraryManager;
private readonly INetworkManager _networkManager;
- private readonly IUserManager _userManager;
+ private readonly IUserManager _userManager;
- public PlayToManager(ILogger logger, ISessionManager sessionManager, IHttpClient httpClient, IItemRepository itemRepository, ILibraryManager libraryManager, INetworkManager networkManager, IUserManager userManager)
+ public PlayToManager(ILogger logger,IServerConfigurationManager config, ISessionManager sessionManager, IHttpClient httpClient, IItemRepository itemRepository, ILibraryManager libraryManager, INetworkManager networkManager, IUserManager userManager)
{
_locations = new ConcurrentDictionary();
_tokenSource = new CancellationTokenSource();
@@ -43,6 +46,10 @@ namespace MediaBrowser.Dlna.PlayTo
_libraryManager = libraryManager;
_networkManager = networkManager;
_userManager = userManager;
+
+ var path = Path.Combine(config.CommonApplicationPaths.ConfigurationDirectoryPath, "DlnaProfiles.xml");
+
+ PlayToConfiguration.Load(path, logger);
}
public async void Start()
@@ -214,7 +221,7 @@ namespace MediaBrowser.Dlna.PlayTo
if (device != null && device.RendererCommands != null && !_sessionManager.Sessions.Any(s => string.Equals(s.DeviceId, device.Properties.UUID) && s.IsActive))
{
- var transcodeProfiles = TranscodeSettings.GetProfileSettings(device.Properties);
+ var transcodeProfiles = TranscodeSetting.GetProfileSettings(device.Properties);
var sessionInfo = await _sessionManager.LogSessionActivity(device.Properties.ClientType, device.Properties.Name, device.Properties.UUID, device.Properties.DisplayName, uri.OriginalString, null)
.ConfigureAwait(false);
diff --git a/MediaBrowser.Dlna/PlayTo/PlayToServerEntryPoint.cs b/MediaBrowser.Dlna/PlayTo/PlayToServerEntryPoint.cs
index a6746cfc5..5b326d202 100644
--- a/MediaBrowser.Dlna/PlayTo/PlayToServerEntryPoint.cs
+++ b/MediaBrowser.Dlna/PlayTo/PlayToServerEntryPoint.cs
@@ -36,6 +36,7 @@ namespace MediaBrowser.Dlna.PlayTo
public void Run()
{
_config.ConfigurationUpdated += ConfigurationUpdated;
+
ReloadPlayToManager();
}
@@ -65,7 +66,7 @@ namespace MediaBrowser.Dlna.PlayTo
{
try
{
- _manager = new PlayToManager(_logger, _sessionManager, _httpClient, _itemRepo, _libraryManager, _networkManager, _userManager);
+ _manager = new PlayToManager(_logger, _config, _sessionManager, _httpClient, _itemRepo, _libraryManager, _networkManager, _userManager);
_manager.Start();
}
catch (Exception ex)
diff --git a/MediaBrowser.Dlna/PlayTo/PlaylistItem.cs b/MediaBrowser.Dlna/PlayTo/PlaylistItem.cs
index 6523eb9f5..99f56bfd7 100644
--- a/MediaBrowser.Dlna/PlayTo/PlaylistItem.cs
+++ b/MediaBrowser.Dlna/PlayTo/PlaylistItem.cs
@@ -28,7 +28,7 @@ namespace MediaBrowser.Dlna.PlayTo
public long StartPositionTicks { get; set; }
- public static PlaylistItem GetBasicConfig(BaseItem item, TranscodeSettings[] profileTranscodings)
+ public static PlaylistItem GetBasicConfig(BaseItem item, TranscodeSetting[] profileTranscodings)
{
var playlistItem = new PlaylistItem();
@@ -49,7 +49,7 @@ namespace MediaBrowser.Dlna.PlayTo
//Check the DlnaProfile associated with the renderer
if (profileTranscodings != null)
{
- foreach (TranscodeSettings transcodeSetting in profileTranscodings)
+ foreach (TranscodeSetting transcodeSetting in profileTranscodings)
{
if (string.IsNullOrWhiteSpace(transcodeSetting.Container))
continue;
@@ -76,7 +76,7 @@ namespace MediaBrowser.Dlna.PlayTo
{
//Check to see if we support serving the format statically
- foreach (string supported in PlayToConfiguration.SupportedStaticFormats)
+ foreach (string supported in PlayToConfiguration.Instance.SupportedStaticFormats)
{
if (path.EndsWith(supported))
{
@@ -91,7 +91,7 @@ namespace MediaBrowser.Dlna.PlayTo
}
else
{
- foreach (string supported in PlayToConfiguration.SupportedStaticFormats)
+ foreach (string supported in PlayToConfiguration.Instance.SupportedStaticFormats)
{
if (path.EndsWith(supported))
{