mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-11-04 03:27:21 -05:00 
			
		
		
		
	rework EnableMediaPlayback
This commit is contained in:
		
							parent
							
								
									7cd41a6ed6
								
							
						
					
					
						commit
						2ceea17bf4
					
				@ -12,6 +12,7 @@ using MediaBrowser.Model.Drawing;
 | 
				
			|||||||
using MediaBrowser.Model.Dto;
 | 
					using MediaBrowser.Model.Dto;
 | 
				
			||||||
using MediaBrowser.Model.Entities;
 | 
					using MediaBrowser.Model.Entities;
 | 
				
			||||||
using MediaBrowser.Model.IO;
 | 
					using MediaBrowser.Model.IO;
 | 
				
			||||||
 | 
					using MediaBrowser.Model.Library;
 | 
				
			||||||
using MediaBrowser.Model.LiveTv;
 | 
					using MediaBrowser.Model.LiveTv;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
@ -1268,11 +1269,6 @@ namespace MediaBrowser.Api.Playback
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            var user = AuthorizationRequestFilterAttribute.GetCurrentUser(Request, UserManager);
 | 
					            var 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;
 | 
					            var url = Request.PathInfo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!request.AudioCodec.HasValue)
 | 
					            if (!request.AudioCodec.HasValue)
 | 
				
			||||||
@ -1288,6 +1284,11 @@ namespace MediaBrowser.Api.Playback
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            var item = DtoService.GetItemByDtoId(request.Id);
 | 
					            var 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)
 | 
					            if (item is ILiveTvRecording)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                var recording = await LiveTvManager.GetInternalRecording(request.Id, cancellationToken).ConfigureAwait(false);
 | 
					                var recording = await LiveTvManager.GetInternalRecording(request.Id, cancellationToken).ConfigureAwait(false);
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,7 @@ using MediaBrowser.Controller.Persistence;
 | 
				
			|||||||
using MediaBrowser.Controller.Providers;
 | 
					using MediaBrowser.Controller.Providers;
 | 
				
			||||||
using MediaBrowser.Model.Configuration;
 | 
					using MediaBrowser.Model.Configuration;
 | 
				
			||||||
using MediaBrowser.Model.Entities;
 | 
					using MediaBrowser.Model.Entities;
 | 
				
			||||||
 | 
					using MediaBrowser.Model.Library;
 | 
				
			||||||
using MediaBrowser.Model.Logging;
 | 
					using MediaBrowser.Model.Logging;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					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>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Loads local trailers from the file system
 | 
					        /// Loads local trailers from the file system
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
 | 
				
			|||||||
@ -233,6 +233,9 @@
 | 
				
			|||||||
    <Compile Include="..\MediaBrowser.Model\IO\IZipClient.cs">
 | 
					    <Compile Include="..\MediaBrowser.Model\IO\IZipClient.cs">
 | 
				
			||||||
      <Link>IO\IZipClient.cs</Link>
 | 
					      <Link>IO\IZipClient.cs</Link>
 | 
				
			||||||
    </Compile>
 | 
					    </Compile>
 | 
				
			||||||
 | 
					    <Compile Include="..\MediaBrowser.Model\Library\PlayAccess.cs">
 | 
				
			||||||
 | 
					      <Link>Library\PlayAccess.cs</Link>
 | 
				
			||||||
 | 
					    </Compile>
 | 
				
			||||||
    <Compile Include="..\MediaBrowser.Model\LiveTv\ChannelInfoDto.cs">
 | 
					    <Compile Include="..\MediaBrowser.Model\LiveTv\ChannelInfoDto.cs">
 | 
				
			||||||
      <Link>LiveTv\ChannelInfoDto.cs</Link>
 | 
					      <Link>LiveTv\ChannelInfoDto.cs</Link>
 | 
				
			||||||
    </Compile>
 | 
					    </Compile>
 | 
				
			||||||
 | 
				
			|||||||
@ -220,6 +220,9 @@
 | 
				
			|||||||
    <Compile Include="..\MediaBrowser.Model\IO\IZipClient.cs">
 | 
					    <Compile Include="..\MediaBrowser.Model\IO\IZipClient.cs">
 | 
				
			||||||
      <Link>IO\IZipClient.cs</Link>
 | 
					      <Link>IO\IZipClient.cs</Link>
 | 
				
			||||||
    </Compile>
 | 
					    </Compile>
 | 
				
			||||||
 | 
					    <Compile Include="..\MediaBrowser.Model\Library\PlayAccess.cs">
 | 
				
			||||||
 | 
					      <Link>Library\PlayAccess.cs</Link>
 | 
				
			||||||
 | 
					    </Compile>
 | 
				
			||||||
    <Compile Include="..\MediaBrowser.Model\LiveTv\ChannelInfoDto.cs">
 | 
					    <Compile Include="..\MediaBrowser.Model\LiveTv\ChannelInfoDto.cs">
 | 
				
			||||||
      <Link>LiveTv\ChannelInfoDto.cs</Link>
 | 
					      <Link>LiveTv\ChannelInfoDto.cs</Link>
 | 
				
			||||||
    </Compile>
 | 
					    </Compile>
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,7 @@ using System.Collections.Generic;
 | 
				
			|||||||
using System.ComponentModel;
 | 
					using System.ComponentModel;
 | 
				
			||||||
using System.Diagnostics;
 | 
					using System.Diagnostics;
 | 
				
			||||||
