diff options
| author | Niels van Velzen <nielsvanvelzen@users.noreply.github.com> | 2025-11-27 16:33:19 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-27 16:33:19 +0100 |
| commit | a35ffbf17e313b293c2deac6c7320e8286d1cc95 (patch) | |
| tree | c8405042c8f79cfd1c029eae621cf0405b1277d9 /MediaBrowser.Model/Dlna/StreamInfo.cs | |
| parent | 8c02c3be9381ed81260537eab1f7c1e2b8048ffc (diff) | |
| parent | aebabb15801a2d216f84d6a49d8b434ae59e1f34 (diff) | |
Merge pull request #13977 from sususu98/fix/strm-local-subtitle-url
refactor(StreamInfo): reorganize subtitle URL logic and conditions
Diffstat (limited to 'MediaBrowser.Model/Dlna/StreamInfo.cs')
| -rw-r--r-- | MediaBrowser.Model/Dlna/StreamInfo.cs | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/MediaBrowser.Model/Dlna/StreamInfo.cs b/MediaBrowser.Model/Dlna/StreamInfo.cs index 13acd15a3..92404de50 100644 --- a/MediaBrowser.Model/Dlna/StreamInfo.cs +++ b/MediaBrowser.Model/Dlna/StreamInfo.cs @@ -1250,30 +1250,37 @@ public class StreamInfo if (info.DeliveryMethod == SubtitleDeliveryMethod.External) { - if (MediaSource.Protocol == MediaProtocol.File || !string.Equals(stream.Codec, subtitleProfile.Format, StringComparison.OrdinalIgnoreCase) || !stream.IsExternal) - { - info.Url = string.Format( - CultureInfo.InvariantCulture, - "{0}/Videos/{1}/{2}/Subtitles/{3}/{4}/Stream.{5}", - baseUrl, - ItemId, - MediaSourceId, - stream.Index.ToString(CultureInfo.InvariantCulture), - startPositionTicks.ToString(CultureInfo.InvariantCulture), - subtitleProfile.Format); - - if (!string.IsNullOrEmpty(accessToken)) - { - info.Url += "?ApiKey=" + accessToken; - } - - info.IsExternalUrl = false; - } - else + // Default to using the API URL + info.Url = string.Format( + CultureInfo.InvariantCulture, + "{0}/Videos/{1}/{2}/Subtitles/{3}/{4}/Stream.{5}", + baseUrl, + ItemId, + MediaSourceId, + stream.Index.ToString(CultureInfo.InvariantCulture), + startPositionTicks.ToString(CultureInfo.InvariantCulture), + subtitleProfile.Format); + info.IsExternalUrl = false; // Default to API URL + + // Check conditions for potentially using the direct path + if (stream.IsExternal // Must be external + && MediaSource?.Protocol != MediaProtocol.File // Main media must not be a local file + && string.Equals(stream.Codec, subtitleProfile.Format, StringComparison.OrdinalIgnoreCase) // Format must match (no conversion needed) + && !string.IsNullOrEmpty(stream.Path) // Path must exist + && Uri.TryCreate(stream.Path, UriKind.Absolute, out Uri? uriResult) // Path must be an absolute URI + && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps)) // Scheme must be HTTP or HTTPS { + // All conditions met, override with the direct path info.Url = stream.Path; info.IsExternalUrl = true; } + + // Append ApiKey only if we are using the API URL + if (!info.IsExternalUrl && !string.IsNullOrEmpty(accessToken)) + { + // Use "?ApiKey=" as seen in HEAD and other parts of the code + info.Url += "?ApiKey=" + accessToken; + } } return info; |
