From 9e0290521bae02f403104bd9679099a092857cd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BB=D0=B5=D0=B1=20=D0=A1=D0=B0=D0=BB=D1=8C=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Wed, 23 Oct 2024 12:13:35 +0300 Subject: [PATCH 01/14] Change service URLs to relative in description.xml 'Bigscreen Beta' app doesn't work with absolute paths in description.xml. Partially addresses #81. --- src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs | 7 ++++++- src/Jellyfin.Plugin.Dlna/Server/DescriptionXmlBuilder.cs | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs b/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs index a322d7c..108ae37 100644 --- a/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs +++ b/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs @@ -59,7 +59,7 @@ public DlnaServerController( [Produces(MediaTypeNames.Text.Xml)] public ActionResult GetDescriptionXml([FromRoute, Required] string serverId) { - var url = GetAbsoluteUri(); + var url = GetRelativeUrl(); var serverAddress = url.Substring(0, url.IndexOf("/dlna/", StringComparison.OrdinalIgnoreCase)); var xml = _dlnaManager.GetServerDescriptionXml(Request.Headers, serverId, serverAddress); return Ok(xml); @@ -279,6 +279,11 @@ private string GetAbsoluteUri() return $"{Request.Scheme}://{Request.Host}{Request.PathBase}{Request.Path}"; } + private string GetRelativeUrl() + { + return $"{Request.PathBase}{Request.Path}"; + } + private Task ProcessControlRequestInternalAsync(string id, Stream requestStream, IUpnpService service) { return service.ProcessControlRequestAsync(new ControlRequest(Request.Headers) diff --git a/src/Jellyfin.Plugin.Dlna/Server/DescriptionXmlBuilder.cs b/src/Jellyfin.Plugin.Dlna/Server/DescriptionXmlBuilder.cs index 536c3e0..24e2ff8 100644 --- a/src/Jellyfin.Plugin.Dlna/Server/DescriptionXmlBuilder.cs +++ b/src/Jellyfin.Plugin.Dlna/Server/DescriptionXmlBuilder.cs @@ -23,7 +23,6 @@ public class DescriptionXmlBuilder public DescriptionXmlBuilder(DlnaDeviceProfile profile, string serverUdn, string serverAddress, string serverName, string serverId) { ArgumentException.ThrowIfNullOrEmpty(serverUdn); - ArgumentException.ThrowIfNullOrEmpty(serverAddress); _profile = profile; _serverUdn = serverUdn; From be761c52929fbd64832db522002dd60df12c535f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BB=D0=B5=D0=B1=20=D0=A1=D0=B0=D0=BB=D1=8C=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Wed, 23 Oct 2024 12:14:01 +0300 Subject: [PATCH 02/14] Fix browse responses ignoring StartIndex GetMusicFolders, GetMovieFolders and GetTvFolders would ignore the StartIndex provided in the request when returning library stubs, forcing some clients to go into an infinite loop. Resolves: #81 --- .../ContentDirectory/ControlHandler.cs | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs b/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs index 0664afb..d3ab80d 100644 --- a/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs +++ b/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs @@ -681,15 +681,7 @@ private QueryResult GetMusicFolders(BaseItem item, User user, StubTy new(item, StubType.FavoriteSongs) }; - if (limit < serverItems.Length) - { - serverItems = serverItems[..limit.Value]; - } - - return new QueryResult( - startIndex, - serverItems.Length, - serverItems); + return GetTrimmedArray(serverItems, startIndex, limit); } /// @@ -737,15 +729,7 @@ private QueryResult GetMovieFolders(BaseItem item, User user, StubTy new(item, StubType.Genres) }; - if (limit < array.Length) - { - array = array[..limit.Value]; - } - - return new QueryResult( - startIndex, - array.Length, - array); + return GetTrimmedArray(array, startIndex, limit); } /// @@ -821,15 +805,7 @@ private QueryResult GetTvFolders(BaseItem item, User user, StubType? new(item, StubType.Genres) }; - if (limit < serverItems.Length) - { - serverItems = serverItems[..limit.Value]; - } - - return new QueryResult( - startIndex, - serverItems.Length, - serverItems); + return GetTrimmedArray(serverItems, startIndex, limit); } /// @@ -1122,6 +1098,34 @@ private QueryResult GetMusicGenreItems(BaseItem item, User user, Sor return ToResult(startIndex, result); } + + private static QueryResult GetTrimmedArray(ServerItem[] serverItems, int? startIndex, int? limit) + { + if (startIndex >= serverItems.Length) + { + serverItems = new ServerItem[] { }; + + return new QueryResult( + startIndex, + serverItems.Length, + serverItems); + } + + if (startIndex > 0) + { + serverItems = serverItems[startIndex.Value..]; + } + + if (limit < serverItems.Length) + { + serverItems = serverItems[..limit.Value]; + } + + return new QueryResult( + startIndex, + serverItems.Length, + serverItems); + } /// /// Converts into a . From 1d9c2840c3cbf41868978bbab270b94e25adfdc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BB=D0=B5=D0=B1=20=D0=A1=D0=B0=D0=BB=D1=8C=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Thu, 24 Oct 2024 18:28:33 +0300 Subject: [PATCH 03/14] Change description.xml service URL structure Make service URLs being absolute/relative dependent on request User-Agent header, set Bigscreen to be presented with relative URLs. Potentially unbreaks some setups that might require absolute URIs. --- .../Api/DlnaServerController.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs b/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs index 108ae37..3cdd0a1 100644 --- a/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs +++ b/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs @@ -4,6 +4,7 @@ using System.IO; using System.Net.Mime; using System.Threading.Tasks; +using Jellyfin.Extensions; using Jellyfin.Plugin.Dlna.Model; using MediaBrowser.Common.Api; using MediaBrowser.Model.Net; @@ -45,6 +46,10 @@ public DlnaServerController( _mediaReceiverRegistrar = mediaReceiverRegistrar; } + private static readonly string[] relativeUrlUserAgents = new string[] { + "Bigscreen" + }; + /// /// Get Description Xml. /// @@ -59,7 +64,22 @@ public DlnaServerController( [Produces(MediaTypeNames.Text.Xml)] public ActionResult GetDescriptionXml([FromRoute, Required] string serverId) { - var url = GetRelativeUrl(); + var useRelativePath = false; + string? userAgent = Request.Headers.UserAgent; + if (userAgent != null) + { + userAgent = userAgent.Substring(0, userAgent.IndexOf('/')); + foreach (var relativePathUserAgent in relativeUrlUserAgents) + { + if (userAgent == relativePathUserAgent) + { + useRelativePath = true; + break; + } + } + } + + var url = useRelativePath ? GetRelativeUrl() : GetAbsoluteUri(); var serverAddress = url.Substring(0, url.IndexOf("/dlna/", StringComparison.OrdinalIgnoreCase)); var xml = _dlnaManager.GetServerDescriptionXml(Request.Headers, serverId, serverAddress); return Ok(xml); From 2e2ad88af58aa6661224a8f1a939024158746714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BB=D0=B5=D0=B1=20=D0=A1=D0=B0=D0=BB=D1=8C=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Thu, 24 Oct 2024 18:32:16 +0300 Subject: [PATCH 04/14] Fix 'Latest' stub responses ignoring StartIndex Jellyfin appears to ignore StartIndex in LatestItemQuery as well, so when StartIndex is set it is necessary to request more items than would otherwise be required and then trim the array. --- .../ContentDirectory/ControlHandler.cs | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs b/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs index d3ab80d..585b67a 100644 --- a/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs +++ b/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs @@ -999,18 +999,45 @@ private QueryResult GetLatest(BaseItem parent, InternalItemsQuery qu { query.OrderBy = Array.Empty<(ItemSortBy, SortOrder)>(); + int limit; + + if (query.StartIndex > 0) + { + limit = (query.Limit == null || query.Limit <= 0) ? int.MaxValue : (query.StartIndex + query.Limit).Value; + } + else + { + limit = query.Limit ?? 50; + } + var items = _userViewManager.GetLatestItems( new LatestItemsQuery { // User cannot be null here as the caller has set it UserId = query.User!.Id, - Limit = query.Limit ?? 50, + Limit = limit, IncludeItemTypes = new[] { itemType }, ParentId = parent?.Id ?? Guid.Empty, GroupItems = true }, query.DtoOptions).Select(i => i.Item1 ?? i.Item2.FirstOrDefault()).Where(i => i is not null).ToArray(); + if (query.StartIndex > 0) + { + if (items.Length <= query.StartIndex) + { + items = new BaseItem[] { }; + } + else if (query.Limit > 0 && items.Length > query.Limit.Value) + { + items = items[query.StartIndex.Value..(query.StartIndex + query.Limit).Value]; + } + else + { + items = items[query.StartIndex.Value..]; + } + } + return ToResult(query.StartIndex, items); } From 804fafe2b3851906dd0ed0bae863169508bfc774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BB=D0=B5=D0=B1=20=D0=A1=D0=B0=D0=BB=D1=8C=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Fri, 25 Oct 2024 13:20:55 +0300 Subject: [PATCH 05/14] Replace null checks with C#9-style ones --- src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs | 2 +- src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs b/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs index 3cdd0a1..4aaa32e 100644 --- a/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs +++ b/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs @@ -66,7 +66,7 @@ public ActionResult GetDescriptionXml([FromRoute, Required] string serve { var useRelativePath = false; string? userAgent = Request.Headers.UserAgent; - if (userAgent != null) + if (userAgent is not null) { userAgent = userAgent.Substring(0, userAgent.IndexOf('/')); foreach (var relativePathUserAgent in relativeUrlUserAgents) diff --git a/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs b/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs index 585b67a..ffa1d26 100644 --- a/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs +++ b/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs @@ -1003,7 +1003,7 @@ private QueryResult GetLatest(BaseItem parent, InternalItemsQuery qu if (query.StartIndex > 0) { - limit = (query.Limit == null || query.Limit <= 0) ? int.MaxValue : (query.StartIndex + query.Limit).Value; + limit = (query.Limit is null || query.Limit <= 0) ? int.MaxValue : (query.StartIndex + query.Limit).Value; } else { From 20c5b73dc8f1ff8c743ed0b40e8d57bd77500db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BB=D0=B5=D0=B1=20=D0=A1=D0=B0=D0=BB=D1=8C=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Fri, 25 Oct 2024 13:41:56 +0300 Subject: [PATCH 06/14] Improve code quality --- src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs b/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs index 4aaa32e..88adec2 100644 --- a/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs +++ b/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs @@ -69,14 +69,7 @@ public ActionResult GetDescriptionXml([FromRoute, Required] string serve if (userAgent is not null) { userAgent = userAgent.Substring(0, userAgent.IndexOf('/')); - foreach (var relativePathUserAgent in relativeUrlUserAgents) - { - if (userAgent == relativePathUserAgent) - { - useRelativePath = true; - break; - } - } + useRelativePath = relativeUrlUserAgents.Contains(userAgent, StringComparison.Ordinal); } var url = useRelativePath ? GetRelativeUrl() : GetAbsoluteUri(); From 5744432c67ab0872425a9e1a5de2a6bed12e5e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BB=D0=B5=D0=B1=20=D0=A1=D0=B0=D0=BB=D1=8C=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Sat, 26 Oct 2024 22:44:51 +0300 Subject: [PATCH 07/14] Improve code quality --- .../Api/DlnaServerController.cs | 8 +- .../ContentDirectory/ControlHandler.cs | 75 +++++++++++-------- 2 files changed, 46 insertions(+), 37 deletions(-) diff --git a/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs b/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs index 88adec2..5c1b723 100644 --- a/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs +++ b/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs @@ -22,6 +22,8 @@ namespace Jellyfin.Plugin.Dlna.Api; [Authorize(Policy = Policies.AnonymousLanAccessPolicy)] public class DlnaServerController : ControllerBase { + private static readonly string[] _relativeUrlUserAgents = { "Bigscreen" }; + private readonly IDlnaManager _dlnaManager; private readonly IContentDirectory _contentDirectory; private readonly IConnectionManager _connectionManager; @@ -46,10 +48,6 @@ public DlnaServerController( _mediaReceiverRegistrar = mediaReceiverRegistrar; } - private static readonly string[] relativeUrlUserAgents = new string[] { - "Bigscreen" - }; - /// /// Get Description Xml. /// @@ -69,7 +67,7 @@ public ActionResult GetDescriptionXml([FromRoute, Required] string serve if (userAgent is not null) { userAgent = userAgent.Substring(0, userAgent.IndexOf('/')); - useRelativePath = relativeUrlUserAgents.Contains(userAgent, StringComparison.Ordinal); + useRelativePath = _relativeUrlUserAgents.Contains(userAgent, StringComparison.Ordinal); } var url = useRelativePath ? GetRelativeUrl() : GetAbsoluteUri(); diff --git a/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs b/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs index 4933780..9e31af6 100644 --- a/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs +++ b/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs @@ -681,7 +681,11 @@ private QueryResult GetMusicFolders(BaseItem item, User user, StubTy new(item, StubType.FavoriteSongs) }; - return GetTrimmedArray(serverItems, startIndex, limit); + serverItems = GetTrimmedServerItemsArray(serverItems, startIndex, limit); + return new QueryResult( + startIndex, + serverItems.Length, + serverItems); } /// @@ -729,7 +733,11 @@ private QueryResult GetMovieFolders(BaseItem item, User user, StubTy new(item, StubType.Genres) }; - return GetTrimmedArray(array, startIndex, limit); + array = GetTrimmedServerItemsArray(array, startIndex, limit); + return new QueryResult( + startIndex, + array.Length, + array); } /// @@ -805,7 +813,11 @@ private QueryResult GetTvFolders(BaseItem item, User user, StubType? new(item, StubType.Genres) }; - return GetTrimmedArray(serverItems, startIndex, limit); + serverItems = GetTrimmedServerItemsArray(serverItems, startIndex, limit); + return new QueryResult( + startIndex, + serverItems.Length, + serverItems); } /// @@ -1026,7 +1038,7 @@ private QueryResult GetLatest(BaseItem parent, InternalItemsQuery qu { if (items.Length <= query.StartIndex) { - items = new BaseItem[] { }; + items = Array.Empty(); } else if (query.Limit > 0 && items.Length > query.Limit.Value) { @@ -1125,34 +1137,6 @@ private QueryResult GetMusicGenreItems(BaseItem item, User user, Sor return ToResult(startIndex, result); } - - private static QueryResult GetTrimmedArray(ServerItem[] serverItems, int? startIndex, int? limit) - { - if (startIndex >= serverItems.Length) - { - serverItems = new ServerItem[] { }; - - return new QueryResult( - startIndex, - serverItems.Length, - serverItems); - } - - if (startIndex > 0) - { - serverItems = serverItems[startIndex.Value..]; - } - - if (limit < serverItems.Length) - { - serverItems = serverItems[..limit.Value]; - } - - return new QueryResult( - startIndex, - serverItems.Length, - serverItems); - } /// /// Converts into a . @@ -1274,4 +1258,31 @@ private ServerItem ParseItemId(string id) return new ServerItem(_libraryManager.GetUserRootFolder(), null); } + + /// + /// Discards elements before startIndex and elements after startIndex+limit from an array of serverItems. + /// + /// + /// + /// + /// + private static ServerItem[] GetTrimmedServerItemsArray(ServerItem[] serverItems, int? startIndex, int? limit) + { + if (startIndex >= serverItems.Length) + { + return Array.Empty(); + } + + if (startIndex > 0) + { + serverItems = serverItems[startIndex.Value..]; + } + + if (limit < serverItems.Length) + { + serverItems = serverItems[..limit.Value]; + } + + return serverItems; + } } From b5c24e5ae4cd806027c287d271377b232b1bfab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BB=D0=B5=D0=B1=20=D0=A1=D0=B0=D0=BB=D1=8C=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Sat, 26 Oct 2024 22:50:05 +0300 Subject: [PATCH 08/14] Fix documentation for GetTrimmedServerItemsArray --- .../ContentDirectory/ControlHandler.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs b/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs index 9e31af6..5701ccf 100644 --- a/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs +++ b/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs @@ -1260,12 +1260,12 @@ private ServerItem ParseItemId(string id) } /// - /// Discards elements before startIndex and elements after startIndex+limit from an array of serverItems. + /// Discards elements before startIndex and elements after startIndex+limit from an array of . /// - /// - /// - /// - /// + /// An array of . + /// The start index. + /// The maximum number to return. + /// The corresponding trimmed array of private static ServerItem[] GetTrimmedServerItemsArray(ServerItem[] serverItems, int? startIndex, int? limit) { if (startIndex >= serverItems.Length) From b24d9078723f693ebeff1d316605435440a2ddb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BB=D0=B5=D0=B1=20=D0=A1=D0=B0=D0=BB=D1=8C=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Sat, 26 Oct 2024 22:54:46 +0300 Subject: [PATCH 09/14] Improve naming consistency --- src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs b/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs index 5c1b723..3fb8fdc 100644 --- a/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs +++ b/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs @@ -22,7 +22,7 @@ namespace Jellyfin.Plugin.Dlna.Api; [Authorize(Policy = Policies.AnonymousLanAccessPolicy)] public class DlnaServerController : ControllerBase { - private static readonly string[] _relativeUrlUserAgents = { "Bigscreen" }; + private static readonly string[] _relativePathUserAgents = { "Bigscreen" }; private readonly IDlnaManager _dlnaManager; private readonly IContentDirectory _contentDirectory; @@ -67,7 +67,7 @@ public ActionResult GetDescriptionXml([FromRoute, Required] string serve if (userAgent is not null) { userAgent = userAgent.Substring(0, userAgent.IndexOf('/')); - useRelativePath = _relativeUrlUserAgents.Contains(userAgent, StringComparison.Ordinal); + useRelativePath = _relativePathUserAgents.Contains(userAgent, StringComparison.Ordinal); } var url = useRelativePath ? GetRelativeUrl() : GetAbsoluteUri(); From ee47abe2c8d8177f9fe698c48a5d4c13f231e72a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BB=D0=B5=D0=B1=20=D0=A1=D0=B0=D0=BB=D1=8C=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Sat, 26 Oct 2024 23:00:33 +0300 Subject: [PATCH 10/14] Improve naming consistency --- src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs b/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs index 3fb8fdc..e814d37 100644 --- a/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs +++ b/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs @@ -70,7 +70,7 @@ public ActionResult GetDescriptionXml([FromRoute, Required] string serve useRelativePath = _relativePathUserAgents.Contains(userAgent, StringComparison.Ordinal); } - var url = useRelativePath ? GetRelativeUrl() : GetAbsoluteUri(); + var url = useRelativePath ? GetRelativePath() : GetAbsoluteUri(); var serverAddress = url.Substring(0, url.IndexOf("/dlna/", StringComparison.OrdinalIgnoreCase)); var xml = _dlnaManager.GetServerDescriptionXml(Request.Headers, serverId, serverAddress); return Ok(xml); @@ -290,7 +290,7 @@ private string GetAbsoluteUri() return $"{Request.Scheme}://{Request.Host}{Request.PathBase}{Request.Path}"; } - private string GetRelativeUrl() + private string GetRelativePath() { return $"{Request.PathBase}{Request.Path}"; } From 3b151fb0938bae76cb67e8a524fce032880095b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BB=D0=B5=D0=B1=20=D0=A1=D0=B0=D0=BB=D1=8C=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Tue, 29 Oct 2024 02:08:32 +0300 Subject: [PATCH 11/14] Fix limit being unused --- src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs b/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs index 5701ccf..12bc80a 100644 --- a/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs +++ b/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs @@ -1027,7 +1027,7 @@ private QueryResult GetLatest(BaseItem parent, InternalItemsQuery qu { // User cannot be null here as the caller has set it User = query.User!, - Limit = query.Limit ?? 50, + Limit = limit, IncludeItemTypes = new[] { itemType }, ParentId = parent?.Id ?? Guid.Empty, GroupItems = true From 713790c7e9405d2442b46062e7230dfcadd73394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BB=D0=B5=D0=B1=20=D0=A1=D0=B0=D0=BB=D1=8C=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Wed, 30 Oct 2024 02:44:12 +0300 Subject: [PATCH 12/14] Fix potential out of bounds exception --- src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs b/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs index 12bc80a..788dfcb 100644 --- a/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs +++ b/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs @@ -1040,9 +1040,9 @@ private QueryResult GetLatest(BaseItem parent, InternalItemsQuery qu { items = Array.Empty(); } - else if (query.Limit > 0 && items.Length > query.Limit.Value) + else if (query.Limit > 0 && items.Length > limit) { - items = items[query.StartIndex.Value..(query.StartIndex + query.Limit).Value]; + items = items[query.StartIndex.Value..(query.StartIndex + query.Limit - 1).Value]; } else { From 4c7a63b8aba710868125652cb2c1b4ad8431dd82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BB=D0=B5=D0=B1=20=D0=A1=D0=B0=D0=BB=D1=8C=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Wed, 30 Oct 2024 02:51:50 +0300 Subject: [PATCH 13/14] Remove unnecessary limit check --- .../ContentDirectory/ControlHandler.cs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs b/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs index 788dfcb..9371ed4 100644 --- a/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs +++ b/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs @@ -1036,18 +1036,7 @@ private QueryResult GetLatest(BaseItem parent, InternalItemsQuery qu if (query.StartIndex > 0) { - if (items.Length <= query.StartIndex) - { - items = Array.Empty(); - } - else if (query.Limit > 0 && items.Length > limit) - { - items = items[query.StartIndex.Value..(query.StartIndex + query.Limit - 1).Value]; - } - else - { - items = items[query.StartIndex.Value..]; - } + items = (items.Length <= query.StartIndex) ? Array.Empty() : items[query.StartIndex.Value..]; } return ToResult(query.StartIndex, items); From ef698b07cd1acab6a51a6e9ef7e64674ac155028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BB=D0=B5=D0=B1=20=D0=A1=D0=B0=D0=BB=D1=8C=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Wed, 30 Oct 2024 02:58:05 +0300 Subject: [PATCH 14/14] Limit to 50 instead of int.MaxValue if null --- src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs b/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs index 9371ed4..53eddfa 100644 --- a/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs +++ b/src/Jellyfin.Plugin.Dlna/ContentDirectory/ControlHandler.cs @@ -1015,7 +1015,7 @@ private QueryResult GetLatest(BaseItem parent, InternalItemsQuery qu if (query.StartIndex > 0) { - limit = (query.Limit is null || query.Limit <= 0) ? int.MaxValue : (query.StartIndex + query.Limit).Value; + limit = (query.Limit <= 0) ? int.MaxValue : (query.StartIndex.Value + (query.Limit ?? 50)); } else {