diff --git a/MediaBrowser.Api/DlnaService.cs b/MediaBrowser.Api/DlnaService.cs index d40492ee2..792a7ff43 100644 --- a/MediaBrowser.Api/DlnaService.cs +++ b/MediaBrowser.Api/DlnaService.cs @@ -30,6 +30,18 @@ namespace MediaBrowser.Api public string Id { get; set; } } + [Route("/Dlna/Profiles/{ProfileId}", "POST", Summary = "Updates a profile")] + public class UpdateProfile : DeviceProfile, IReturnVoid + { + [ApiMember(Name = "ProfileId", Description = "Profile Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] + public string ProfileId { get; set; } + } + + [Route("/Dlna/Profiles", "POST", Summary = "Creates a profile")] + public class CreateProfile : DeviceProfile, IReturnVoid + { + } + public class DlnaService : BaseApiService { private readonly IDlnaManager _dlnaManager; @@ -64,5 +76,15 @@ namespace MediaBrowser.Api { _dlnaManager.DeleteProfile(request.Id); } + + public void Post(UpdateProfile request) + { + _dlnaManager.UpdateProfile(request); + } + + public void Post(CreateProfile request) + { + _dlnaManager.CreateProfile(request); + } } } diff --git a/MediaBrowser.Controller/Dlna/DeviceProfile.cs b/MediaBrowser.Controller/Dlna/DeviceProfile.cs index d0c2dcc1a..5950698fb 100644 --- a/MediaBrowser.Controller/Dlna/DeviceProfile.cs +++ b/MediaBrowser.Controller/Dlna/DeviceProfile.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Dlna; +using MediaBrowser.Model.Entities; using System; using System.Collections.Generic; using System.Linq; @@ -17,9 +18,11 @@ namespace MediaBrowser.Controller.Dlna public string Name { get; set; } [XmlIgnore] - [IgnoreDataMember] public string Id { get; set; } + [XmlIgnore] + public DeviceProfileType ProfileType { get; set; } + /// /// Gets or sets the identification. /// diff --git a/MediaBrowser.Controller/Dlna/IDlnaManager.cs b/MediaBrowser.Controller/Dlna/IDlnaManager.cs index eb4b65e14..521d17e01 100644 --- a/MediaBrowser.Controller/Dlna/IDlnaManager.cs +++ b/MediaBrowser.Controller/Dlna/IDlnaManager.cs @@ -24,6 +24,18 @@ namespace MediaBrowser.Controller.Dlna /// DeviceProfile. DeviceProfile GetDefaultProfile(); + /// + /// Creates the profile. + /// + /// The profile. + void CreateProfile(DeviceProfile profile); + + /// + /// Updates the profile. + /// + /// The profile. + void UpdateProfile(DeviceProfile profile); + /// /// Deletes the profile. /// diff --git a/MediaBrowser.Dlna/DlnaManager.cs b/MediaBrowser.Dlna/DlnaManager.cs index e40b085fd..edccc71c9 100644 --- a/MediaBrowser.Dlna/DlnaManager.cs +++ b/MediaBrowser.Dlna/DlnaManager.cs @@ -35,11 +35,11 @@ namespace MediaBrowser.Dlna { ExtractProfilesIfNeeded(); - var list = GetProfiles(UserProfilesPath) + var list = GetProfiles(UserProfilesPath, DeviceProfileType.User) .OrderBy(i => i.Name) .ToList(); - list.AddRange(GetProfiles(SystemProfilesPath) + list.AddRange(GetProfiles(SystemProfilesPath, DeviceProfileType.System) .OrderBy(i => i.Name)); return list; @@ -111,7 +111,13 @@ namespace MediaBrowser.Dlna public DeviceProfile GetProfile(DeviceIdentification deviceInfo) { - var profile = GetProfiles().FirstOrDefault(i => IsMatch(deviceInfo, i.Identification)); + if (deviceInfo == null) + { + throw new ArgumentNullException("deviceInfo"); + } + + var profile = GetProfiles() + .FirstOrDefault(i => i.Identification != null && IsMatch(deviceInfo, i.Identification)); if (profile != null) { @@ -127,12 +133,6 @@ namespace MediaBrowser.Dlna private bool IsMatch(DeviceIdentification deviceInfo, DeviceIdentification profileInfo) { - if (profileInfo == null) - { - //There are profiles without identification, ignore thoose - return false; - } - if (!string.IsNullOrWhiteSpace(profileInfo.DeviceDescription)) { if (deviceInfo.DeviceDescription == null || !Regex.IsMatch(deviceInfo.DeviceDescription, profileInfo.DeviceDescription)) @@ -192,6 +192,11 @@ namespace MediaBrowser.Dlna public DeviceProfile GetProfile(IDictionary headers) { + if (headers == null) + { + throw new ArgumentNullException("headers"); + } + return GetProfiles().FirstOrDefault(i => IsMatch(headers, i.Identification)); } @@ -238,14 +243,14 @@ namespace MediaBrowser.Dlna } } - private IEnumerable GetProfiles(string path) + private IEnumerable GetProfiles(string path, DeviceProfileType type) { try { return new DirectoryInfo(path) .EnumerateFiles("*", SearchOption.TopDirectoryOnly) .Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase)) - .Select(i => ParseProfileXmlFile(i.FullName)) + .Select(i => ParseProfileXmlFile(i.FullName, type)) .Where(i => i != null) .ToList(); } @@ -255,13 +260,14 @@ namespace MediaBrowser.Dlna } } - private DeviceProfile ParseProfileXmlFile(string path) + private DeviceProfile ParseProfileXmlFile(string path, DeviceProfileType type) { try { var profile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path); profile.Id = path.ToLower().GetMD5().ToString("N"); + profile.ProfileType = type; return profile; } @@ -275,9 +281,14 @@ namespace MediaBrowser.Dlna public DeviceProfile GetProfile(string id) { + if (string.IsNullOrWhiteSpace(id)) + { + throw new ArgumentNullException("id"); + } + var info = GetProfileInfosInternal().First(i => string.Equals(i.Info.Id, id)); - return ParseProfileXmlFile(info.Path); + return ParseProfileXmlFile(info.Path, info.Info.Type); } private IEnumerable GetProfileInfosInternal() @@ -368,6 +379,14 @@ namespace MediaBrowser.Dlna File.Delete(info.Path); } + public void CreateProfile(DeviceProfile profile) + { + } + + public void UpdateProfile(DeviceProfile profile) + { + } + class InternalProfileInfo { internal DeviceProfileInfo Info { get; set; } diff --git a/MediaBrowser.Dlna/Profiles/DefaultProfile.cs b/MediaBrowser.Dlna/Profiles/DefaultProfile.cs index 254a4d944..0efe18755 100644 --- a/MediaBrowser.Dlna/Profiles/DefaultProfile.cs +++ b/MediaBrowser.Dlna/Profiles/DefaultProfile.cs @@ -8,10 +8,11 @@ namespace MediaBrowser.Dlna.Profiles { public DefaultProfile() { - Name = "Media Browser"; + Name = "Generic Device"; ProtocolInfo = "DLNA"; + FriendlyName = "Media Browser"; Manufacturer = "Media Browser"; ModelDescription = "Media Browser"; ModelName = "Media Browser"; diff --git a/MediaBrowser.Dlna/Profiles/WdtvLiveProfile.cs b/MediaBrowser.Dlna/Profiles/WdtvLiveProfile.cs index b0d65469d..af5d9b295 100644 --- a/MediaBrowser.Dlna/Profiles/WdtvLiveProfile.cs +++ b/MediaBrowser.Dlna/Profiles/WdtvLiveProfile.cs @@ -1,5 +1,5 @@ -using System.Xml.Serialization; -using MediaBrowser.Controller.Dlna; +using MediaBrowser.Controller.Dlna; +using System.Xml.Serialization; namespace MediaBrowser.Dlna.Profiles { diff --git a/MediaBrowser.Dlna/Profiles/Xml/Default.xml b/MediaBrowser.Dlna/Profiles/Xml/Default.xml index 25d553a07..52b92c6f3 100644 --- a/MediaBrowser.Dlna/Profiles/Xml/Default.xml +++ b/MediaBrowser.Dlna/Profiles/Xml/Default.xml @@ -1,6 +1,7 @@ - Media Browser + Generic Device + Media Browser Media Browser http://mediabrowser3.com/ Media Browser diff --git a/MediaBrowser.Dlna/Profiles/Xml/Denon AVR.xml b/MediaBrowser.Dlna/Profiles/Xml/Denon AVR.xml index ac0309ce4..3332e4d45 100644 --- a/MediaBrowser.Dlna/Profiles/Xml/Denon AVR.xml +++ b/MediaBrowser.Dlna/Profiles/Xml/Denon AVR.xml @@ -6,6 +6,7 @@ Denon + Media Browser Media Browser http://mediabrowser3.com/ Media Browser diff --git a/MediaBrowser.Dlna/Profiles/Xml/LG Smart TV.xml b/MediaBrowser.Dlna/Profiles/Xml/LG Smart TV.xml index 32364ced7..cc8b40430 100644 --- a/MediaBrowser.Dlna/Profiles/Xml/LG Smart TV.xml +++ b/MediaBrowser.Dlna/Profiles/Xml/LG Smart TV.xml @@ -7,6 +7,7 @@ + Media Browser Media Browser http://mediabrowser3.com/ Media Browser diff --git a/MediaBrowser.Dlna/Profiles/Xml/Linksys DMA2100.xml b/MediaBrowser.Dlna/Profiles/Xml/Linksys DMA2100.xml index 3437cdb5c..b19cb0f7b 100644 --- a/MediaBrowser.Dlna/Profiles/Xml/Linksys DMA2100.xml +++ b/MediaBrowser.Dlna/Profiles/Xml/Linksys DMA2100.xml @@ -5,6 +5,7 @@ DMA2100us + Media Browser Media Browser http://mediabrowser3.com/ Media Browser diff --git a/MediaBrowser.Dlna/Profiles/Xml/Panasonic Viera.xml b/MediaBrowser.Dlna/Profiles/Xml/Panasonic Viera.xml index e8b2ff619..71e240313 100644 --- a/MediaBrowser.Dlna/Profiles/Xml/Panasonic Viera.xml +++ b/MediaBrowser.Dlna/Profiles/Xml/Panasonic Viera.xml @@ -8,6 +8,7 @@ + Media Browser Media Browser http://mediabrowser3.com/ Media Browser diff --git a/MediaBrowser.Dlna/Profiles/Xml/Samsung Smart TV.xml b/MediaBrowser.Dlna/Profiles/Xml/Samsung Smart TV.xml index 0cc34bbca..77648147f 100644 --- a/MediaBrowser.Dlna/Profiles/Xml/Samsung Smart TV.xml +++ b/MediaBrowser.Dlna/Profiles/Xml/Samsung Smart TV.xml @@ -5,6 +5,7 @@ samsung.com + Media Browser Media Browser http://mediabrowser3.com/ Media Browser diff --git a/MediaBrowser.Dlna/Profiles/Xml/Sony Blu-ray Player 2013.xml b/MediaBrowser.Dlna/Profiles/Xml/Sony Blu-ray Player 2013.xml index a26ab8c85..942812295 100644 --- a/MediaBrowser.Dlna/Profiles/Xml/Sony Blu-ray Player 2013.xml +++ b/MediaBrowser.Dlna/Profiles/Xml/Sony Blu-ray Player 2013.xml @@ -7,6 +7,7 @@ Sony + Media Browser Microsoft Corporation http://mediabrowser3.com/ Windows Media Player Sharing diff --git a/MediaBrowser.Dlna/Profiles/Xml/Sony Blu-ray Player.xml b/MediaBrowser.Dlna/Profiles/Xml/Sony Blu-ray Player.xml index f5e4da835..519304576 100644 --- a/MediaBrowser.Dlna/Profiles/Xml/Sony Blu-ray Player.xml +++ b/MediaBrowser.Dlna/Profiles/Xml/Sony Blu-ray Player.xml @@ -9,6 +9,7 @@ + Media Browser Microsoft Corporation http://mediabrowser3.com/ Windows Media Player Sharing diff --git a/MediaBrowser.Dlna/Profiles/Xml/Sony Bravia (2010).xml b/MediaBrowser.Dlna/Profiles/Xml/Sony Bravia (2010).xml index 8387e2d0d..d240e1d34 100644 --- a/MediaBrowser.Dlna/Profiles/Xml/Sony Bravia (2010).xml +++ b/MediaBrowser.Dlna/Profiles/Xml/Sony Bravia (2010).xml @@ -8,6 +8,7 @@ + Media Browser Microsoft Corporation http://www.microsoft.com/ Windows Media Player Sharing diff --git a/MediaBrowser.Dlna/Profiles/Xml/Sony Bravia (2011).xml b/MediaBrowser.Dlna/Profiles/Xml/Sony Bravia (2011).xml index febd70f50..2372aa5ad 100644 --- a/MediaBrowser.Dlna/Profiles/Xml/Sony Bravia (2011).xml +++ b/MediaBrowser.Dlna/Profiles/Xml/Sony Bravia (2011).xml @@ -8,6 +8,7 @@ + Media Browser Microsoft Corporation http://www.microsoft.com/ Windows Media Player Sharing diff --git a/MediaBrowser.Dlna/Profiles/Xml/Sony Bravia (2012).xml b/MediaBrowser.Dlna/Profiles/Xml/Sony Bravia (2012).xml index 08217ce04..7edf09134 100644 --- a/MediaBrowser.Dlna/Profiles/Xml/Sony Bravia (2012).xml +++ b/MediaBrowser.Dlna/Profiles/Xml/Sony Bravia (2012).xml @@ -8,6 +8,7 @@ + Media Browser Microsoft Corporation http://www.microsoft.com/ Windows Media Player Sharing diff --git a/MediaBrowser.Dlna/Profiles/Xml/Sony Bravia (2013).xml b/MediaBrowser.Dlna/Profiles/Xml/Sony Bravia (2013).xml index 9f0f4204e..ec624cd8e 100644 --- a/MediaBrowser.Dlna/Profiles/Xml/Sony Bravia (2013).xml +++ b/MediaBrowser.Dlna/Profiles/Xml/Sony Bravia (2013).xml @@ -8,6 +8,7 @@ + Media Browser Microsoft Corporation http://www.microsoft.com/ Windows Media Player Sharing diff --git a/MediaBrowser.Dlna/Profiles/Xml/Sony PlayStation 3.xml b/MediaBrowser.Dlna/Profiles/Xml/Sony PlayStation 3.xml index 21e94f3e5..eeaf2d819 100644 --- a/MediaBrowser.Dlna/Profiles/Xml/Sony PlayStation 3.xml +++ b/MediaBrowser.Dlna/Profiles/Xml/Sony PlayStation 3.xml @@ -8,6 +8,7 @@ + Media Browser Media Browser http://mediabrowser3.com/ Media Browser diff --git a/MediaBrowser.Dlna/Profiles/Xml/WDTV Live.xml b/MediaBrowser.Dlna/Profiles/Xml/WDTV Live.xml index df3d78f03..ffa39c26d 100644 --- a/MediaBrowser.Dlna/Profiles/Xml/WDTV Live.xml +++ b/MediaBrowser.Dlna/Profiles/Xml/WDTV Live.xml @@ -8,6 +8,7 @@ + Media Browser Media Browser http://mediabrowser3.com/ Media Browser diff --git a/MediaBrowser.Dlna/Profiles/Xml/Xbox 360.xml b/MediaBrowser.Dlna/Profiles/Xml/Xbox 360.xml index 99401434c..e7839ca77 100644 --- a/MediaBrowser.Dlna/Profiles/Xml/Xbox 360.xml +++ b/MediaBrowser.Dlna/Profiles/Xml/Xbox 360.xml @@ -8,6 +8,7 @@ + Media Browser Microsoft Corporation http://www.microsoft.com/ Windows Media Player Sharing diff --git a/MediaBrowser.Dlna/Profiles/Xml/Xbox One.xml b/MediaBrowser.Dlna/Profiles/Xml/Xbox One.xml index f731903ce..5243218fb 100644 --- a/MediaBrowser.Dlna/Profiles/Xml/Xbox One.xml +++ b/MediaBrowser.Dlna/Profiles/Xml/Xbox One.xml @@ -6,6 +6,7 @@ Xbox One + Media Browser Media Browser http://mediabrowser3.com/ Media Browser diff --git a/MediaBrowser.Dlna/Profiles/Xml/foobar2000.xml b/MediaBrowser.Dlna/Profiles/Xml/foobar2000.xml index f50ea581a..126d7fe73 100644 --- a/MediaBrowser.Dlna/Profiles/Xml/foobar2000.xml +++ b/MediaBrowser.Dlna/Profiles/Xml/foobar2000.xml @@ -7,6 +7,7 @@ + Media Browser Media Browser http://mediabrowser3.com/ Media Browser