jellyfin/MediaBrowser.Dlna/DlnaManager.cs

133 lines
4.3 KiB
C#
Raw Normal View History

2014-03-15 04:14:07 +00:00
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Dlna;
2014-03-23 16:42:02 +00:00
using MediaBrowser.Dlna.Profiles;
2014-03-15 04:14:07 +00:00
using MediaBrowser.Model.Serialization;
2014-03-13 19:08:02 +00:00
using System.Collections.Generic;
2014-03-17 14:48:16 +00:00
using System.Linq;
2014-03-13 19:08:02 +00:00
using System.Text.RegularExpressions;
namespace MediaBrowser.Dlna
{
public class DlnaManager : IDlnaManager
{
2014-03-15 04:14:07 +00:00
private IApplicationPaths _appPaths;
private readonly IXmlSerializer _xmlSerializer;
private readonly IFileSystem _fileSystem;
2014-03-23 16:42:02 +00:00
private readonly IJsonSerializer _jsonSerializer;
2014-03-15 04:14:07 +00:00
2014-03-23 16:42:02 +00:00
public DlnaManager(IXmlSerializer xmlSerializer, IFileSystem fileSystem, IJsonSerializer jsonSerializer)
2014-03-15 04:14:07 +00:00
{
_xmlSerializer = xmlSerializer;
_fileSystem = fileSystem;
2014-03-23 16:42:02 +00:00
_jsonSerializer = jsonSerializer;
2014-03-15 04:14:07 +00:00
2014-03-23 16:42:02 +00:00
GetProfiles();
2014-03-15 04:14:07 +00:00
}
public IEnumerable<DeviceProfile> GetProfiles()
2014-03-13 19:08:02 +00:00
{
2014-03-15 04:14:07 +00:00
var list = new List<DeviceProfile>();
2014-03-13 21:36:19 +00:00
2014-03-23 17:18:24 +00:00
list.Add(new SamsungSmartTvProfile());
2014-03-23 16:42:02 +00:00
list.Add(new Xbox360Profile());
list.Add(new XboxOneProfile());
list.Add(new SonyBravia2010Profile());
list.Add(new SonyBravia2011Profile());
list.Add(new SonyBravia2012Profile());
list.Add(new SonyBravia2013Profile());
list.Add(new PanasonicVieraProfile());
list.Add(new WdtvLiveProfile());
list.Add(new DenonAvrProfile());
2014-03-23 17:18:24 +00:00
list.Add(new LinksysDMA2100Profile());
2014-03-15 04:14:07 +00:00
foreach (var item in list)
{
2014-03-23 16:42:02 +00:00
//_xmlSerializer.SerializeToFile(item, "d:\\" + _fileSystem.GetValidFilename(item.Name) + ".xml");
//_jsonSerializer.SerializeToFile(item, "d:\\" + _fileSystem.GetValidFilename(item.Name) + ".json");
2014-03-15 04:14:07 +00:00
}
2014-03-13 21:36:19 +00:00
return list;
2014-03-13 19:08:02 +00:00
}
2014-03-15 04:14:07 +00:00
public DeviceProfile GetDefaultProfile()
2014-03-13 19:08:02 +00:00
{
2014-03-23 16:42:02 +00:00
return new DefaultProfile();
2014-03-13 19:08:02 +00:00
}
2014-03-17 14:48:16 +00:00
public DeviceProfile GetProfile(DeviceIdentification deviceInfo)
{
2014-03-22 19:37:15 +00:00
return GetProfiles().FirstOrDefault(i => IsMatch(deviceInfo, i.Identification)) ??
2014-03-17 14:48:16 +00:00
GetDefaultProfile();
}
private bool IsMatch(DeviceIdentification deviceInfo, DeviceIdentification profileInfo)
2014-03-13 19:08:02 +00:00
{
2014-03-18 01:45:41 +00:00
if (!string.IsNullOrWhiteSpace(profileInfo.DeviceDescription))
{
if (!Regex.IsMatch(deviceInfo.DeviceDescription, profileInfo.DeviceDescription))
return false;
}
if (!string.IsNullOrWhiteSpace(profileInfo.FriendlyName))
2014-03-13 19:08:02 +00:00
{
2014-03-17 14:48:16 +00:00
if (!Regex.IsMatch(deviceInfo.FriendlyName, profileInfo.FriendlyName))
return false;
}
2014-03-13 19:08:02 +00:00
2014-03-18 01:45:41 +00:00
if (!string.IsNullOrWhiteSpace(profileInfo.Manufacturer))
2014-03-17 14:48:16 +00:00
{
2014-03-18 01:45:41 +00:00
if (!Regex.IsMatch(deviceInfo.Manufacturer, profileInfo.Manufacturer))
2014-03-17 14:48:16 +00:00
return false;
}
2014-03-13 19:08:02 +00:00
2014-03-18 01:45:41 +00:00
if (!string.IsNullOrWhiteSpace(profileInfo.ManufacturerUrl))
{
if (!Regex.IsMatch(deviceInfo.ManufacturerUrl, profileInfo.ManufacturerUrl))
return false;
}
if (!string.IsNullOrWhiteSpace(profileInfo.ModelDescription))
{
if (!Regex.IsMatch(deviceInfo.ModelDescription, profileInfo.ModelDescription))
return false;
}
if (!string.IsNullOrWhiteSpace(profileInfo.ModelName))
2014-03-17 14:48:16 +00:00
{
if (!Regex.IsMatch(deviceInfo.ModelName, profileInfo.ModelName))
return false;
}
2014-03-13 19:08:02 +00:00
2014-03-18 01:45:41 +00:00
if (!string.IsNullOrWhiteSpace(profileInfo.ModelNumber))
2014-03-17 14:48:16 +00:00
{
2014-03-18 01:45:41 +00:00
if (!Regex.IsMatch(deviceInfo.ModelNumber, profileInfo.ModelNumber))
2014-03-17 14:48:16 +00:00
return false;
}
2014-03-18 01:45:41 +00:00
if (!string.IsNullOrWhiteSpace(profileInfo.ModelUrl))
2014-03-17 14:48:16 +00:00
{
2014-03-18 01:45:41 +00:00
if (!Regex.IsMatch(deviceInfo.ModelUrl, profileInfo.ModelUrl))
2014-03-17 14:48:16 +00:00
return false;
}
2014-03-13 19:08:02 +00:00
2014-03-18 01:45:41 +00:00
if (!string.IsNullOrWhiteSpace(profileInfo.SerialNumber))
2014-03-17 14:48:16 +00:00
{
if (!Regex.IsMatch(deviceInfo.SerialNumber, profileInfo.SerialNumber))
return false;
2014-03-13 19:08:02 +00:00
}
2014-03-17 14:48:16 +00:00
return true;
2014-03-13 19:08:02 +00:00
}
}
2014-03-14 14:27:32 +00:00
}