using System.Runtime.Serialization;
 | 
					using System.Runtime.Serialization;
 | 
				
			||||||
 | 
					using MediaBrowser.Model.Library;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace MediaBrowser.Model.Dto
 | 
					namespace MediaBrowser.Model.Dto
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -154,12 +155,24 @@ namespace MediaBrowser.Model.Dto
 | 
				
			|||||||
        /// <value>The cumulative run time ticks.</value>
 | 
					        /// <value>The cumulative run time ticks.</value>
 | 
				
			||||||
        public long? CumulativeRunTimeTicks { get; set; }
 | 
					        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>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Gets or sets the run time ticks.
 | 
					        /// Gets or sets the run time ticks.
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <value>The run time ticks.</value>
 | 
					        /// <value>The run time ticks.</value>
 | 
				
			||||||
        public long? RunTimeTicks { get; set; }
 | 
					        public long? RunTimeTicks { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// Gets or sets the play access.
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <value>The play access.</value>
 | 
				
			||||||
 | 
					        public PlayAccess PlayAccess { get; set; }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Gets or sets the aspect ratio.
 | 
					        /// Gets or sets the aspect ratio.
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
 | 
				
			|||||||
@ -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
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										9
									
								
								MediaBrowser.Model/Library/PlayAccess.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								MediaBrowser.Model/Library/PlayAccess.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					namespace MediaBrowser.Model.Library
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public enum PlayAccess
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        Full = 0,
 | 
				
			||||||
 | 
					        None = 1
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -76,6 +76,7 @@
 | 
				
			|||||||
    <Compile Include="Entities\PackageReviewInfo.cs" />
 | 
					    <Compile Include="Entities\PackageReviewInfo.cs" />
 | 
				
			||||||
    <Compile Include="FileOrganization\FileOrganizationResult.cs" />
 | 
					    <Compile Include="FileOrganization\FileOrganizationResult.cs" />
 | 
				
			||||||
    <Compile Include="FileOrganization\FileOrganizationQuery.cs" />
 | 
					    <Compile Include="FileOrganization\FileOrganizationQuery.cs" />
 | 
				
			||||||
 | 
					    <Compile Include="Library\PlayAccess.cs" />
 | 
				
			||||||
    <Compile Include="LiveTv\ChannelInfoDto.cs" />
 | 
					    <Compile Include="LiveTv\ChannelInfoDto.cs" />
 | 
				
			||||||
    <Compile Include="LiveTv\ChannelQuery.cs" />
 | 
					    <Compile Include="LiveTv\ChannelQuery.cs" />
 | 
				
			||||||
    <Compile Include="LiveTv\ProgramInfoDto.cs" />
 | 
					    <Compile Include="LiveTv\ProgramInfoDto.cs" />
 | 
				
			||||||
 | 
				
			|||||||
@ -10,7 +10,6 @@ using MediaBrowser.Controller.Entities.TV;
 | 
				
			|||||||
using MediaBrowser.Controller.Library;
 | 
					using MediaBrowser.Controller.Library;
 | 
				
			||||||
using MediaBrowser.Controller.Persistence;
 | 
					using MediaBrowser.Controller.Persistence;
 | 
				
			||||||
using MediaBrowser.Controller.Session;
 | 
					using MediaBrowser.Controller.Session;
 | 
				
			||||||
using MediaBrowser.Model.Configuration;
 | 
					 | 
				
			||||||
using MediaBrowser.Model.Drawing;
 | 
					using MediaBrowser.Model.Drawing;
 | 
				
			||||||
using MediaBrowser.Model.Dto;
 | 
					using MediaBrowser.Model.Dto;
 | 
				
			||||||
using MediaBrowser.Model.Entities;
 | 
					using MediaBrowser.Model.Entities;
 | 
				
			||||||
@ -185,6 +184,8 @@ namespace MediaBrowser.Server.Implementations.Dto
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                dto.UserData.Played = dto.PlayedPercentage.HasValue && dto.PlayedPercentage.Value >= 100;
 | 
					                dto.UserData.Played = dto.PlayedPercentage.HasValue && dto.PlayedPercentage.Value >= 100;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            dto.PlayAccess = item.GetPlayAccess(user);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private int GetChildCount(Folder folder, User user)
 | 
					        private int GetChildCount(Folder folder, User user)
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,7 @@ using MediaBrowser.Controller.Library;
 | 
				
			|||||||
using MediaBrowser.Controller.Persistence;
 | 
					using MediaBrowser.Controller.Persistence;
 | 
				
			||||||
using MediaBrowser.Controller.Session;
 | 
					using MediaBrowser.Controller.Session;
 | 
				
			||||||
using MediaBrowser.Model.Entities;
 | 
					using MediaBrowser.Model.Entities;
 | 
				
			||||||
 | 
					using MediaBrowser.Model.Library;
 | 
				
			||||||
using MediaBrowser.Model.Logging;
 | 
					using MediaBrowser.Model.Logging;
 | 
				
			||||||
using MediaBrowser.Model.Session;
 | 
					using MediaBrowser.Model.Session;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
@ -604,20 +605,20 @@ namespace MediaBrowser.Server.Implementations.Session
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            var session = GetSessionForRemoteControl(sessionId);
 | 
					            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)
 | 
					            if (session.UserId.HasValue)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                var user = _userManager.GetUserById(session.UserId.Value);
 | 
					                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));
 | 
					                    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 (command.PlayCommand != PlayCommand.PlayNow)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if (items.Any(i => !session.QueueableMediaTypes.Contains(i.MediaType, StringComparer.OrdinalIgnoreCase)))
 | 
					                if (items.Any(i => !session.QueueableMediaTypes.Contains(i.MediaType, StringComparer.OrdinalIgnoreCase)))
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user