PlayTo profiles added as xmlfile
This commit is contained in:
parent
b7bcc24506
commit
e985e81e84
|
@ -48,6 +48,6 @@
|
|||
/// <value>
|
||||
/// The transcode settings.
|
||||
/// </value>
|
||||
public TranscodeSettings[] TranscodeSettings { get; set; }
|
||||
public TranscodeSetting[] TranscodeSettings { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public string[] SupportedStaticFormats
|
||||
{
|
||||
get
|
||||
{
|
||||
return _supportedStaticFormats;
|
||||
return new[] { "mp3", "flac", "m4a", "wma", "avi", "mp4", "mkv" };
|
||||
}
|
||||
}
|
||||
|
||||
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 +36,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 +50,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 +64,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 +77,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 +91,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 +102,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 +111,7 @@
|
|||
Name = "WDTV Live [Profile]",
|
||||
ClientType = "DLNA",
|
||||
ModelName = "WD TV HD Live",
|
||||
TranscodeSettings = new TranscodeSettings[] { }
|
||||
TranscodeSettings = new TranscodeSetting[] { }
|
||||
};
|
||||
|
||||
var profile7 = new DlnaProfile
|
||||
|
@ -115,7 +120,7 @@
|
|||
Name = "Linksys DMA2100 [Profile]",
|
||||
ClientType = "DLNA",
|
||||
ModelName = "DMA2100us",
|
||||
TranscodeSettings = new TranscodeSettings[] { }
|
||||
TranscodeSettings = new TranscodeSetting[] { }
|
||||
};
|
||||
|
||||
return new[]
|
||||
|
@ -130,5 +135,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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
|
||||
namespace MediaBrowser.Dlna.PlayTo.Configuration
|
||||
{
|
||||
public class TranscodeSettings
|
||||
public class TranscodeSetting
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the container.
|
||||
|
@ -32,14 +33,14 @@ namespace MediaBrowser.Dlna.PlayTo.Configuration
|
|||
/// <summary>
|
||||
/// The default transcoding settings
|
||||
/// </summary>
|
||||
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
|
|||
/// </summary>
|
||||
/// <param name="deviceProperties">The device properties.</param>
|
||||
/// <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))
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<string, DateTime>();
|
||||
_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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user