jellyfin/MediaBrowser.Dlna/DlnaManager.cs

408 lines
14 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 16:42:02 +00:00
//list.Add(new DeviceProfile
//{
// Name = "Samsung TV (B Series)",
// ClientType = "DLNA",
// Identification = new DeviceIdentification
// {
// FriendlyName = "^TV$",
// ModelNumber = @"1\.0",
// ModelName = "Samsung DTV DMR"
// },
// TranscodingProfiles = new[]
// {
// new TranscodingProfile
// {
// Container = "mp3",
// Type = DlnaProfileType.Audio,
// },
// new TranscodingProfile
// {
// Container = "ts",
// Type = DlnaProfileType.Video
// }
// },
// DirectPlayProfiles = new[]
// {
// new DirectPlayProfile
// {
// Container = "mp3",
// Type = DlnaProfileType.Audio,
// },
// new DirectPlayProfile
// {
// Container = "mkv",
// Type = DlnaProfileType.Video
// },
// new DirectPlayProfile
// {
// Container = "avi",
// Type = DlnaProfileType.Video
// },
// new DirectPlayProfile
// {
// Container = "mp4",
// Type = DlnaProfileType.Video
// }
// },
// MediaProfiles = new[]
// {
// new MediaProfile
// {
// Container ="avi",
// MimeType = "video/x-msvideo",
// Type = DlnaProfileType.Video
// },
// new MediaProfile
// {
// Container ="mkv",
// MimeType = "video/x-mkv",
// Type = DlnaProfileType.Video
// }
// }
//});
//list.Add(new DeviceProfile
//{
// Name = "Samsung TV (E/F-series)",
// ClientType = "DLNA",
// Identification = new DeviceIdentification
// {
// FriendlyName = @"(^\[TV\][A-Z]{2}\d{2}(E|F)[A-Z]?\d{3,4}.*)|^\[TV\] Samsung|(^\[TV\]Samsung [A-Z]{2}\d{2}(E|F)[A-Z]?\d{3,4}.*)",
// ModelNumber = @"(1\.0)|(AllShare1\.0)"
// },
// TranscodingProfiles = new[]
// {
// new TranscodingProfile
// {
// Container = "mp3",
// Type = DlnaProfileType.Audio
// },
// new TranscodingProfile
// {
// Container = "ts",
// Type = DlnaProfileType.Video
// }
// },
// DirectPlayProfiles = new[]
// {
// new DirectPlayProfile
// {
// Container = "mp3",
// Type = DlnaProfileType.Audio
// },
// new DirectPlayProfile
// {
// Container = "mkv",
// Type = DlnaProfileType.Video
// },
// new DirectPlayProfile
// {
// Container = "avi",
// Type = DlnaProfileType.Video
// },
// new DirectPlayProfile
// {
// Container = "mp4",
// Type = DlnaProfileType.Video
// }
// },
// MediaProfiles = new[]
// {
// new MediaProfile
// {
// Container ="avi",
// MimeType = "video/x-msvideo",
// Type = DlnaProfileType.Video
// },
// new MediaProfile
// {
// Container ="mkv",
// MimeType = "video/x-mkv",
// Type = DlnaProfileType.Video
// }
// }
//});
//list.Add(new DeviceProfile
//{
// Name = "Samsung TV (C/D-series)",
// ClientType = "DLNA",
// Identification = new DeviceIdentification
// {
// FriendlyName = @"(^TV-\d{2}C\d{3}.*)|(^\[TV\][A-Z]{2}\d{2}(D)[A-Z]?\d{3,4}.*)|^\[TV\] Samsung",
// ModelNumber = @"(1\.0)|(AllShare1\.0)"
// },
// TranscodingProfiles = new[]
// {
// new TranscodingProfile
// {
// Container = "mp3",
// Type = DlnaProfileType.Audio
// },
// new TranscodingProfile
// {
// Container = "ts",
// Type = DlnaProfileType.Video
// }
// },
// DirectPlayProfiles = new[]
// {
// new DirectPlayProfile
// {
// Container = "mp3",
// Type = DlnaProfileType.Audio
// },
// new DirectPlayProfile
// {
// Container = "mkv",
// Type = DlnaProfileType.Video
// },
// new DirectPlayProfile
// {
// Container = "avi",
// Type = DlnaProfileType.Video
// },
// new DirectPlayProfile
// {
// Container = "mp4",
// Type = DlnaProfileType.Video
// }
// },
// MediaProfiles = new[]
// {
// new MediaProfile
// {
// Container ="avi",
// MimeType = "video/x-msvideo",
// Type = DlnaProfileType.Video
// },
// new MediaProfile
// {
// Container ="mkv",
// MimeType = "video/x-mkv",
// Type = DlnaProfileType.Video
// }
// }
//});
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 DeviceProfile
//{
// Name = "Philips (2010-)",
// ClientType = "DLNA",
// Identification = new DeviceIdentification
// {
// FriendlyName = ".*PHILIPS.*",
// ModelName = "WD TV HD Live"
// },
// DirectPlayProfiles = new[]
// {
// new DirectPlayProfile
// {
// Container = "mp3,wma",
// Type = DlnaProfileType.Audio
// },
// new DirectPlayProfile
// {
// Container = "avi",
// Type = DlnaProfileType.Video
// },
// new DirectPlayProfile
// {
// Container = "mkv",
// Type = DlnaProfileType.Video
// }
// },
// MediaProfiles = new[]
// {
// new MediaProfile
// {
// Container ="avi",
// MimeType = "video/avi",
// Type = DlnaProfileType.Video
// },
// new MediaProfile
// {
// Container ="mkv",
// MimeType = "video/x-matroska",
// Type = DlnaProfileType.Video
// }
// }
//});
list.Add(new WdtvLiveProfile());
//list.Add(new DeviceProfile
//{
// // Linksys DMA2100us does not need any transcoding of the formats we support statically
// Name = "Linksys DMA2100",
// ClientType = "DLNA",
// Identification = new DeviceIdentification
// {
// ModelName = "DMA2100us"
// },
// DirectPlayProfiles = new[]
// {
// new DirectPlayProfile
// {
// Container = "mp3,flac,m4a,wma",
// Type = DlnaProfileType.Audio
// },
// new DirectPlayProfile
// {
// Container = "avi,mp4,mkv,ts",
// Type = DlnaProfileType.Video
// }
// }
//});
list.Add(new DenonAvrProfile());
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
}