PlayTo profiles added as xmlfile

This commit is contained in:
7illusions 2014-03-13 15:54:11 +01:00
parent b7bcc24506
commit e985e81e84
7 changed files with 121 additions and 50 deletions

View File

@ -48,6 +48,6 @@
/// <value> /// <value>
/// The transcode settings. /// The transcode settings.
/// </value> /// </value>
public TranscodeSettings[] TranscodeSettings { get; set; } public TranscodeSetting[] TranscodeSettings { get; set; }
} }
} }

View File

@ -1,26 +1,31 @@
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 public class PlayToConfiguration
{ {
private static readonly string[] _supportedStaticFormats = { "mp3", "flac", "m4a", "wma", "avi", "mp4", "mkv", "ts" }; [XmlIgnore]
public static string[] SupportedStaticFormats public static PlayToConfiguration Instance
{
get;
private set;
}
[XmlIgnore]
public string[] SupportedStaticFormats
{ {
get get
{ {
return _supportedStaticFormats; return new[] { "mp3", "flac", "m4a", "wma", "avi", "mp4", "mkv" };
} }
} }
private static readonly DlnaProfile[] _profiles = GetDefaultProfiles(); public DlnaProfile[] Profiles
public static DlnaProfile[] Profiles { get; set; }
{
get
{
return _profiles;
}
}
private static DlnaProfile[] GetDefaultProfiles() public static DlnaProfile[] GetDefaultProfiles()
{ {
var profile0 = new DlnaProfile var profile0 = new DlnaProfile
{ {
@ -31,9 +36,9 @@
ModelName = "Samsung DTV DMR", ModelName = "Samsung DTV DMR",
TranscodeSettings = new[] TranscodeSettings = new[]
{ {
new TranscodeSettings {Container = "mkv", MimeType = "x-mkv"}, new TranscodeSetting {Container = "mkv", MimeType = "x-mkv"},
new TranscodeSettings {Container = "flac", TargetContainer = "mp3"}, new TranscodeSetting {Container = "flac", TargetContainer = "mp3"},
new TranscodeSettings {Container = "m4a", TargetContainer = "mp3"} new TranscodeSetting {Container = "m4a", TargetContainer = "mp3"}
} }
}; };
@ -45,9 +50,9 @@
ModelNumber = @"(1\.0)|(AllShare1\.0)", ModelNumber = @"(1\.0)|(AllShare1\.0)",
TranscodeSettings = new[] TranscodeSettings = new[]
{ {
new TranscodeSettings {Container = "mkv", MimeType = "x-mkv"}, new TranscodeSetting {Container = "mkv", MimeType = "x-mkv"},
new TranscodeSettings {Container = "flac", TargetContainer = "mp3"}, new TranscodeSetting {Container = "flac", TargetContainer = "mp3"},
new TranscodeSettings {Container = "m4a", TargetContainer = "mp3"} new TranscodeSetting {Container = "m4a", TargetContainer = "mp3"}
} }
}; };
@ -59,9 +64,9 @@
ModelNumber = @"(1\.0)|(AllShare1\.0)", ModelNumber = @"(1\.0)|(AllShare1\.0)",
TranscodeSettings = new[] TranscodeSettings = new[]
{ {
new TranscodeSettings {Container = "mkv", MimeType = "x-mkv"}, new TranscodeSetting {Container = "mkv", MimeType = "x-mkv"},
new TranscodeSettings {Container = "flac", TargetContainer = "mp3"}, new TranscodeSetting {Container = "flac", TargetContainer = "mp3"},
new TranscodeSettings {Container = "m4a", TargetContainer = "mp3"} new TranscodeSetting {Container = "m4a", TargetContainer = "mp3"}
} }
}; };
@ -72,9 +77,9 @@
ModelName = "Xbox 360", ModelName = "Xbox 360",
TranscodeSettings = new[] TranscodeSettings = new[]
{ {
new TranscodeSettings {Container = "mkv", TargetContainer = "ts"}, new TranscodeSetting {Container = "mkv", TargetContainer = "ts"},
new TranscodeSettings {Container = "flac", TargetContainer = "mp3"}, new TranscodeSetting {Container = "flac", TargetContainer = "mp3"},
new TranscodeSettings {Container = "m4a", TargetContainer = "mp3"} new TranscodeSetting {Container = "m4a", TargetContainer = "mp3"}
} }
}; };
@ -86,9 +91,9 @@
FriendlyName = "Xbox-SystemOS", FriendlyName = "Xbox-SystemOS",
TranscodeSettings = new[] TranscodeSettings = new[]
{ {
new TranscodeSettings {Container = "mkv", TargetContainer = "ts"}, new TranscodeSetting {Container = "mkv", TargetContainer = "ts"},
new TranscodeSettings {Container = "flac", TargetContainer = "mp3"}, new TranscodeSetting {Container = "flac", TargetContainer = "mp3"},
new TranscodeSettings {Container = "m4a", TargetContainer = "mp3"} new TranscodeSetting {Container = "m4a", TargetContainer = "mp3"}
} }
}; };
@ -97,7 +102,7 @@
Name = "Sony Bravia TV (2012)", Name = "Sony Bravia TV (2012)",
ClientType = "TV", ClientType = "TV",
FriendlyName = @"BRAVIA KDL-\d{2}[A-Z]X\d5(\d|G).*", 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 //WDTV does not need any transcoding of the formats we support statically
@ -106,7 +111,7 @@
Name = "WDTV Live [Profile]", Name = "WDTV Live [Profile]",
ClientType = "DLNA", ClientType = "DLNA",
ModelName = "WD TV HD Live", ModelName = "WD TV HD Live",
TranscodeSettings = new TranscodeSettings[] { } TranscodeSettings = new TranscodeSetting[] { }
}; };
var profile7 = new DlnaProfile var profile7 = new DlnaProfile
@ -115,7 +120,7 @@
Name = "Linksys DMA2100 [Profile]", Name = "Linksys DMA2100 [Profile]",
ClientType = "DLNA", ClientType = "DLNA",
ModelName = "DMA2100us", ModelName = "DMA2100us",
TranscodeSettings = new TranscodeSettings[] { } TranscodeSettings = new TranscodeSetting[] { }
}; };
return new[] return new[]
@ -130,5 +135,62 @@
profile7 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;
}
} }
} }

