mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-07-18 20:24:20 +01:00
Merge pull request #13977 from sususu98/fix/strm-local-subtitle-url
refactor(StreamInfo): reorganize subtitle URL logic and conditions
This commit is contained in:
@@ -1250,30 +1250,37 @@ public class StreamInfo
|
|||||||
|
|
||||||
if (info.DeliveryMethod == SubtitleDeliveryMethod.External)
|
if (info.DeliveryMethod == SubtitleDeliveryMethod.External)
|
||||||
{
|
{
|
||||||
if (MediaSource.Protocol == MediaProtocol.File || !string.Equals(stream.Codec, subtitleProfile.Format, StringComparison.OrdinalIgnoreCase) || !stream.IsExternal)
|
// Default to using the API URL
|
||||||
{
|
info.Url = string.Format(
|
||||||
info.Url = string.Format(
|
CultureInfo.InvariantCulture,
|
||||||
CultureInfo.InvariantCulture,
|
"{0}/Videos/{1}/{2}/Subtitles/{3}/{4}/Stream.{5}",
|
||||||
"{0}/Videos/{1}/{2}/Subtitles/{3}/{4}/Stream.{5}",
|
baseUrl,
|
||||||
baseUrl,
|
ItemId,
|
||||||
ItemId,
|
MediaSourceId,
|
||||||
MediaSourceId,
|
stream.Index.ToString(CultureInfo.InvariantCulture),
|
||||||
stream.Index.ToString(CultureInfo.InvariantCulture),
|
startPositionTicks.ToString(CultureInfo.InvariantCulture),
|
||||||
startPositionTicks.ToString(CultureInfo.InvariantCulture),
|
subtitleProfile.Format);
|
||||||
subtitleProfile.Format);
|
info.IsExternalUrl = false; // Default to API URL
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(accessToken))
|
// Check conditions for potentially using the direct path
|
||||||
{
|
if (stream.IsExternal // Must be external
|
||||||
info.Url += "?ApiKey=" + accessToken;
|
&& 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
|
||||||
info.IsExternalUrl = false;
|
&& 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
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
// All conditions met, override with the direct path
|
||||||
info.Url = stream.Path;
|
info.Url = stream.Path;
|
||||||
info.IsExternalUrl = true;
|
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;
|
return info;
|
||||||
|
|||||||
Reference in New Issue
Block a user