From d8ec7109ab5ec561254465e1664974049cc556d7 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 30 May 2017 14:24:50 -0400 Subject: [PATCH] add FindByPath error handling --- .../Collections/CollectionManager.cs | 5 +++++ .../Library/LibraryManager.cs | 5 +++++ .../Playlists/PlaylistManager.cs | 5 +++++ .../UserLibrary/PlaystateService.cs | 18 ++++++++++++++++++ MediaBrowser.Controller/Entities/BaseItem.cs | 2 +- 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/Collections/CollectionManager.cs b/Emby.Server.Implementations/Collections/CollectionManager.cs index 9c26655fc..4e5d344a3 100644 --- a/Emby.Server.Implementations/Collections/CollectionManager.cs +++ b/Emby.Server.Implementations/Collections/CollectionManager.cs @@ -170,6 +170,11 @@ namespace Emby.Server.Implementations.Collections { var item = _libraryManager.GetItemById(itemId); + if (string.IsNullOrWhiteSpace(item.Path)) + { + continue; + } + if (item == null) { throw new ArgumentException("No item exists with the supplied Id"); diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs index 94bd4e0d4..42eda00b7 100644 --- a/Emby.Server.Implementations/Library/LibraryManager.cs +++ b/Emby.Server.Implementations/Library/LibraryManager.cs @@ -864,6 +864,11 @@ namespace Emby.Server.Implementations.Library // If this returns multiple items it could be tricky figuring out which one is correct. // In most cases, the newest one will be and the others obsolete but not yet cleaned up + if (string.IsNullOrWhiteSpace(path)) + { + throw new ArgumentNullException("path"); + } + var query = new InternalItemsQuery { Path = path, diff --git a/Emby.Server.Implementations/Playlists/PlaylistManager.cs b/Emby.Server.Implementations/Playlists/PlaylistManager.cs index 474ef0f53..e0e133e38 100644 --- a/Emby.Server.Implementations/Playlists/PlaylistManager.cs +++ b/Emby.Server.Implementations/Playlists/PlaylistManager.cs @@ -198,6 +198,11 @@ namespace Emby.Server.Implementations.Playlists foreach (var item in items) { + if (string.IsNullOrWhiteSpace(item.Path)) + { + continue; + } + list.Add(LinkedChild.Create(item)); } diff --git a/MediaBrowser.Api/UserLibrary/PlaystateService.cs b/MediaBrowser.Api/UserLibrary/PlaystateService.cs index acbbde769..98b4a5d5d 100644 --- a/MediaBrowser.Api/UserLibrary/PlaystateService.cs +++ b/MediaBrowser.Api/UserLibrary/PlaystateService.cs @@ -279,6 +279,20 @@ namespace MediaBrowser.Api.UserLibrary return dto; } + private PlayMethod ValidatePlayMethod(PlayMethod method, string playSessionId) + { + if (method == PlayMethod.Transcode) + { + var job = string.IsNullOrWhiteSpace(playSessionId) ? null : ApiEntryPoint.Instance.GetTranscodingJob(playSessionId); + if (job == null) + { + return PlayMethod.DirectPlay; + } + } + + return method; + } + /// /// Posts the specified request. /// @@ -300,6 +314,8 @@ namespace MediaBrowser.Api.UserLibrary public void Post(ReportPlaybackStart request) { + request.PlayMethod = ValidatePlayMethod(request.PlayMethod, request.PlaySessionId); + request.SessionId = GetSession(_sessionContext).Result.Id; var task = _sessionManager.OnPlaybackStart(request); @@ -332,6 +348,8 @@ namespace MediaBrowser.Api.UserLibrary public void Post(ReportPlaybackProgress request) { + request.PlayMethod = ValidatePlayMethod(request.PlayMethod, request.PlaySessionId); + request.SessionId = GetSession(_sessionContext).Result.Id; var task = _sessionManager.OnPlaybackProgress(request); diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index c5422fce9..3d46cc9aa 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1733,7 +1733,7 @@ namespace MediaBrowser.Controller.Entities private BaseItem FindLinkedChild(LinkedChild info) { - if (!string.IsNullOrEmpty(info.Path)) + if (!string.IsNullOrWhiteSpace(info.Path)) { var itemByPath = LibraryManager.FindByPath(info.Path, null);