diff options
Diffstat (limited to 'MediaBrowser.Api')
| -rw-r--r-- | MediaBrowser.Api/Images/ImageService.cs | 26 | ||||
| -rw-r--r-- | MediaBrowser.Api/Playback/BaseStreamingService.cs | 24 | ||||
| -rw-r--r-- | MediaBrowser.Api/Sessions/ApiKeyService.cs | 85 | ||||
| -rw-r--r-- | MediaBrowser.Api/Sessions/SessionInfoWebSocketListener.cs (renamed from MediaBrowser.Api/Session/SessionInfoWebSocketListener.cs) | 2 | ||||
| -rw-r--r-- | MediaBrowser.Api/Sessions/SessionService.cs (renamed from MediaBrowser.Api/Session/SessionsService.cs) | 100 | ||||
| -rw-r--r-- | MediaBrowser.Api/UserLibrary/PlaystateService.cs | 4 | ||||
| -rw-r--r-- | MediaBrowser.Api/UserService.cs | 2 |
7 files changed, 133 insertions, 110 deletions
diff --git a/MediaBrowser.Api/Images/ImageService.cs b/MediaBrowser.Api/Images/ImageService.cs index c55618aa1..af455987b 100644 --- a/MediaBrowser.Api/Images/ImageService.cs +++ b/MediaBrowser.Api/Images/ImageService.cs @@ -24,7 +24,7 @@ using Microsoft.Net.Http.Headers; namespace MediaBrowser.Api.Images { /// <summary> - /// Class GetItemImage + /// Class GetItemImage. /// </summary> [Route("/Items/{Id}/Images", "GET", Summary = "Gets information about an item's images")] [Authenticated] @@ -558,21 +558,6 @@ namespace MediaBrowser.Api.Images throw new ResourceNotFoundException(string.Format("{0} does not have an image of type {1}", displayText, request.Type)); } - IImageEnhancer[] supportedImageEnhancers; - if (_imageProcessor.ImageEnhancers.Count > 0) - { - if (item == null) - { - item = _libraryManager.GetItemById(itemId); - } - - supportedImageEnhancers = request.EnableImageEnhancers ? _imageProcessor.GetSupportedEnhancers(item, request.Type).ToArray() : Array.Empty<IImageEnhancer>(); - } - else - { - supportedImageEnhancers = Array.Empty<IImageEnhancer>(); - } - bool cropwhitespace; if (request.CropWhitespace.HasValue) { @@ -598,25 +583,25 @@ namespace MediaBrowser.Api.Images {"realTimeInfo.dlna.org", "DLNA.ORG_TLAG=*"} }; - return GetImageResult(item, + return GetImageResult( + item, itemId, request, imageInfo, cropwhitespace, outputFormats, - supportedImageEnhancers, cacheDuration, responseHeaders, isHeadRequest); } - private async Task<object> GetImageResult(BaseItem item, + private async Task<object> GetImageResult( + BaseItem item, Guid itemId, ImageRequest request, ItemImageInfo image, bool cropwhitespace, IReadOnlyCollection<ImageFormat> supportedFormats, - IReadOnlyCollection<IImageEnhancer> enhancers, TimeSpan? cacheDuration, IDictionary<string, string> headers, bool isHeadRequest) @@ -624,7 +609,6 @@ namespace MediaBrowser.Api.Images var options = new ImageProcessingOptions { CropWhiteSpace = cropwhitespace, - Enhancers = enhancers, Height = request.Height, ImageIndex = request.Index ?? 0, Image = image, diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index ab74bab1c..5029ce0bb 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -250,11 +250,11 @@ namespace MediaBrowser.Api.Playback { if (string.Equals(state.OutputAudioCodec, "copy", StringComparison.OrdinalIgnoreCase)) { - logFilePrefix = "ffmpeg-directstream"; + logFilePrefix = "ffmpeg-remux"; } else { - logFilePrefix = "ffmpeg-remux"; + logFilePrefix = "ffmpeg-directstream"; } } @@ -327,15 +327,19 @@ namespace MediaBrowser.Api.Playback private bool EnableThrottling(StreamState state) { + var encodingOptions = ServerConfigurationManager.GetEncodingOptions(); + + // enable throttling when NOT using hardware acceleration + if (encodingOptions.HardwareAccelerationType == string.Empty) + { + return state.InputProtocol == MediaProtocol.File && + state.RunTimeTicks.HasValue && + state.RunTimeTicks.Value >= TimeSpan.FromMinutes(5).Ticks && + state.IsInputVideo && + state.VideoType == VideoType.VideoFile && + !string.Equals(state.OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase); + } return false; - //// do not use throttling with hardware encoders - //return state.InputProtocol == MediaProtocol.File && - // state.RunTimeTicks.HasValue && - // state.RunTimeTicks.Value >= TimeSpan.FromMinutes(5).Ticks && - // state.IsInputVideo && - // state.VideoType == VideoType.VideoFile && - // !string.Equals(state.OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase) && - // string.Equals(GetVideoEncoder(state), "libx264", StringComparison.OrdinalIgnoreCase); } /// <summary> diff --git a/MediaBrowser.Api/Sessions/ApiKeyService.cs b/MediaBrowser.Api/Sessions/ApiKeyService.cs new file mode 100644 index 000000000..5102ce0a7 --- /dev/null +++ b/MediaBrowser.Api/Sessions/ApiKeyService.cs @@ -0,0 +1,85 @@ +using System; +using System.Globalization; +using MediaBrowser.Controller; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Net; +using MediaBrowser.Controller.Security; +using MediaBrowser.Controller.Session; +using MediaBrowser.Model.Services; +using Microsoft.Extensions.Logging; + +namespace MediaBrowser.Api.Sessions +{ + [Route("/Auth/Keys", "GET")] + [Authenticated(Roles = "Admin")] + public class GetKeys + { + } + + [Route("/Auth/Keys/{Key}", "DELETE")] + [Authenticated(Roles = "Admin")] + public class RevokeKey + { + [ApiMember(Name = "Key", Description = "Authentication key", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")] + public string Key { get; set; } + } + + [Route("/Auth/Keys", "POST")] + [Authenticated(Roles = "Admin")] + public class CreateKey + { + [ApiMember(Name = "App", Description = "Name of the app using the authentication key", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] + public string App { get; set; } + } + + public class ApiKeyService : BaseApiService + { + private readonly ISessionManager _sessionManager; + + private readonly IAuthenticationRepository _authRepo; + + private readonly IServerApplicationHost _appHost; + + public ApiKeyService( + ILogger<ApiKeyService> logger, + IServerConfigurationManager serverConfigurationManager, + IHttpResultFactory httpResultFactory, + ISessionManager sessionManager, + IServerApplicationHost appHost, + IAuthenticationRepository authRepo) + : base(logger, serverConfigurationManager, httpResultFactory) + { + _sessionManager = sessionManager; + _authRepo = authRepo; + _appHost = appHost; + } + + public void Delete(RevokeKey request) + { + _sessionManager.RevokeToken(request.Key); + } + + public void Post(CreateKey request) + { + _authRepo.Create(new AuthenticationInfo + { + AppName = request.App, + AccessToken = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture), + DateCreated = DateTime.UtcNow, + DeviceId = _appHost.SystemId, + DeviceName = _appHost.FriendlyName, + AppVersion = _appHost.ApplicationVersionString + }); + } + + public object Get(GetKeys request) + { + var result = _authRepo.Get(new AuthenticationInfoQuery + { + HasUser = false + }); + + return result; + } + } +} diff --git a/MediaBrowser.Api/Session/SessionInfoWebSocketListener.cs b/MediaBrowser.Api/Sessions/SessionInfoWebSocketListener.cs index f1a6622fb..051d09850 100644 --- a/MediaBrowser.Api/Session/SessionInfoWebSocketListener.cs +++ b/MediaBrowser.Api/Sessions/SessionInfoWebSocketListener.cs @@ -5,7 +5,7 @@ using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Session; using Microsoft.Extensions.Logging; -namespace MediaBrowser.Api.Session +namespace MediaBrowser.Api.Sessions { /// <summary> /// Class SessionInfoWebSocketListener diff --git a/MediaBrowser.Api/Session/SessionsService.cs b/MediaBrowser.Api/Sessions/SessionService.cs index 9aa7b2c88..020bb5042 100644 --- a/MediaBrowser.Api/Session/SessionsService.cs +++ b/MediaBrowser.Api/Sessions/SessionService.cs @@ -1,21 +1,18 @@ using System; -using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; -using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Devices; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Net; -using MediaBrowser.Controller.Security; using MediaBrowser.Controller.Session; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Services; using MediaBrowser.Model.Session; using Microsoft.Extensions.Logging; -namespace MediaBrowser.Api.Session +namespace MediaBrowser.Api.Sessions { /// <summary> /// Class GetSessions. @@ -24,10 +21,10 @@ namespace MediaBrowser.Api.Session [Authenticated] public class GetSessions : IReturn<SessionInfo[]> { - [ApiMember(Name = "ControllableByUserId", Description = "Optional. Filter by sessions that a given user is allowed to remote control.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + [ApiMember(Name = "ControllableByUserId", Description = "Filter by sessions that a given user is allowed to remote control.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public Guid ControllableByUserId { get; set; } - [ApiMember(Name = "DeviceId", Description = "Optional. Filter by device id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + [ApiMember(Name = "DeviceId", Description = "Filter by device Id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string DeviceId { get; set; } public int? ActiveWithinSeconds { get; set; } @@ -182,7 +179,7 @@ namespace MediaBrowser.Api.Session [ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")] public string Id { get; set; } - [ApiMember(Name = "UserId", Description = "UserId Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")] + [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")] public string UserId { get; set; } } @@ -230,15 +227,20 @@ namespace MediaBrowser.Api.Session public string Id { get; set; } } - [Route("/Sessions/Logout", "POST", Summary = "Reports that a session has ended")] + [Route("/Sessions/Viewing", "POST", Summary = "Reports that a session is viewing an item")] [Authenticated] - public class ReportSessionEnded : IReturnVoid + public class ReportViewing : IReturnVoid { + [ApiMember(Name = "SessionId", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] + public string SessionId { get; set; } + + [ApiMember(Name = "ItemId", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] + public string ItemId { get; set; } } - [Route("/Auth/Keys", "GET")] - [Authenticated(Roles = "Admin")] - public class GetApiKeys + [Route("/Sessions/Logout", "POST", Summary = "Reports that a session has ended")] + [Authenticated] + public class ReportSessionEnded : IReturnVoid { } @@ -254,48 +256,28 @@ namespace MediaBrowser.Api.Session { } - [Route("/Auth/Keys/{Key}", "DELETE")] - [Authenticated(Roles = "Admin")] - public class RevokeKey - { - [ApiMember(Name = "Key", Description = "Auth Key", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")] - public string Key { get; set; } - } - - [Route("/Auth/Keys", "POST")] - [Authenticated(Roles = "Admin")] - public class CreateKey - { - [ApiMember(Name = "App", Description = "App", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] - public string App { get; set; } - } - /// <summary> /// Class SessionsService. /// </summary> - public class SessionsService : BaseApiService + public class SessionService : BaseApiService { /// <summary> - /// The _session manager. + /// The session manager. /// </summary> private readonly ISessionManager _sessionManager; private readonly IUserManager _userManager; private readonly IAuthorizationContext _authContext; - private readonly IAuthenticationRepository _authRepo; private readonly IDeviceManager _deviceManager; private readonly ISessionContext _sessionContext; - private readonly IServerApplicationHost _appHost; - public SessionsService( - ILogger<SessionsService> logger, + public SessionService( + ILogger<SessionService> logger, IServerConfigurationManager serverConfigurationManager, IHttpResultFactory httpResultFactory, ISessionManager sessionManager, - IServerApplicationHost appHost, IUserManager userManager, IAuthorizationContext authContext, - IAuthenticationRepository authRepo, IDeviceManager deviceManager, ISessionContext sessionContext) : base(logger, serverConfigurationManager, httpResultFactory) @@ -303,10 +285,8 @@ namespace MediaBrowser.Api.Session _sessionManager = sessionManager; _userManager = userManager; _authContext = authContext; - _authRepo = authRepo; _deviceManager = deviceManager; _sessionContext = sessionContext; - _appHost = appHost; } public object Get(GetAuthProviders request) @@ -319,25 +299,6 @@ namespace MediaBrowser.Api.Session return _userManager.GetPasswordResetProviders(); } - public void Delete(RevokeKey request) - { - _sessionManager.RevokeToken(request.Key); - - } - - public void Post(CreateKey request) - { - _authRepo.Create(new AuthenticationInfo - { - AppName = request.App, - AccessToken = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture), - DateCreated = DateTime.UtcNow, - DeviceId = _appHost.SystemId, - DeviceName = _appHost.FriendlyName, - AppVersion = _appHost.ApplicationVersionString - }); - } - public void Post(ReportSessionEnded request) { var auth = _authContext.GetAuthorizationInfo(Request); @@ -345,16 +306,6 @@ namespace MediaBrowser.Api.Session _sessionManager.Logout(auth.Token); } - public object Get(GetApiKeys request) - { - var result = _authRepo.Get(new AuthenticationInfoQuery - { - HasUser = false - }); - - return result; - } - /// <summary> /// Gets the specified request. /// </summary> @@ -438,14 +389,12 @@ namespace MediaBrowser.Api.Session public Task Post(SendSystemCommand request) { var name = request.Command; - if (Enum.TryParse(name, true, out GeneralCommandType commandType)) { name = commandType.ToString(); } var currentSession = GetSession(_sessionContext); - var command = new GeneralCommand { Name = name, @@ -518,16 +467,13 @@ namespace MediaBrowser.Api.Session { request.Id = GetSession(_sessionContext).Id; } + _sessionManager.ReportCapabilities(request.Id, new ClientCapabilities { PlayableMediaTypes = SplitValue(request.PlayableMediaTypes, ','), - SupportedCommands = SplitValue(request.SupportedCommands, ','), - SupportsMediaControl = request.SupportsMediaControl, - SupportsSync = request.SupportsSync, - SupportsPersistentIdentifier = request.SupportsPersistentIdentifier }); } @@ -538,7 +484,15 @@ namespace MediaBrowser.Api.Session { request.Id = GetSession(_sessionContext).Id; } + _sessionManager.ReportCapabilities(request.Id, request); } + + public void Post(ReportViewing request) + { + request.SessionId = GetSession(_sessionContext).Id; + + _sessionManager.ReportNowViewingItem(request.SessionId, request.ItemId); + } } } diff --git a/MediaBrowser.Api/UserLibrary/PlaystateService.cs b/MediaBrowser.Api/UserLibrary/PlaystateService.cs index 9d1cf5d9e..d0faca163 100644 --- a/MediaBrowser.Api/UserLibrary/PlaystateService.cs +++ b/MediaBrowser.Api/UserLibrary/PlaystateService.cs @@ -103,10 +103,6 @@ namespace MediaBrowser.Api.UserLibrary [ApiMember(Name = "MediaSourceId", Description = "The id of the MediaSource", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] public string MediaSourceId { get; set; } - /// <summary> - /// Gets or sets a value indicating whether this <see cref="UpdateUserItemRating" /> is likes. - /// </summary> - /// <value><c>true</c> if likes; otherwise, <c>false</c>.</value> [ApiMember(Name = "CanSeek", Description = "Indicates if the client can seek", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "POST")] public bool CanSeek { get; set; } diff --git a/MediaBrowser.Api/UserService.cs b/MediaBrowser.Api/UserService.cs index ac140150b..401514349 100644 --- a/MediaBrowser.Api/UserService.cs +++ b/MediaBrowser.Api/UserService.cs @@ -240,7 +240,7 @@ namespace MediaBrowser.Api public class UserService : BaseApiService { /// <summary> - /// The _user manager + /// The user manager. /// </summary> private readonly IUserManager _userManager; private readonly ISessionManager _sessionMananger; |
