The Free Software Media System - Server Backend & API
add dlna service methods
Luke Pulverenti6ac7675c15af
diff --git a/MediaBrowser.Api/DlnaService.cs b/MediaBrowser.Api/DlnaService.csnew file mode 100644index 0000000000..d40492ee29--- /dev/null+++ b/MediaBrowser.Api/DlnaService.cs@@ -0,0 +1,68 @@+using MediaBrowser.Controller.Dlna;+using MediaBrowser.Model.Dlna;+using ServiceStack;+using System.Collections.Generic;+using System.Linq;++namespace MediaBrowser.Api+{+ [Route("/Dlna/ProfileInfos", "GET", Summary = "Gets a list of profiles")]+ public class GetProfileInfos : IReturn<List<DeviceProfileInfo>>+ {+ }++ [Route("/Dlna/Profiles/{Id}", "DELETE", Summary = "Deletes a profile")]+ public class DeleteProfile : IReturnVoid+ {+ [ApiMember(Name = "Id", Description = "Profile Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]+ public string Id { get; set; }+ }++ [Route("/Dlna/Profiles/Default", "GET", Summary = "Gets the default profile")]+ public class GetDefaultProfile : IReturn<DeviceProfile>+ {+ }++ [Route("/Dlna/Profiles/{Id}", "GET", Summary = "Gets a single profile")]+ public class GetProfile : IReturn<DeviceProfile>+ {+ [ApiMember(Name = "Id", Description = "Profile Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]+ public string Id { get; set; }+ }++ public class DlnaService : BaseApiService+ {+ private readonly IDlnaManager _dlnaManager;++ public DlnaService(IDlnaManager dlnaManager)+ {+ _dlnaManager = dlnaManager;+ }++ public object Get(GetProfileInfos request)+ {+ var result = _dlnaManager.GetProfileInfos().ToList();++ return ToOptimizedResult(result);+ }++ public object Get(GetProfile request)+ {+ var result = _dlnaManager.GetProfile(request.Id);++ return ToOptimizedResult(result);+ }++ public object Get(GetDefaultProfile request)+ {+ var result = _dlnaManager.GetDefaultProfile();++ return ToOptimizedResult(result);+ }++ public void Delete(DeleteProfile request)+ {+ _dlnaManager.DeleteProfile(request.Id);+ }+ }+}diff --git a/MediaBrowser.Api/Images/ImageService.cs b/MediaBrowser.Api/Images/ImageService.csindex 2cdaef1ed8..562da40ee5 100644--- a/MediaBrowser.Api/Images/ImageService.cs+++ b/MediaBrowser.Api/Images/ImageService.cs@@ -15,7 +15,6 @@ using ServiceStack.Text.Controller;using ServiceStack.Web;using System;using System.Collections.Generic;-using System.Drawing;using System.IO;using System.Linq;using System.Threading;@@ -776,15 +775,6 @@ namespace MediaBrowser.Api.Imagesvar bytes = Convert.FromBase64String(text);- // Validate first- using (var validationStream = new MemoryStream(bytes))- {- // This will throw an exception if it's not a valid image- using (Image.FromStream(validationStream))- {- }- }-var memoryStream = new MemoryStream(bytes){Position = 0diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csprojindex 38cf39b54f..18559a68df 100644--- a/MediaBrowser.Api/MediaBrowser.Api.csproj+++ b/MediaBrowser.Api/MediaBrowser.Api.csproj@@ -53,7 +53,6 @@<Reference Include="System.Core" /><Reference Include="Microsoft.CSharp" /><Reference Include="System.Data" />- <Reference Include="System.Drawing" /><Reference Include="System.Xml" /><Reference Include="ServiceStack.Interfaces"><HintPath>..\ThirdParty\ServiceStack\ServiceStack.Interfaces.dll</HintPath>@@ -67,6 +66,7 @@<Link>Properties\SharedVersion.cs</Link></Compile><Compile Include="ChannelService.cs" />+ <Compile Include="DlnaService.cs" /><Compile Include="Movies\CollectionService.cs" /><Compile Include="Music\AlbumsService.cs" /><Compile Include="AppThemeService.cs" />diff --git a/MediaBrowser.Controller/Dlna/IDlnaManager.cs b/MediaBrowser.Controller/Dlna/IDlnaManager.csindex dfed5e3108..eb4b65e143 100644--- a/MediaBrowser.Controller/Dlna/IDlnaManager.cs+++ b/MediaBrowser.Controller/Dlna/IDlnaManager.cs@@ -23,6 +23,12 @@ namespace MediaBrowser.Controller.Dlna/// </summary>/// <returns>DeviceProfile.</returns>DeviceProfile GetDefaultProfile();++ /// <summary>+ /// Deletes the profile.+ /// </summary>+ /// <param name="id">The identifier.</param>+ void DeleteProfile(string id);/// <summary>/// Gets the profile.diff --git a/MediaBrowser.Controller/MediaEncoding/MediaEncoderHelpers.cs b/MediaBrowser.Controller/MediaEncoding/MediaEncoderHelpers.csindex 1840331773..fd1f651017 100644--- a/MediaBrowser.Controller/MediaEncoding/MediaEncoderHelpers.cs+++ b/MediaBrowser.Controller/MediaEncoding/MediaEncoderHelpers.cs@@ -154,7 +154,8 @@ namespace MediaBrowser.Controller.MediaEncodingCodec = streamInfo.codec_name,Profile = streamInfo.profile,Level = streamInfo.level,- Index = streamInfo.index+ Index = streamInfo.index,+ PixelFormat = streamInfo.pix_fmt};if (streamInfo.tags != null)@@ -196,24 +197,21 @@ namespace MediaBrowser.Controller.MediaEncoding}// Get stream bitrate- if (stream.Type != MediaStreamType.Subtitle)- {- var bitrate = 0;+ var bitrate = 0;- if (!string.IsNullOrEmpty(streamInfo.bit_rate))- {- bitrate = int.Parse(streamInfo.bit_rate, UsCulture);- }- else if (formatInfo != null && !string.IsNullOrEmpty(formatInfo.bit_rate))- {- // If the stream info doesn't have a bitrate get the value from the media format info- bitrate = int.Parse(formatInfo.bit_rate, UsCulture);- }+ if (!string.IsNullOrEmpty(streamInfo.bit_rate))+ {+ bitrate = int.Parse(streamInfo.bit_rate, UsCulture);+ }+ else if (formatInfo != null && !string.IsNullOrEmpty(formatInfo.bit_rate) && stream.Type == MediaStreamType.Video)+ {+ // If the stream info doesn't have a bitrate get the value from the media format info+ bitrate = int.Parse(formatInfo.bit_rate, UsCulture);+ }- if (bitrate > 0)- {- stream.BitRate = bitrate;- }+ if (bitrate > 0)+ {+ stream.BitRate = bitrate;}if (streamInfo.disposition != null)diff --git a/MediaBrowser.Dlna/DlnaManager.cs b/MediaBrowser.Dlna/DlnaManager.csindex 32d6c61baf..6582b4ee5f 100644--- a/MediaBrowser.Dlna/DlnaManager.cs+++ b/MediaBrowser.Dlna/DlnaManager.cs@@ -350,6 +350,18 @@ namespace MediaBrowser.DlnaDirectory.CreateDirectory(UserProfilesPath);}+ public void DeleteProfile(string id)+ {+ var info = GetProfileInfosInternal().First(i => string.Equals(id, i.Info.Id));++ if (info.Info.Type == DeviceProfileType.System)+ {+ throw new ArgumentException("System profiles cannot be deleted.");+ }++ File.Delete(info.Path);+ }+class InternalProfileInfo{internal DeviceProfileInfo Info { get; set; }diff --git a/MediaBrowser.Model/Entities/MediaStream.cs b/MediaBrowser.Model/Entities/MediaStream.csindex a8f751c104..b644661f49 100644--- a/MediaBrowser.Model/Entities/MediaStream.cs+++ b/MediaBrowser.Model/Entities/MediaStream.cs@@ -123,6 +123,12 @@ namespace MediaBrowser.Model.Entities/// <value>The filename.</value>public string Path { get; set; }+ /// <summary>+ /// Gets or sets the pixel format.+ /// </summary>+ /// <value>The pixel format.</value>+ public string PixelFormat { get; set; }+/// <summary>/// Gets or sets the level./// </summary>diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.csindex cb5915b702..99afbbdd70 100644--- a/MediaBrowser.WebDashboard/Api/DashboardService.cs+++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs@@ -422,6 +422,7 @@ namespace MediaBrowser.WebDashboard.Api"dashboardinfo.js","dashboardpage.js","directorybrowser.js",+ "dlnaprofile.js","dlnaprofiles.js","dlnasettings.js","editcollectionitems.js",diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csprojindex 97e8c9ba01..6a8cc49b1a 100644--- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj+++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj@@ -224,6 +224,9 @@<Content Include="dashboard-ui\dashboardinfopage.html"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>+ <Content Include="dashboard-ui\dlnaprofile.html">+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>+ </Content><Content Include="dashboard-ui\dlnaprofiles.html"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>@@ -515,6 +518,9 @@<Content Include="dashboard-ui\scripts\dashboardinfo.js"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>+ <Content Include="dashboard-ui\scripts\dlnaprofile.js">+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>+ </Content><Content Include="dashboard-ui\scripts\dlnaprofiles.js"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>