aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Dlna/DlnaManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Dlna/DlnaManager.cs')
-rw-r--r--MediaBrowser.Dlna/DlnaManager.cs136
1 files changed, 70 insertions, 66 deletions
diff --git a/MediaBrowser.Dlna/DlnaManager.cs b/MediaBrowser.Dlna/DlnaManager.cs
index b4127a91f1..aae157e7a8 100644
--- a/MediaBrowser.Dlna/DlnaManager.cs
+++ b/MediaBrowser.Dlna/DlnaManager.cs
@@ -29,7 +29,7 @@ namespace MediaBrowser.Dlna
private readonly IJsonSerializer _jsonSerializer;
private readonly IServerApplicationHost _appHost;
- private readonly Dictionary<string, DeviceProfile> _profiles = new Dictionary<string, DeviceProfile>(StringComparer.Ordinal);
+ private readonly Dictionary<string, Tuple<InternalProfileInfo, DeviceProfile>> _profiles = new Dictionary<string, Tuple<InternalProfileInfo, DeviceProfile>>(StringComparer.Ordinal);
public DlnaManager(IXmlSerializer xmlSerializer,
IFileSystem fileSystem,
@@ -45,50 +45,45 @@ namespace MediaBrowser.Dlna
_appHost = appHost;
}
- public IEnumerable<DeviceProfile> GetProfiles()
+ public void InitProfiles()
{
- ExtractProfilesIfNeeded();
+ try
+ {
+ ExtractSystemProfiles();
+ LoadProfiles();
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error extracting DLNA profiles.", ex);
+ }
+ }
+ private void LoadProfiles()
+ {
var list = GetProfiles(UserProfilesPath, DeviceProfileType.User)
.OrderBy(i => i.Name)
.ToList();
list.AddRange(GetProfiles(SystemProfilesPath, DeviceProfileType.System)
.OrderBy(i => i.Name));
-
- return list;
}
- private bool _extracted;
- private readonly object _syncLock = new object();
- private void ExtractProfilesIfNeeded()
+ public IEnumerable<DeviceProfile> GetProfiles()
{
- if (!_extracted)
+ lock (_profiles)
{
- lock (_syncLock)
- {
- if (!_extracted)
- {
- try
- {
- ExtractSystemProfiles();
- }
- catch (Exception ex)
- {
- _logger.ErrorException("Error extracting DLNA profiles.", ex);
- }
-
- _extracted = true;
- }
-
- }
+ var list = _profiles.Values.ToList();
+ return list
+ .OrderBy(i => i.Item1.Info.Type == DeviceProfileType.User ? 0 : 1)
+ .ThenBy(i => i.Item1.Info.Name)
+ .Select(i => i.Item2)
+ .ToList();
}
+
}
public DeviceProfile GetDefaultProfile()
{
- ExtractProfilesIfNeeded();
-
return new DefaultProfile();
}
@@ -211,7 +206,6 @@ namespace MediaBrowser.Dlna
throw new ArgumentNullException("headers");
}
- //_logger.Debug("GetProfile. Headers: " + _jsonSerializer.SerializeToString(headers));
// Convert to case insensitive
headers = new Dictionary<string, string>(headers, StringComparer.OrdinalIgnoreCase);
@@ -223,16 +217,12 @@ namespace MediaBrowser.Dlna
}
else
{
- string userAgent = null;
- headers.TryGetValue("User-Agent", out userAgent);
-
- var msg = "No matching device profile via headers found. The default will be used. ";
- if (!string.IsNullOrEmpty(userAgent))
+ var msg = new StringBuilder();
+ foreach (var header in headers)
{
- msg += "User-agent: " + userAgent + ". ";
+ msg.AppendLine(header.Key + ": " + header.Value);
}
-
- _logger.Debug(msg);
+ _logger.LogMultiline("No matching device profile found. The default will need to be used.", LogSeverity.Info, msg);
}
return profile;
@@ -258,8 +248,7 @@ namespace MediaBrowser.Dlna
//_logger.Debug("IsMatch-Substring value: {0} testValue: {1} isMatch: {2}", value, header.Value, isMatch);
return isMatch;
case HeaderMatchType.Regex:
- // Reports of IgnoreCase not working on linux so try it a couple different ways.
- return Regex.IsMatch(value, header.Value, RegexOptions.IgnoreCase) || Regex.IsMatch(value.ToUpper(), header.Value.ToUpper(), RegexOptions.IgnoreCase);
+ return Regex.IsMatch(value, header.Value, RegexOptions.IgnoreCase);
default:
throw new ArgumentException("Unrecognized HeaderMatchType");
}
@@ -304,20 +293,20 @@ namespace MediaBrowser.Dlna
{
lock (_profiles)
{
- DeviceProfile profile;
- if (_profiles.TryGetValue(path, out profile))
+ Tuple<InternalProfileInfo, DeviceProfile> profileTuple;
+ if (_profiles.TryGetValue(path, out profileTuple))
{
- return profile;
+ return profileTuple.Item2;
}
try
{
- profile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path);
+ var profile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path);
profile.Id = path.ToLower().GetMD5().ToString("N");
profile.ProfileType = type;
- _profiles[path] = profile;
+ _profiles[path] = new Tuple<InternalProfileInfo, DeviceProfile>(GetInternalProfileInfo(_fileSystem.GetFileInfo(path), type), profile);
return profile;
}
@@ -344,12 +333,14 @@ namespace MediaBrowser.Dlna
private IEnumerable<InternalProfileInfo> GetProfileInfosInternal()
{
- ExtractProfilesIfNeeded();
-
- return GetProfileInfos(UserProfilesPath, DeviceProfileType.User)
- .Concat(GetProfileInfos(SystemProfilesPath, DeviceProfileType.System))
- .OrderBy(i => i.Info.Type == DeviceProfileType.User ? 0 : 1)
- .ThenBy(i => i.Info.Name);
+ lock (_profiles)
+ {
+ var list = _profiles.Values.ToList();
+ return list
+ .Select(i => i.Item1)
+ .OrderBy(i => i.Info.Type == DeviceProfileType.User ? 0 : 1)
+ .ThenBy(i => i.Info.Name);
+ }
}
public IEnumerable<DeviceProfileInfo> GetProfileInfos()
@@ -363,17 +354,7 @@ namespace MediaBrowser.Dlna
{
return _fileSystem.GetFiles(path)
.Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase))
- .Select(i => new InternalProfileInfo
- {
- Path = i.FullName,
-
- Info = new DeviceProfileInfo
- {
- Id = i.FullName.ToLower().GetMD5().ToString("N"),
- Name = _fileSystem.GetFileNameWithoutExtension(i),
- Type = type
- }
- })
+ .Select(i => GetInternalProfileInfo(i, type))
.ToList();
}
catch (DirectoryNotFoundException)
@@ -382,6 +363,21 @@ namespace MediaBrowser.Dlna
}
}
+ private InternalProfileInfo GetInternalProfileInfo(FileSystemMetadata file, DeviceProfileType type)
+ {
+ return new InternalProfileInfo
+ {
+ Path = file.FullName,
+
+ Info = new DeviceProfileInfo
+ {
+ Id = file.FullName.ToLower().GetMD5().ToString("N"),
+ Name = _fileSystem.GetFileNameWithoutExtension(file),
+ Type = type
+ }
+ };
+ }
+
private void ExtractSystemProfiles()
{
var assembly = GetType().Assembly;
@@ -427,6 +423,11 @@ namespace MediaBrowser.Dlna
}
_fileSystem.DeleteFile(info.Path);
+
+ lock (_profiles)
+ {
+ _profiles.Remove(info.Path);
+ }
}
public void CreateProfile(DeviceProfile profile)
@@ -441,7 +442,7 @@ namespace MediaBrowser.Dlna
var newFilename = _fileSystem.GetValidFilename(profile.Name) + ".xml";
var path = Path.Combine(UserProfilesPath, newFilename);
- SaveProfile(profile, path);
+ SaveProfile(profile, path, DeviceProfileType.User);
}
public void UpdateProfile(DeviceProfile profile)
@@ -468,14 +469,14 @@ namespace MediaBrowser.Dlna
_fileSystem.DeleteFile(current.Path);
}
- SaveProfile(profile, path);
+ SaveProfile(profile, path, DeviceProfileType.User);
}
- private void SaveProfile(DeviceProfile profile, string path)
+ private void SaveProfile(DeviceProfile profile, string path, DeviceProfileType type)
{
lock (_profiles)
{
- _profiles[path] = profile;
+ _profiles[path] = new Tuple<InternalProfileInfo, DeviceProfile>(GetInternalProfileInfo(_fileSystem.GetFileInfo(path), type), profile);
}
_xmlSerializer.SerializeToFile(profile, path);
}
@@ -560,7 +561,10 @@ namespace MediaBrowser.Dlna
new SonyBravia2012Profile(),
new SonyBravia2013Profile(),
new SonyBravia2014Profile(),
- new SonyBlurayPlayer2013Profile(),
+ new SonyBlurayPlayer2013(),
+ new SonyBlurayPlayer2014(),
+ new SonyBlurayPlayer2015(),
+ new SonyBlurayPlayer2016(),
new SonyBlurayPlayerProfile(),
new PanasonicVieraProfile(),
new WdtvLiveProfile(),