From afe9ed977b9b1fe83cb0132ddf753040a4bb95e3 Mon Sep 17 00:00:00 2001 From: dkanada Date: Sat, 1 Feb 2020 22:44:27 +0900 Subject: improve scan progress and fix a few bugs --- Emby.Server.Implementations/Session/SessionManager.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'Emby.Server.Implementations/Session') diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index b1d513dd4..72e4e151e 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -30,17 +30,17 @@ using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.Session { /// - /// Class SessionManager + /// Class SessionManager. /// public class SessionManager : ISessionManager, IDisposable { /// - /// The _user data repository + /// The user data repository. /// private readonly IUserDataManager _userDataManager; /// - /// The _logger + /// The logger. /// private readonly ILogger _logger; @@ -57,7 +57,7 @@ namespace Emby.Server.Implementations.Session private readonly IDeviceManager _deviceManager; /// - /// The _active connections + /// The active connections. /// private readonly ConcurrentDictionary _activeConnections = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); @@ -70,18 +70,23 @@ namespace Emby.Server.Implementations.Session /// Occurs when [playback start]. /// public event EventHandler PlaybackStart; + /// /// Occurs when [playback progress]. /// public event EventHandler PlaybackProgress; + /// /// Occurs when [playback stopped]. /// public event EventHandler PlaybackStopped; public event EventHandler SessionStarted; + public event EventHandler CapabilitiesChanged; + public event EventHandler SessionEnded; + public event EventHandler SessionActivity; public SessionManager( @@ -924,7 +929,6 @@ namespace Emby.Server.Implementations.Session ClientName = session.Client, DeviceId = session.DeviceId, Session = session - }, _logger); } @@ -1610,7 +1614,7 @@ namespace Emby.Server.Implementations.Session private DtoOptions _itemInfoDtoOptions; /// - /// Converts a BaseItem to a BaseItemInfo + /// Converts a BaseItem to a BaseItemInfo. /// private BaseItemDto GetItemInfo(BaseItem item, MediaSourceInfo mediaSource) { @@ -1680,7 +1684,7 @@ namespace Emby.Server.Implementations.Session } catch (Exception ex) { - _logger.LogError("Error getting {0} image info", ex, type); + _logger.LogError("Error getting image information for {0}", ex, type); return null; } } -- cgit v1.2.3 From 7df6f8d54e4d7eb8efd261b9ce5138c3efa9a364 Mon Sep 17 00:00:00 2001 From: dkanada Date: Sat, 1 Feb 2020 23:14:27 +0900 Subject: update error message Co-Authored-By: Bond-009 --- Emby.Server.Implementations/Session/SessionManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Emby.Server.Implementations/Session') diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index 72e4e151e..0bba19f2a 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -1684,7 +1684,7 @@ namespace Emby.Server.Implementations.Session } catch (Exception ex) { - _logger.LogError("Error getting image information for {0}", ex, type); + _logger.LogError(ex, "Error getting image information for {Type}", type); return null; } } -- cgit v1.2.3 From 6341d986a95be928a85ecd81c08fefdc5c3ec3b6 Mon Sep 17 00:00:00 2001 From: dkanada Date: Sun, 2 Feb 2020 00:07:46 +0900 Subject: fix a few warnings --- .../Session/SessionManager.cs | 30 +++++++++++----------- MediaBrowser.Api/Session/SessionsService.cs | 10 +++----- MediaBrowser.Api/UserLibrary/PlaystateService.cs | 4 --- MediaBrowser.Api/UserService.cs | 2 +- MediaBrowser.Controller/Session/SessionInfo.cs | 7 ----- 5 files changed, 19 insertions(+), 34 deletions(-) (limited to 'Emby.Server.Implementations/Session') diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index b1d513dd4..ec3e87573 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -67,15 +67,15 @@ namespace Emby.Server.Implementations.Session public event EventHandler> AuthenticationSucceeded; /// - /// Occurs when [playback start]. + /// Occurs when playback has started. /// public event EventHandler PlaybackStart; /// - /// Occurs when [playback progress]. + /// Occurs when playback has progressed. /// public event EventHandler PlaybackProgress; /// - /// Occurs when [playback stopped]. + /// Occurs when playback has stopped. /// public event EventHandler PlaybackStopped; @@ -685,7 +685,7 @@ namespace Emby.Server.Implementations.Session } /// - /// Used to report playback progress for an item + /// Used to report playback progress for an item. /// /// Task. public async Task OnPlaybackProgress(PlaybackProgressInfo info, bool isAutomated) @@ -1435,14 +1435,13 @@ namespace Emby.Server.Implementations.Session DeviceId = deviceId, UserId = user.Id, Limit = 1 - }).Items.FirstOrDefault(); - var allExistingForDevice = _authRepo.Get(new AuthenticationInfoQuery - { - DeviceId = deviceId - - }).Items; + var allExistingForDevice = _authRepo.Get( + new AuthenticationInfoQuery + { + DeviceId = deviceId + }).Items; foreach (var auth in allExistingForDevice) { @@ -1499,8 +1498,7 @@ namespace Emby.Server.Implementations.Session { Limit = 1, AccessToken = accessToken - - }).Items.FirstOrDefault(); + }).Items[0]; if (existing != null) { @@ -1708,7 +1706,8 @@ namespace Emby.Server.Implementations.Session public void ReportTranscodingInfo(string deviceId, TranscodingInfo info) { - var session = Sessions.FirstOrDefault(i => string.Equals(i.DeviceId, deviceId)); + var session = Sessions.FirstOrDefault(i => + string.Equals(i.DeviceId, deviceId, StringComparison.OrdinalIgnoreCase)); if (session != null) { @@ -1723,8 +1722,9 @@ namespace Emby.Server.Implementations.Session public SessionInfo GetSession(string deviceId, string client, string version) { - return Sessions.FirstOrDefault(i => string.Equals(i.DeviceId, deviceId) && - string.Equals(i.Client, client)); + return Sessions.FirstOrDefault(i => + string.Equals(i.DeviceId, deviceId, StringComparison.OrdinalIgnoreCase) + && string.Equals(i.Client, client, StringComparison.OrdinalIgnoreCase)); } public SessionInfo GetSessionByAuthenticationToken(AuthenticationInfo info, string deviceId, string remoteEndpoint, string appVersion) diff --git a/MediaBrowser.Api/Session/SessionsService.cs b/MediaBrowser.Api/Session/SessionsService.cs index 700861c55..8e53490ff 100644 --- a/MediaBrowser.Api/Session/SessionsService.cs +++ b/MediaBrowser.Api/Session/SessionsService.cs @@ -276,7 +276,7 @@ namespace MediaBrowser.Api.Session public class SessionsService : BaseApiService { /// - /// The _session manager. + /// The session manager. /// private readonly ISessionManager _sessionManager; @@ -438,14 +438,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 +516,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,6 +533,7 @@ namespace MediaBrowser.Api.Session { request.Id = GetSession(_sessionContext).Id; } + _sessionManager.ReportCapabilities(request.Id, request); } } 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; } - /// - /// Gets or sets a value indicating whether this is likes. - /// - /// true if likes; otherwise, false. [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 e1b01b012..3b82dd9dd 100644 --- a/MediaBrowser.Api/UserService.cs +++ b/MediaBrowser.Api/UserService.cs @@ -240,7 +240,7 @@ namespace MediaBrowser.Api public class UserService : BaseApiService { /// - /// The _user manager + /// The user manager. /// private readonly IUserManager _userManager; private readonly ISessionManager _sessionMananger; diff --git a/MediaBrowser.Controller/Session/SessionInfo.cs b/MediaBrowser.Controller/Session/SessionInfo.cs index acda6a416..964fc9b19 100644 --- a/MediaBrowser.Controller/Session/SessionInfo.cs +++ b/MediaBrowser.Controller/Session/SessionInfo.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using System.Text.Json.Serialization; using System.Threading; using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Dto; @@ -123,7 +122,6 @@ namespace MediaBrowser.Controller.Session /// Gets or sets the session controller. /// /// The session controller. - [JsonIgnore] public ISessionController[] SessionControllers { get; set; } /// @@ -245,11 +243,6 @@ namespace MediaBrowser.Controller.Session SessionControllers = controllers.ToArray(); } - public bool ContainsUser(string userId) - { - return ContainsUser(new Guid(userId)); - } - public bool ContainsUser(Guid userId) { if (UserId.Equals(userId)) -- cgit v1.2.3 From 26dd67a441d251bef56c14d8058e7068e38e06af Mon Sep 17 00:00:00 2001 From: dkanada Date: Sun, 2 Feb 2020 00:09:18 +0900 Subject: change authentication flow --- Emby.Server.Implementations/Session/SessionManager.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'Emby.Server.Implementations/Session') diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index ec3e87573..659483a36 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -1379,20 +1379,16 @@ namespace Emby.Server.Implementations.Session user = _userManager.GetUserByName(request.Username); } - if (user != null) + if (user == null) { - // TODO: Move this to userManager? - if (!string.IsNullOrEmpty(request.DeviceId) - && !_deviceManager.CanAccessDevice(user, request.DeviceId)) - { - throw new SecurityException("User is not allowed access from this device."); - } + AuthenticationFailed?.Invoke(this, new GenericEventArgs(request)); + throw new SecurityException("Invalid username or password entered."); } - if (user == null) + if (!string.IsNullOrEmpty(request.DeviceId) + && !_deviceManager.CanAccessDevice(user, request.DeviceId)) { - AuthenticationFailed?.Invoke(this, new GenericEventArgs(request)); - throw new SecurityException("Invalid user or password entered."); + throw new SecurityException("User is not allowed access from this device."); } if (enforcePassword) -- cgit v1.2.3 From 1bc8ca25421dd3b66a58e1ff0938ee7874d8448e Mon Sep 17 00:00:00 2001 From: dkanada Date: Sun, 2 Feb 2020 00:16:11 +0900 Subject: add session view endpoint --- Emby.Server.Implementations/Session/SessionManager.cs | 10 +++++----- MediaBrowser.Api/Session/SessionsService.cs | 18 ++++++++++++++++++ MediaBrowser.Controller/Session/SessionInfo.cs | 2 ++ 3 files changed, 25 insertions(+), 5 deletions(-) (limited to 'Emby.Server.Implementations/Session') diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index 659483a36..8e52f2415 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -1686,18 +1686,18 @@ namespace Emby.Server.Implementations.Session throw new ArgumentNullException(nameof(itemId)); } - //var item = _libraryManager.GetItemById(new Guid(itemId)); + var item = _libraryManager.GetItemById(new Guid(itemId)); - //var info = GetItemInfo(item, null, null); + var info = GetItemInfo(item, null); - //ReportNowViewingItem(sessionId, info); + ReportNowViewingItem(sessionId, info); } public void ReportNowViewingItem(string sessionId, BaseItemDto item) { - //var session = GetSession(sessionId); + var session = GetSession(sessionId); - //session.NowViewingItem = item; + session.NowViewingItem = item; } public void ReportTranscodingInfo(string deviceId, TranscodingInfo info) diff --git a/MediaBrowser.Api/Session/SessionsService.cs b/MediaBrowser.Api/Session/SessionsService.cs index 8e53490ff..df816927a 100644 --- a/MediaBrowser.Api/Session/SessionsService.cs +++ b/MediaBrowser.Api/Session/SessionsService.cs @@ -230,6 +230,17 @@ namespace MediaBrowser.Api.Session public string Id { get; set; } } + [Route("/Sessions/Viewing", "POST", Summary = "Reports that a session is viewing an item")] + [Authenticated] + 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("/Sessions/Logout", "POST", Summary = "Reports that a session has ended")] [Authenticated] public class ReportSessionEnded : IReturnVoid @@ -536,5 +547,12 @@ namespace MediaBrowser.Api.Session _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.Controller/Session/SessionInfo.cs b/MediaBrowser.Controller/Session/SessionInfo.cs index 964fc9b19..7bc50eb41 100644 --- a/MediaBrowser.Controller/Session/SessionInfo.cs +++ b/MediaBrowser.Controller/Session/SessionInfo.cs @@ -106,6 +106,8 @@ namespace MediaBrowser.Controller.Session public BaseItem FullNowPlayingItem { get; set; } + public BaseItemDto NowViewingItem { get; set; } + /// /// Gets or sets the device id. /// -- cgit v1.2.3 From f93edb7ade68588f4e2e7e05932b3266105ea91a Mon Sep 17 00:00:00 2001 From: dkanada Date: Tue, 4 Feb 2020 01:29:18 +0900 Subject: add code suggestions --- Emby.Server.Implementations/Session/SessionManager.cs | 2 +- MediaBrowser.Controller/Session/SessionInfo.cs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'Emby.Server.Implementations/Session') diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index 8e52f2415..4aed226de 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -1494,7 +1494,7 @@ namespace Emby.Server.Implementations.Session { Limit = 1, AccessToken = accessToken - }).Items[0]; + }).Items.FirstOrDefault(); if (existing != null) { diff --git a/MediaBrowser.Controller/Session/SessionInfo.cs b/MediaBrowser.Controller/Session/SessionInfo.cs index 7bc50eb41..cc5160d77 100644 --- a/MediaBrowser.Controller/Session/SessionInfo.cs +++ b/MediaBrowser.Controller/Session/SessionInfo.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Text.Json.Serialization; using System.Threading; using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Dto; @@ -124,6 +125,7 @@ namespace MediaBrowser.Controller.Session /// Gets or sets the session controller. /// /// The session controller. + [JsonIgnore] public ISessionController[] SessionControllers { get; set; } /// -- cgit v1.2.3