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-23 21:46:13 +00: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 16:11:10 +00:00
|
|
|
|
|
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))
|
|
|
|
|
{
|
2014-03-24 07:47:23 +00:00
|
|
|
|
if (deviceInfo.DeviceDescription == null || !Regex.IsMatch(deviceInfo.DeviceDescription, profileInfo.DeviceDescription))
|
2014-03-18 01:45:41 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(profileInfo.FriendlyName))
|
2014-03-13 19:08:02 +00:00
|
|
|
|
{
|
2014-03-24 07:47:23 +00:00
|
|
|
|
if (deviceInfo.FriendlyName == null || !Regex.IsMatch(deviceInfo.FriendlyName, profileInfo.FriendlyName))
|
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.Manufacturer))
|
2014-03-17 14:48:16 +00:00
|
|
|
|
{
|
2014-03-24 07:47:23 +00:00
|
|
|
|
if (deviceInfo.Manufacturer == null || !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))
|
|
|
|
|
{
|
2014-03-24 07:47:23 +00:00
|
|
|
|
if (deviceInfo.ManufacturerUrl == null || !Regex.IsMatch(deviceInfo.ManufacturerUrl, profileInfo.ManufacturerUrl))
|
2014-03-18 01:45:41 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(profileInfo.ModelDescription))
|
|
|
|
|
{
|
2014-03-24 07:47:23 +00:00
|
|
|
|
if (deviceInfo.ModelDescription == null || !Regex.IsMatch(deviceInfo.ModelDescription, profileInfo.ModelDescription))
|
2014-03-18 01:45:41 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(profileInfo.ModelName))
|
2014-03-17 14:48:16 +00:00
|
|
|
|
{
|
2014-03-24 07:47:23 +00:00
|
|
|
|
if (deviceInfo.ModelName == null || !Regex.IsMatch(deviceInfo.ModelName, profileInfo.ModelName))
|
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.ModelNumber))
|
2014-03-17 14:48:16 +00:00
|
|
|
|
{
|
2014-03-24 07:47:23 +00:00
|
|
|
|
if (deviceInfo.ModelNumber == null || !Regex.IsMatch(deviceInfo.ModelNumber, profileInfo.ModelNumber))
|
2014-03-17 14:48:16 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-03-15 16:11:10 +00:00
|
|
|
|
|
2014-03-18 01:45:41 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(profileInfo.ModelUrl))
|
2014-03-17 14:48:16 +00:00
|
|
|
|
{
|
2014-03-24 07:47:23 +00:00
|
|
|
|
if (deviceInfo.ModelUrl == null || !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
|
|
|
|
{
|
2014-03-24 07:47:23 +00:00
|
|
|
|
if (deviceInfo.SerialNumber == null || !Regex.IsMatch(deviceInfo.SerialNumber, profileInfo.SerialNumber))
|
2014-03-17 14:48:16 +00:00
|
|
|
|
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
|
|
|
|
}
|