The Free Software Media System - Server Backend & API
rework EnableMediaPlayback
Luke Pulverenti2ceea17bf424
diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.csindex da3f9be17c..5b32210786 100644--- a/MediaBrowser.Api/Playback/BaseStreamingService.cs+++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs@@ -12,6 +12,7 @@ using MediaBrowser.Model.Drawing;using MediaBrowser.Model.Dto;using MediaBrowser.Model.Entities;using MediaBrowser.Model.IO;+using MediaBrowser.Model.Library;using MediaBrowser.Model.LiveTv;using System;using System.Collections.Generic;@@ -1268,11 +1269,6 @@ namespace MediaBrowser.Api.Playbackvar user = AuthorizationRequestFilterAttribute.GetCurrentUser(Request, UserManager);- if (user != null && !user.Configuration.EnableMediaPlayback)- {- throw new ArgumentException(string.Format("{0} is not allowed to play media.", user.Name));- }-var url = Request.PathInfo;if (!request.AudioCodec.HasValue)@@ -1288,6 +1284,11 @@ namespace MediaBrowser.Api.Playbackvar item = DtoService.GetItemByDtoId(request.Id);+ if (user != null && item.GetPlayAccess(user) != PlayAccess.Full)+ {+ throw new ArgumentException(string.Format("{0} is not allowed to play media.", user.Name));+ }+if (item is ILiveTvRecording){var recording = await LiveTvManager.GetInternalRecording(request.Id, cancellationToken).ConfigureAwait(false);diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.csindex cf79148f64..483ed1c341 100644--- a/MediaBrowser.Controller/Entities/BaseItem.cs+++ b/MediaBrowser.Controller/Entities/BaseItem.cs@@ -7,6 +7,7 @@ using MediaBrowser.Controller.Persistence;using MediaBrowser.Controller.Providers;using MediaBrowser.Model.Configuration;using MediaBrowser.Model.Entities;+using MediaBrowser.Model.Library;using MediaBrowser.Model.Logging;using System;using System.Collections.Generic;@@ -478,6 +479,21 @@ namespace MediaBrowser.Controller.Entities}}+ /// <summary>+ /// Gets the play access.+ /// </summary>+ /// <param name="user">The user.</param>+ /// <returns>PlayAccess.</returns>+ public PlayAccess GetPlayAccess(User user)+ {+ if (!user.Configuration.EnableMediaPlayback)+ {+ return PlayAccess.None;+ }++ return PlayAccess.Full;+ }+/// <summary>/// Loads local trailers from the file system/// </summary>diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csprojindex 8987cae5fa..556a59138a 100644--- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj+++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj@@ -233,6 +233,9 @@<Compile Include="..\MediaBrowser.Model\IO\IZipClient.cs"><Link>IO\IZipClient.cs</Link></Compile>+ <Compile Include="..\MediaBrowser.Model\Library\PlayAccess.cs">+ <Link>Library\PlayAccess.cs</Link>+ </Compile><Compile Include="..\MediaBrowser.Model\LiveTv\ChannelInfoDto.cs"><Link>LiveTv\ChannelInfoDto.cs</Link></Compile>diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csprojindex 76fbe20007..b5ac60d52f 100644--- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj+++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj@@ -220,6 +220,9 @@<Compile Include="..\MediaBrowser.Model\IO\IZipClient.cs"><Link>IO\IZipClient.cs</Link></Compile>+ <Compile Include="..\MediaBrowser.Model\Library\PlayAccess.cs">+ <Link>Library\PlayAccess.cs</Link>+ </Compile><Compile Include="..\MediaBrowser.Model\LiveTv\ChannelInfoDto.cs"><Link>LiveTv\ChannelInfoDto.cs</Link></Compile>diff --git a/MediaBrowser.Model/Dto/BaseItemDto.cs b/MediaBrowser.Model/Dto/BaseItemDto.csindex 8f43304463..0d2c4c34ed 100644--- a/MediaBrowser.Model/Dto/BaseItemDto.cs+++ b/MediaBrowser.Model/Dto/BaseItemDto.cs@@ -4,6 +4,7 @@ using System.Collections.Generic;using System.ComponentModel;using System.Diagnostics;using System.Runtime.Serialization;+using MediaBrowser.Model.Library;namespace MediaBrowser.Model.Dto{@@ -153,6 +154,12 @@ namespace MediaBrowser.Model.Dto/// </summary>/// <value>The cumulative run time ticks.</value>public long? CumulativeRunTimeTicks { get; set; }++ /// <summary>+ /// Gets or sets the original run time ticks.+ /// </summary>+ /// <value>The original run time ticks.</value>+ public long? OriginalRunTimeTicks { get; set; }/// <summary>/// Gets or sets the run time ticks.@@ -160,6 +167,12 @@ namespace MediaBrowser.Model.Dto/// <value>The run time ticks.</value>public long? RunTimeTicks { get; set; }+ /// <summary>+ /// Gets or sets the play access.+ /// </summary>+ /// <value>The play access.</value>+ public PlayAccess PlayAccess { get; set; }+/// <summary>/// Gets or sets the aspect ratio./// </summary>diff --git a/MediaBrowser.Model/Dto/RecordingInfoDto.cs b/MediaBrowser.Model/Dto/RecordingInfoDto.csdeleted file mode 100644index 4151c5a9c8..0000000000--- a/MediaBrowser.Model/Dto/RecordingInfoDto.cs+++ /dev/null@@ -1,12 +0,0 @@-using System;-using System.Collections.Generic;-using System.Linq;-using System.Text;-using System.Threading.Tasks;--namespace MediaBrowser.Model.Dto-{- public class RecordingInfoDto- {- }-}diff --git a/MediaBrowser.Model/Library/PlayAccess.cs b/MediaBrowser.Model/Library/PlayAccess.csnew file mode 100644index 0000000000..6ec845fc73--- /dev/null+++ b/MediaBrowser.Model/Library/PlayAccess.cs@@ -0,0 +1,9 @@++namespace MediaBrowser.Model.Library+{+ public enum PlayAccess+ {+ Full = 0,+ None = 1+ }+}diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csprojindex efe450ac15..b2d1303585 100644--- a/MediaBrowser.Model/MediaBrowser.Model.csproj+++ b/MediaBrowser.Model/MediaBrowser.Model.csproj@@ -76,6 +76,7 @@<Compile Include="Entities\PackageReviewInfo.cs" /><Compile Include="FileOrganization\FileOrganizationResult.cs" /><Compile Include="FileOrganization\FileOrganizationQuery.cs" />+ <Compile Include="Library\PlayAccess.cs" /><Compile Include="LiveTv\ChannelInfoDto.cs" /><Compile Include="LiveTv\ChannelQuery.cs" /><Compile Include="LiveTv\ProgramInfoDto.cs" />diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.csindex 65a496533e..321923dbaf 100644--- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs+++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs@@ -10,7 +10,6 @@ using MediaBrowser.Controller.Entities.TV;using MediaBrowser.Controller.Library;using MediaBrowser.Controller.Persistence;using MediaBrowser.Controller.Session;-using MediaBrowser.Model.Configuration;using MediaBrowser.Model.Drawing;using MediaBrowser.Model.Dto;using MediaBrowser.Model.Entities;@@ -185,6 +184,8 @@ namespace MediaBrowser.Server.Implementations.Dto{dto.UserData.Played = dto.PlayedPercentage.HasValue && dto.PlayedPercentage.Value >= 100;}++ dto.PlayAccess = item.GetPlayAccess(user);}private int GetChildCount(Folder folder, User user)diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.csindex 09a442966c..bfa23b9975 100644--- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs+++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs@@ -7,6 +7,7 @@ using MediaBrowser.Controller.Library;using MediaBrowser.Controller.Persistence;using MediaBrowser.Controller.Session;using MediaBrowser.Model.Entities;+using MediaBrowser.Model.Library;using MediaBrowser.Model.Logging;using MediaBrowser.Model.Session;using System;@@ -604,20 +605,20 @@ namespace MediaBrowser.Server.Implementations.Session{var session = GetSessionForRemoteControl(sessionId);+ var items = command.ItemIds.Select(i => _libraryManager.GetItemById(new Guid(i)))+ .Where(i => i.LocationType != LocationType.Virtual)+ .ToList();+if (session.UserId.HasValue){var user = _userManager.GetUserById(session.UserId.Value);- if (!user.Configuration.EnableMediaPlayback)+ if (items.Any(i => i.GetPlayAccess(user) != PlayAccess.Full)){throw new ArgumentException(string.Format("{0} is not allowed to play media.", user.Name));}}- var items = command.ItemIds.Select(i => _libraryManager.GetItemById(new Guid(i)))- .Where(i => i.LocationType != LocationType.Virtual)- .ToList();-if (command.PlayCommand != PlayCommand.PlayNow){if (items.Any(i => !session.QueueableMediaTypes.Contains(i.MediaType, StringComparer.OrdinalIgnoreCase)))