View File

@ -1,9 +1,10 @@
using System; using System;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace MediaBrowser.Dlna.PlayTo.Configuration namespace MediaBrowser.Dlna.PlayTo.Configuration
{ {
public class TranscodeSettings public class TranscodeSetting
{ {
/// <summary> /// <summary>
/// Gets or sets the container. /// Gets or sets the container.
@ -32,14 +33,14 @@ namespace MediaBrowser.Dlna.PlayTo.Configuration
/// <summary> /// <summary>
/// The default transcoding settings /// The default transcoding settings
/// </summary> /// </summary>
private static readonly TranscodeSettings[] DefaultTranscodingSettings = private static readonly TranscodeSetting[] DefaultTranscodingSettings =
{ {
new TranscodeSettings { Container = "mkv", TargetContainer = "ts" }, new TranscodeSetting { Container = "mkv", TargetContainer = "ts" },
new TranscodeSettings { Container = "flac", TargetContainer = "mp3" }, new TranscodeSetting { Container = "flac", TargetContainer = "mp3" },
new TranscodeSettings { Container = "m4a", TargetContainer = "mp3" } new TranscodeSetting { Container = "m4a", TargetContainer = "mp3" }
}; };
public static TranscodeSettings[] GetDefaultTranscodingSettings() public static TranscodeSetting[] GetDefaultTranscodingSettings()
{ {
return DefaultTranscodingSettings; return DefaultTranscodingSettings;
} }
@ -49,9 +50,9 @@ namespace MediaBrowser.Dlna.PlayTo.Configuration
/// </summary> /// </summary>
/// <param name="deviceProperties">The device properties.</param> /// <param name="deviceProperties">The device properties.</param>
/// <returns>The TranscodeSettings for the device</returns> /// <returns>The TranscodeSettings for the device</returns>
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)) if (!string.IsNullOrEmpty(profile.FriendlyName))
{ {

View File

@ -21,7 +21,7 @@ namespace MediaBrowser.Dlna.PlayTo
{ {
private Device _device; private Device _device;
private BaseItem _currentItem = null; private BaseItem _currentItem = null;
private TranscodeSettings[] _transcodeSettings; private TranscodeSetting[] _transcodeSettings;
private readonly SessionInfo _session; private readonly SessionInfo _session;
private readonly ISessionManager _sessionManager; private readonly ISessionManager _sessionManager;
private readonly IItemRepository _itemRepository; private readonly IItemRepository _itemRepository;
@ -56,7 +56,7 @@ namespace MediaBrowser.Dlna.PlayTo
_logger = logger; _logger = logger;
} }
public void Init(Device device, TranscodeSettings[] transcodeSettings) public void Init(Device device, TranscodeSetting[] transcodeSettings)
{ {
_transcodeSettings = transcodeSettings; _transcodeSettings = transcodeSettings;
_device = device; _device = device;

View File

@ -1,4 +1,5 @@
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Persistence;
@ -7,6 +8,7 @@ using MediaBrowser.Dlna.PlayTo.Configuration;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
@ -14,6 +16,7 @@ using System.Net.Sockets;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Serialization;
namespace MediaBrowser.Dlna.PlayTo namespace MediaBrowser.Dlna.PlayTo
{ {
@ -31,7 +34,7 @@ namespace MediaBrowser.Dlna.PlayTo
private readonly INetworkManager _networkManager; 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<string, DateTime>(); _locations = new ConcurrentDictionary<string, DateTime>();
_tokenSource = new CancellationTokenSource(); _tokenSource = new CancellationTokenSource();
@ -43,6 +46,10 @@ namespace MediaBrowser.Dlna.PlayTo
_libraryManager = libraryManager; _libraryManager = libraryManager;
_networkManager = networkManager; _networkManager = networkManager;
_userManager = userManager; _userManager = userManager;
var path = Path.Combine(config.CommonApplicationPaths.ConfigurationDirectoryPath, "DlnaProfiles.xml");
PlayToConfiguration.Load(path, logger);
} }
public async void Start() 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)) 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) var sessionInfo = await _sessionManager.LogSessionActivity(device.Properties.ClientType, device.Properties.Name, device.Properties.UUID, device.Properties.DisplayName, uri.OriginalString, null)
.ConfigureAwait(false); .ConfigureAwait(false);

View File

@ -36,6 +36,7 @@ namespace MediaBrowser.Dlna.PlayTo
public void Run() public void Run()
{ {
_config.ConfigurationUpdated += ConfigurationUpdated; _config.ConfigurationUpdated += ConfigurationUpdated;
ReloadPlayToManager(); ReloadPlayToManager();
} }
@ -65,7 +66,7 @@ namespace MediaBrowser.Dlna.PlayTo
{ {
try try
{ {
_manager = new PlayToManager(_logger, _sessionManager, _httpClient, _itemRepo, _libraryManager, _networkManager, _userManager); _manager = new PlayToManager(_logger, _config, _sessionManager, _httpClient, _itemRepo, _libraryManager, _networkManager, _userManager);
_manager.Start(); _manager.Start();
} }
catch (Exception ex) catch (Exception ex)

View File

@ -28,7 +28,7 @@ namespace MediaBrowser.Dlna.PlayTo
public long StartPositionTicks { get; set; } 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(); var playlistItem = new PlaylistItem();
@ -49,7 +49,7 @@ namespace MediaBrowser.Dlna.PlayTo
//Check the DlnaProfile associated with the renderer //Check the DlnaProfile associated with the renderer
if (profileTranscodings != null) if (profileTranscodings != null)
{ {
foreach (TranscodeSettings transcodeSetting in profileTranscodings) foreach (TranscodeSetting transcodeSetting in profileTranscodings)
{ {
if (string.IsNullOrWhiteSpace(transcodeSetting.Container)) if (string.IsNullOrWhiteSpace(transcodeSetting.Container))
continue; continue;
@ -76,7 +76,7 @@ namespace MediaBrowser.Dlna.PlayTo
{ {
//Check to see if we support serving the format statically //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)) if (path.EndsWith(supported))
{ {
@ -91,7 +91,7 @@ namespace MediaBrowser.Dlna.PlayTo
} }
else else
{ {
foreach (string supported in PlayToConfiguration.SupportedStaticFormats) foreach (string supported in PlayToConfiguration.Instance.SupportedStaticFormats)
{ {
if (path.EndsWith(supported)) if (path.EndsWith(supported))
{ {