jellyfin/MediaBrowser.Dlna/DlnaManager.cs

128 lines
4.7 KiB
C#
Raw Normal View History

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