From ccb2dda358a54810d940c0c7ddceb255a82ae947 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 8 Mar 2015 15:48:30 -0400 Subject: connect to socket with access token --- .../HttpServer/Security/SessionContext.cs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'MediaBrowser.Server.Implementations/HttpServer/Security') diff --git a/MediaBrowser.Server.Implementations/HttpServer/Security/SessionContext.cs b/MediaBrowser.Server.Implementations/HttpServer/Security/SessionContext.cs index 9d1ddb7fc..954db3a9d 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/Security/SessionContext.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/Security/SessionContext.cs @@ -23,6 +23,10 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security { var authorization = _authContext.GetAuthorizationInfo(requestContext); + if (!string.IsNullOrWhiteSpace(authorization.Token)) + { + return _sessionManager.GetSessionByAuthenticationToken(authorization.Token); + } return _sessionManager.GetSession(authorization.DeviceId, authorization.Client, authorization.Version); } -- cgit v1.2.3 From 1b46fb62c48c86e5f9aed9426a90702e2d392bb6 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 9 Mar 2015 15:40:03 -0400 Subject: fix session not found errors --- MediaBrowser.Api/BaseApiService.cs | 7 +- MediaBrowser.Api/LiveTv/LiveTvService.cs | 2 +- MediaBrowser.Api/Session/SessionsService.cs | 18 ++--- MediaBrowser.Api/UserLibrary/PlaystateService.cs | 10 +-- MediaBrowser.Controller/Net/ISessionContext.cs | 11 +-- MediaBrowser.Controller/Session/ISessionManager.cs | 13 +++- .../HttpServer/Security/SessionContext.cs | 30 +++++--- .../Session/SessionManager.cs | 89 +++++++++++++--------- .../Session/SessionWebSocketListener.cs | 13 ++-- 9 files changed, 118 insertions(+), 75 deletions(-) (limited to 'MediaBrowser.Server.Implementations/HttpServer/Security') diff --git a/MediaBrowser.Api/BaseApiService.cs b/MediaBrowser.Api/BaseApiService.cs index dff433c9d..91e1c7d9a 100644 --- a/MediaBrowser.Api/BaseApiService.cs +++ b/MediaBrowser.Api/BaseApiService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Dto; +using System.Threading.Tasks; +using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; @@ -88,9 +89,9 @@ namespace MediaBrowser.Api /// Gets the session. /// /// SessionInfo. - protected SessionInfo GetSession() + protected async Task GetSession() { - var session = SessionContext.GetSession(Request); + var session = await SessionContext.GetSession(Request).ConfigureAwait(false); if (session == null) { diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs index fe21b9ada..f3fd8f42a 100644 --- a/MediaBrowser.Api/LiveTv/LiveTvService.cs +++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs @@ -315,7 +315,7 @@ namespace MediaBrowser.Api.LiveTv private void AssertUserCanManageLiveTv() { - var user = SessionContext.GetUser(Request); + var user = SessionContext.GetUser(Request).Result; if (user == null) { diff --git a/MediaBrowser.Api/Session/SessionsService.cs b/MediaBrowser.Api/Session/SessionsService.cs index 319b3d28c..52ecb95ec 100644 --- a/MediaBrowser.Api/Session/SessionsService.cs +++ b/MediaBrowser.Api/Session/SessionsService.cs @@ -418,7 +418,7 @@ namespace MediaBrowser.Api.Session SeekPositionTicks = request.SeekPositionTicks }; - var task = _sessionManager.SendPlaystateCommand(GetSession().Id, request.Id, command, CancellationToken.None); + var task = _sessionManager.SendPlaystateCommand(GetSession().Result.Id, request.Id, command, CancellationToken.None); Task.WaitAll(task); } @@ -436,7 +436,7 @@ namespace MediaBrowser.Api.Session ItemType = request.ItemType }; - var task = _sessionManager.SendBrowseCommand(GetSession().Id, request.Id, command, CancellationToken.None); + var task = _sessionManager.SendBrowseCommand(GetSession().Result.Id, request.Id, command, CancellationToken.None); Task.WaitAll(task); } @@ -455,7 +455,7 @@ namespace MediaBrowser.Api.Session name = commandType.ToString(); } - var currentSession = GetSession(); + var currentSession = GetSession().Result; var command = new GeneralCommand { @@ -481,7 +481,7 @@ namespace MediaBrowser.Api.Session Text = request.Text }; - var task = _sessionManager.SendMessageCommand(GetSession().Id, request.Id, command, CancellationToken.None); + var task = _sessionManager.SendMessageCommand(GetSession().Result.Id, request.Id, command, CancellationToken.None); Task.WaitAll(task); } @@ -500,14 +500,14 @@ namespace MediaBrowser.Api.Session StartPositionTicks = request.StartPositionTicks }; - var task = _sessionManager.SendPlayCommand(GetSession().Id, request.Id, command, CancellationToken.None); + var task = _sessionManager.SendPlayCommand(GetSession().Result.Id, request.Id, command, CancellationToken.None); Task.WaitAll(task); } public void Post(SendGeneralCommand request) { - var currentSession = GetSession(); + var currentSession = GetSession().Result; var command = new GeneralCommand { @@ -522,7 +522,7 @@ namespace MediaBrowser.Api.Session public void Post(SendFullGeneralCommand request) { - var currentSession = GetSession(); + var currentSession = GetSession().Result; request.ControllingUserId = currentSession.UserId.HasValue ? currentSession.UserId.Value.ToString("N") : null; @@ -545,7 +545,7 @@ namespace MediaBrowser.Api.Session { if (string.IsNullOrWhiteSpace(request.Id)) { - request.Id = GetSession().Id; + request.Id = GetSession().Result.Id; } _sessionManager.ReportCapabilities(request.Id, new ClientCapabilities { @@ -569,7 +569,7 @@ namespace MediaBrowser.Api.Session { if (string.IsNullOrWhiteSpace(request.Id)) { - request.Id = GetSession().Id; + request.Id = GetSession().Result.Id; } _sessionManager.ReportCapabilities(request.Id, request); } diff --git a/MediaBrowser.Api/UserLibrary/PlaystateService.cs b/MediaBrowser.Api/UserLibrary/PlaystateService.cs index fae83e369..55e1681e0 100644 --- a/MediaBrowser.Api/UserLibrary/PlaystateService.cs +++ b/MediaBrowser.Api/UserLibrary/PlaystateService.cs @@ -231,7 +231,7 @@ namespace MediaBrowser.Api.UserLibrary datePlayed = DateTime.ParseExact(request.DatePlayed, "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); } - var session = GetSession(); + var session = await GetSession().ConfigureAwait(false); var dto = await UpdatePlayedStatus(user, request.Id, true, datePlayed).ConfigureAwait(false); @@ -266,7 +266,7 @@ namespace MediaBrowser.Api.UserLibrary public void Post(ReportPlaybackStart request) { - request.SessionId = GetSession().Id; + request.SessionId = GetSession().Result.Id; var task = _sessionManager.OnPlaybackStart(request); @@ -294,7 +294,7 @@ namespace MediaBrowser.Api.UserLibrary public void Post(ReportPlaybackProgress request) { - request.SessionId = GetSession().Id; + request.SessionId = GetSession().Result.Id; var task = _sessionManager.OnPlaybackProgress(request); @@ -317,7 +317,7 @@ namespace MediaBrowser.Api.UserLibrary public void Post(ReportPlaybackStopped request) { - request.SessionId = GetSession().Id; + request.SessionId = GetSession().Result.Id; var task = _sessionManager.OnPlaybackStopped(request); @@ -339,7 +339,7 @@ namespace MediaBrowser.Api.UserLibrary { var user = _userManager.GetUserById(request.UserId); - var session = GetSession(); + var session = await GetSession().ConfigureAwait(false); var dto = await UpdatePlayedStatus(user, request.Id, false, null).ConfigureAwait(false); diff --git a/MediaBrowser.Controller/Net/ISessionContext.cs b/MediaBrowser.Controller/Net/ISessionContext.cs index be8d28acc..167e17867 100644 --- a/MediaBrowser.Controller/Net/ISessionContext.cs +++ b/MediaBrowser.Controller/Net/ISessionContext.cs @@ -1,14 +1,15 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Session; +using System.Threading.Tasks; namespace MediaBrowser.Controller.Net { public interface ISessionContext { - SessionInfo GetSession(object requestContext); - User GetUser(object requestContext); - - SessionInfo GetSession(IServiceRequest requestContext); - User GetUser(IServiceRequest requestContext); + Task GetSession(object requestContext); + Task GetUser(object requestContext); + + Task GetSession(IServiceRequest requestContext); + Task GetUser(IServiceRequest requestContext); } } diff --git a/MediaBrowser.Controller/Session/ISessionManager.cs b/MediaBrowser.Controller/Session/ISessionManager.cs index b51b590cf..234a82346 100644 --- a/MediaBrowser.Controller/Session/ISessionManager.cs +++ b/MediaBrowser.Controller/Session/ISessionManager.cs @@ -1,5 +1,6 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Security; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Events; using MediaBrowser.Model.Session; @@ -282,8 +283,18 @@ namespace MediaBrowser.Controller.Session /// Gets the session by authentication token. /// /// The token. + /// The remote endpoint. /// SessionInfo. - SessionInfo GetSessionByAuthenticationToken(string token); + Task GetSessionByAuthenticationToken(string token, string remoteEndpoint); + + /// + /// Gets the session by authentication token. + /// + /// The information. + /// The remote endpoint. + /// The application version. + /// Task<SessionInfo>. + Task GetSessionByAuthenticationToken(AuthenticationInfo info, string remoteEndpoint, string appVersion); /// /// Logouts the specified access token. diff --git a/MediaBrowser.Server.Implementations/HttpServer/Security/SessionContext.cs b/MediaBrowser.Server.Implementations/HttpServer/Security/SessionContext.cs index 954db3a9d..0557f7528 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/Security/SessionContext.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/Security/SessionContext.cs @@ -1,8 +1,10 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Net; +using MediaBrowser.Controller.Security; using MediaBrowser.Controller.Session; using ServiceStack.Web; +using System.Threading.Tasks; namespace MediaBrowser.Server.Implementations.HttpServer.Security { @@ -19,31 +21,41 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security _sessionManager = sessionManager; } - public SessionInfo GetSession(IServiceRequest requestContext) + public Task GetSession(IServiceRequest requestContext) { var authorization = _authContext.GetAuthorizationInfo(requestContext); if (!string.IsNullOrWhiteSpace(authorization.Token)) { - return _sessionManager.GetSessionByAuthenticationToken(authorization.Token); + var auth = GetTokenInfo(requestContext); + return _sessionManager.GetSessionByAuthenticationToken(auth, requestContext.RemoteIp, authorization.Version); } - return _sessionManager.GetSession(authorization.DeviceId, authorization.Client, authorization.Version); + + var session = _sessionManager.GetSession(authorization.DeviceId, authorization.Client, authorization.Version); + return Task.FromResult(session); } - public User GetUser(IServiceRequest requestContext) + private AuthenticationInfo GetTokenInfo(IServiceRequest request) { - var session = GetSession(requestContext); - - return session == null || !session.UserId.HasValue ? null : _userManager.GetUserById(session.UserId.Value); + object info; + request.Items.TryGetValue("OriginalAuthenticationInfo", out info); + return info as AuthenticationInfo; } - public SessionInfo GetSession(object requestContext) + public Task GetSession(object requestContext) { var req = new ServiceStackServiceRequest((IRequest)requestContext); return GetSession(req); } - public User GetUser(object requestContext) + public async Task GetUser(IServiceRequest requestContext) + { + var session = await GetSession(requestContext).ConfigureAwait(false); + + return session == null || !session.UserId.HasValue ? null : _userManager.GetUserById(session.UserId.Value); + } + + public Task GetUser(object requestContext) { var req = new ServiceStackServiceRequest((IRequest)requestContext); return GetUser(req); diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index a09f585fd..2e28862e9 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -237,10 +237,7 @@ namespace MediaBrowser.Server.Implementations.Session var activityDate = DateTime.UtcNow; - var userId = user == null ? (Guid?)null : user.Id; - var username = user == null ? null : user.Name; - - var session = await GetSessionInfo(clientType, appVersion, deviceId, deviceName, remoteEndPoint, userId, username).ConfigureAwait(false); + var session = await GetSessionInfo(clientType, appVersion, deviceId, deviceName, remoteEndPoint, user).ConfigureAwait(false); session.LastActivityDate = activityDate; @@ -281,7 +278,7 @@ namespace MediaBrowser.Server.Implementations.Session if (session != null) { - var key = GetSessionKey(session.Client, session.ApplicationVersion, session.DeviceId); + var key = GetSessionKey(session.Client, session.DeviceId); SessionInfo removed; @@ -365,7 +362,7 @@ namespace MediaBrowser.Server.Implementations.Session } } - private string GetSessionKey(string clientType, string appVersion, string deviceId) + private string GetSessionKey(string clientType, string deviceId) { return clientType + deviceId; } @@ -378,29 +375,31 @@ namespace MediaBrowser.Server.Implementations.Session /// The device id. /// Name of the device. /// The remote end point. - /// The user identifier. - /// The username. + /// The user. /// SessionInfo. - private async Task GetSessionInfo(string clientType, string appVersion, string deviceId, string deviceName, string remoteEndPoint, Guid? userId, string username) + private async Task GetSessionInfo(string clientType, string appVersion, string deviceId, string deviceName, string remoteEndPoint, User user) { - var key = GetSessionKey(clientType, appVersion, deviceId); + var key = GetSessionKey(clientType, deviceId); await _sessionLock.WaitAsync(CancellationToken.None).ConfigureAwait(false); + var userId = user == null ? (Guid?)null : user.Id; + var username = user == null ? null : user.Name; + try { - SessionInfo connection; + SessionInfo sessionInfo; DeviceInfo device = null; - if (!_activeConnections.TryGetValue(key, out connection)) + if (!_activeConnections.TryGetValue(key, out sessionInfo)) { - var sessionInfo = new SessionInfo - { - Client = clientType, - DeviceId = deviceId, - ApplicationVersion = appVersion, - Id = key.GetMD5().ToString("N") - }; + sessionInfo = new SessionInfo + { + Client = clientType, + DeviceId = deviceId, + ApplicationVersion = appVersion, + Id = key.GetMD5().ToString("N") + }; sessionInfo.DeviceName = deviceName; sessionInfo.UserId = userId; @@ -410,7 +409,6 @@ namespace MediaBrowser.Server.Implementations.Session OnSessionStarted(sessionInfo); _activeConnections.TryAdd(key, sessionInfo); - connection = sessionInfo; if (!string.IsNullOrEmpty(deviceId)) { @@ -426,24 +424,25 @@ namespace MediaBrowser.Server.Implementations.Session deviceName = device.CustomName; } - connection.DeviceName = deviceName; - connection.UserId = userId; - connection.UserName = username; - connection.RemoteEndPoint = remoteEndPoint; + sessionInfo.DeviceName = deviceName; + sessionInfo.UserId = userId; + sessionInfo.UserName = username; + sessionInfo.RemoteEndPoint = remoteEndPoint; + sessionInfo.ApplicationVersion = appVersion; if (!userId.HasValue) { - connection.AdditionalUsers.Clear(); + sessionInfo.AdditionalUsers.Clear(); } - if (connection.SessionController == null) + if (sessionInfo.SessionController == null) { - connection.SessionController = _sessionFactories - .Select(i => i.GetSessionController(connection)) + sessionInfo.SessionController = _sessionFactories + .Select(i => i.GetSessionController(sessionInfo)) .FirstOrDefault(i => i != null); } - return connection; + return sessionInfo; } finally { @@ -920,7 +919,7 @@ namespace MediaBrowser.Server.Implementations.Session return FilterToSingleMediaType(items) .OrderBy(i => i.SortName); } - + if (item.IsFolder) { var folder = (Folder)item; @@ -1640,7 +1639,25 @@ namespace MediaBrowser.Server.Implementations.Session string.Equals(i.Client, client)); } - public SessionInfo GetSessionByAuthenticationToken(string token) + public Task GetSessionByAuthenticationToken(AuthenticationInfo info, string remoteEndpoint, string appVersion) + { + if (info == null) + { + throw new ArgumentNullException("info"); + } + + var user = string.IsNullOrWhiteSpace(info.UserId) + ? null + : _userManager.GetUserById(info.UserId); + + appVersion = string.IsNullOrWhiteSpace(appVersion) + ? "1" + : appVersion; + + return GetSessionInfo(info.AppName, appVersion, info.DeviceId, info.DeviceName, remoteEndpoint, user); + } + + public Task GetSessionByAuthenticationToken(string token, string remoteEndpoint) { var result = _authRepo.Get(new AuthenticationInfoQuery { @@ -1654,10 +1671,12 @@ namespace MediaBrowser.Server.Implementations.Session var info = result.Items[0]; - // TODO: Make Token part of SessionInfo and get result that way - // This can't be done until all apps are updated to new authentication. - return Sessions.FirstOrDefault(i => string.Equals(i.DeviceId, info.DeviceId) && - string.Equals(i.Client, info.AppName)); + if (info == null) + { + return null; + } + + return GetSessionByAuthenticationToken(info, remoteEndpoint, null); } public Task SendMessageToUserSessions(string userId, string name, T data, diff --git a/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs b/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs index b581f9144..72ec16f85 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs @@ -1,5 +1,4 @@ using MediaBrowser.Controller.Net; -using MediaBrowser.Controller.Security; using MediaBrowser.Controller.Session; using MediaBrowser.Model.Events; using MediaBrowser.Model.Logging; @@ -61,9 +60,9 @@ namespace MediaBrowser.Server.Implementations.Session serverManager.WebSocketConnected += _serverManager_WebSocketConnected; } - void _serverManager_WebSocketConnected(object sender, GenericEventArgs e) + async void _serverManager_WebSocketConnected(object sender, GenericEventArgs e) { - var session = GetSession(e.Argument.QueryString); + var session = await GetSession(e.Argument.QueryString, e.Argument.RemoteEndPoint).ConfigureAwait(false); if (session != null) { @@ -84,11 +83,11 @@ namespace MediaBrowser.Server.Implementations.Session } } - void _httpServer_WebSocketConnecting(object sender, WebSocketConnectingEventArgs e) + async void _httpServer_WebSocketConnecting(object sender, WebSocketConnectingEventArgs e) { if (e.QueryString.AllKeys.Contains("api_key", StringComparer.OrdinalIgnoreCase)) { - var session = GetSession(e.QueryString); + var session = await GetSession(e.QueryString, e.Endpoint).ConfigureAwait(false); if (session == null) { @@ -97,10 +96,10 @@ namespace MediaBrowser.Server.Implementations.Session } } - private SessionInfo GetSession(NameValueCollection queryString) + private Task GetSession(NameValueCollection queryString, string remoteEndpoint) { var token = queryString["api_key"]; - return _sessionManager.GetSessionByAuthenticationToken(token); + return _sessionManager.GetSessionByAuthenticationToken(token, remoteEndpoint); } public void Dispose() -- cgit v1.2.3 From 0ec38a9d40a015af87b19cf345e0dfb1e433b45d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 12 Mar 2015 21:55:22 -0400 Subject: adjust audio direct play checks --- MediaBrowser.Controller/Session/ISessionManager.cs | 6 +- MediaBrowser.Model/Dlna/StreamBuilder.cs | 119 ++++++++++++--------- MediaBrowser.Providers/Manager/ProviderUtils.cs | 2 +- .../MediaInfo/FFProbeAudioInfo.cs | 13 ++- .../HttpServer/Security/SessionContext.cs | 2 +- .../Session/SessionManager.cs | 24 ++++- .../Session/SessionWebSocketListener.cs | 3 +- 7 files changed, 109 insertions(+), 60 deletions(-) (limited to 'MediaBrowser.Server.Implementations/HttpServer/Security') diff --git a/MediaBrowser.Controller/Session/ISessionManager.cs b/MediaBrowser.Controller/Session/ISessionManager.cs index 234a82346..bddc035e0 100644 --- a/MediaBrowser.Controller/Session/ISessionManager.cs +++ b/MediaBrowser.Controller/Session/ISessionManager.cs @@ -283,18 +283,20 @@ namespace MediaBrowser.Controller.Session /// Gets the session by authentication token. /// /// The token. + /// The device identifier. /// The remote endpoint. /// SessionInfo. - Task GetSessionByAuthenticationToken(string token, string remoteEndpoint); + Task GetSessionByAuthenticationToken(string token, string deviceId, string remoteEndpoint); /// /// Gets the session by authentication token. /// /// The information. + /// The device identifier. /// The remote endpoint. /// The application version. /// Task<SessionInfo>. - Task GetSessionByAuthenticationToken(AuthenticationInfo info, string remoteEndpoint, string appVersion); + Task GetSessionByAuthenticationToken(AuthenticationInfo info, string deviceId, string remoteEndpoint, string appVersion); /// /// Logouts the specified access token. diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index 126b218e8..07c7ecd8b 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -138,72 +138,60 @@ namespace MediaBrowser.Model.Dlna DeviceProfile = options.Profile }; - int? maxBitrateSetting = options.GetMaxBitrate(); - - MediaStream audioStream = item.DefaultAudioStream; + List directPlayMethods = GetAudioDirectPlayMethods(item, options); - // Honor the max bitrate setting - if (IsAudioEligibleForDirectPlay(item, maxBitrateSetting)) + if (directPlayMethods.Count > 0) { - DirectPlayProfile directPlay = null; - foreach (DirectPlayProfile i in options.Profile.DirectPlayProfiles) - { - if (i.Type == playlistItem.MediaType && IsAudioDirectPlaySupported(i, item, audioStream)) - { - directPlay = i; - break; - } - } + MediaStream audioStream = item.DefaultAudioStream; - if (directPlay != null) + string audioCodec = audioStream == null ? null : audioStream.Codec; + + // Make sure audio codec profiles are satisfied + if (!string.IsNullOrEmpty(audioCodec)) { - string audioCodec = audioStream == null ? null : audioStream.Codec; + ConditionProcessor conditionProcessor = new ConditionProcessor(); - // Make sure audio codec profiles are satisfied - if (!string.IsNullOrEmpty(audioCodec)) + List conditions = new List(); + foreach (CodecProfile i in options.Profile.CodecProfiles) { - ConditionProcessor conditionProcessor = new ConditionProcessor(); - - List conditions = new List(); - foreach (CodecProfile i in options.Profile.CodecProfiles) + if (i.Type == CodecType.Audio && i.ContainsCodec(audioCodec)) { - if (i.Type == CodecType.Audio && i.ContainsCodec(audioCodec)) + foreach (ProfileCondition c in i.Conditions) { - foreach (ProfileCondition c in i.Conditions) - { - conditions.Add(c); - } + conditions.Add(c); } } + } - int? audioChannels = audioStream.Channels; - int? audioBitrate = audioStream.BitRate; + int? audioChannels = audioStream.Channels; + int? audioBitrate = audioStream.BitRate; - bool all = true; - foreach (ProfileCondition c in conditions) + bool all = true; + foreach (ProfileCondition c in conditions) + { + if (!conditionProcessor.IsAudioConditionSatisfied(c, audioChannels, audioBitrate)) { - if (!conditionProcessor.IsAudioConditionSatisfied(c, audioChannels, audioBitrate)) - { - all = false; - break; - } + all = false; + break; } + } - if (all) + if (all) + { + if (item.Protocol == MediaProtocol.File && + directPlayMethods.Contains(PlayMethod.DirectPlay) && + _localPlayer.CanAccessFile(item.Path)) { - if (item.Protocol == MediaProtocol.File && _localPlayer.CanAccessFile(item.Path)) - { - playlistItem.PlayMethod = PlayMethod.DirectPlay; - } - else - { - playlistItem.PlayMethod = PlayMethod.DirectStream; - } + playlistItem.PlayMethod = PlayMethod.DirectPlay; + } + else if (directPlayMethods.Contains(PlayMethod.DirectStream)) + { + playlistItem.PlayMethod = PlayMethod.DirectStream; + } - playlistItem.Container = item.Container; + playlistItem.Container = item.Container; - return playlistItem; - } + return playlistItem; } } } @@ -272,6 +260,41 @@ namespace MediaBrowser.Model.Dlna return playlistItem; } + private List GetAudioDirectPlayMethods(MediaSourceInfo item, AudioOptions options) + { + MediaStream audioStream = item.DefaultAudioStream; + + DirectPlayProfile directPlayProfile = null; + foreach (DirectPlayProfile i in options.Profile.DirectPlayProfiles) + { + if (i.Type == DlnaProfileType.Audio && IsAudioDirectPlaySupported(i, item, audioStream)) + { + directPlayProfile = i; + break; + } + } + + List playMethods = new List(); + + if (directPlayProfile != null) + { + // While options takes the network and other factors into account. Only applies to direct stream + if (IsAudioEligibleForDirectPlay(item, options.GetMaxBitrate())) + { + playMethods.Add(PlayMethod.DirectStream); + } + + // The profile describes what the device supports + // If device requirements are satisfied then allow both direct stream and direct play + if (IsAudioEligibleForDirectPlay(item, options.Profile.MaxStaticBitrate)) + { + playMethods.Add(PlayMethod.DirectPlay); + } + } + + return playMethods; + } + private StreamInfo BuildVideoItem(MediaSourceInfo item, VideoOptions options) { StreamInfo playlistItem = new StreamInfo diff --git a/MediaBrowser.Providers/Manager/ProviderUtils.cs b/MediaBrowser.Providers/Manager/ProviderUtils.cs index 155cd208f..aa92cc280 100644 --- a/MediaBrowser.Providers/Manager/ProviderUtils.cs +++ b/MediaBrowser.Providers/Manager/ProviderUtils.cs @@ -252,7 +252,7 @@ namespace MediaBrowser.Providers.Manager if (sourceHasAlbumArtist != null && targetHasAlbumArtist != null) { - if (replaceData || targetHasAlbumArtist.AlbumArtists.Count > 0) + if (replaceData || targetHasAlbumArtist.AlbumArtists.Count == 0) { targetHasAlbumArtist.AlbumArtists = sourceHasAlbumArtist.AlbumArtists; } diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs b/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs index 39f138c5b..26d00d544 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs @@ -210,7 +210,15 @@ namespace MediaBrowser.Providers.MediaInfo } } - var albumArtist = FFProbeHelpers.GetDictionaryValue(tags, "albumartist") ?? FFProbeHelpers.GetDictionaryValue(tags, "album artist") ?? FFProbeHelpers.GetDictionaryValue(tags, "album_artist"); + var albumArtist = FFProbeHelpers.GetDictionaryValue(tags, "albumartist"); + if (string.IsNullOrWhiteSpace(albumArtist)) + { + albumArtist = FFProbeHelpers.GetDictionaryValue(tags, "album artist"); + } + if (string.IsNullOrWhiteSpace(albumArtist)) + { + albumArtist = FFProbeHelpers.GetDictionaryValue(tags, "album_artist"); + } if (string.IsNullOrWhiteSpace(albumArtist)) { @@ -277,8 +285,7 @@ namespace MediaBrowser.Providers.MediaInfo return value.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries) .Select(i => i.Trim()) - .Where(i => !string.IsNullOrWhiteSpace(i)) - .FirstOrDefault(); + .FirstOrDefault(i => !string.IsNullOrWhiteSpace(i)); } private readonly char[] _nameDelimiters = { '/', '|', ';', '\\' }; diff --git a/MediaBrowser.Server.Implementations/HttpServer/Security/SessionContext.cs b/MediaBrowser.Server.Implementations/HttpServer/Security/SessionContext.cs index 0557f7528..1bbe9893b 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/Security/SessionContext.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/Security/SessionContext.cs @@ -28,7 +28,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security if (!string.IsNullOrWhiteSpace(authorization.Token)) { var auth = GetTokenInfo(requestContext); - return _sessionManager.GetSessionByAuthenticationToken(auth, requestContext.RemoteIp, authorization.Version); + return _sessionManager.GetSessionByAuthenticationToken(auth, authorization.DeviceId, requestContext.RemoteIp, authorization.Version); } var session = _sessionManager.GetSession(authorization.DeviceId, authorization.Client, authorization.Version); diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index 2e28862e9..7c6ab2af6 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -1639,7 +1639,7 @@ namespace MediaBrowser.Server.Implementations.Session string.Equals(i.Client, client)); } - public Task GetSessionByAuthenticationToken(AuthenticationInfo info, string remoteEndpoint, string appVersion) + public Task GetSessionByAuthenticationToken(AuthenticationInfo info, string deviceId, string remoteEndpoint, string appVersion) { if (info == null) { @@ -1654,10 +1654,26 @@ namespace MediaBrowser.Server.Implementations.Session ? "1" : appVersion; - return GetSessionInfo(info.AppName, appVersion, info.DeviceId, info.DeviceName, remoteEndpoint, user); + var deviceName = info.DeviceName; + + if (!string.IsNullOrWhiteSpace(deviceId)) + { + // Replace the info from the token with more recent info + var device = _deviceManager.GetDevice(deviceId); + if (device != null) + { + deviceName = device.Name; + } + } + else + { + deviceId = info.DeviceId; + } + + return GetSessionInfo(info.AppName, appVersion, deviceId, deviceName, remoteEndpoint, user); } - public Task GetSessionByAuthenticationToken(string token, string remoteEndpoint) + public Task GetSessionByAuthenticationToken(string token, string deviceId, string remoteEndpoint) { var result = _authRepo.Get(new AuthenticationInfoQuery { @@ -1676,7 +1692,7 @@ namespace MediaBrowser.Server.Implementations.Session return null; } - return GetSessionByAuthenticationToken(info, remoteEndpoint, null); + return GetSessionByAuthenticationToken(info, deviceId, remoteEndpoint, null); } public Task SendMessageToUserSessions(string userId, string name, T data, diff --git a/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs b/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs index 7cbff9768..dda4c2b90 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs @@ -103,7 +103,8 @@ namespace MediaBrowser.Server.Implementations.Session { return Task.FromResult(null); } - return _sessionManager.GetSessionByAuthenticationToken(token, remoteEndpoint); + var deviceId = queryString["deviceId"]; + return _sessionManager.GetSessionByAuthenticationToken(token, deviceId, remoteEndpoint); } public void Dispose() -- cgit v1.2.3