Fix issue with Jellyfin using local IP adress not server public URL, now pulic URL is set in plugin.
This commit is contained in:
parent
e26f2a2ab1
commit
b8ac466c90
@ -476,9 +476,10 @@ public class SRFPlayChannel : IChannel, IHasCacheKey
|
||||
// Register stream with proxy service
|
||||
_proxyService.RegisterStream(itemId, streamUrl);
|
||||
|
||||
// Get the server's local API URL so remote clients can access the proxy
|
||||
// Use the published server address configured in Jellyfin's network settings
|
||||
var serverUrl = _appHost.GetSmartApiUrl(string.Empty);
|
||||
// Get the server URL for proxy - prefer configured public URL for remote clients
|
||||
var serverUrl = !string.IsNullOrWhiteSpace(config.PublicServerUrl)
|
||||
? config.PublicServerUrl.TrimEnd('/') // Use configured public URL (important for Android/remote clients)
|
||||
: _appHost.GetSmartApiUrl(string.Empty); // Fall back to Jellyfin's smart URL resolution
|
||||
|
||||
// Create proxy URL as absolute HTTP URL (required for ffmpeg)
|
||||
// Use the actual server URL so remote clients can access it
|
||||
|
||||
@ -142,4 +142,11 @@ public class PluginConfiguration : BasePluginConfiguration
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Required for configuration serialization")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1002:Do not expose generic lists", Justification = "Configuration DTO")]
|
||||
public System.Collections.Generic.List<string> EnabledTopics { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the public/external server URL for remote clients (e.g., https://jellyfin.example.com:8920).
|
||||
/// If not set, the plugin will use Jellyfin's GetSmartApiUrl() which may return local addresses.
|
||||
/// This is important for Android and other remote clients to access streams.
|
||||
/// </summary>
|
||||
public string PublicServerUrl { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
@ -82,6 +82,17 @@
|
||||
<input id="ProxyPassword" name="ProxyPassword" type="password" is="emby-input" autocomplete="off" />
|
||||
<div class="fieldDescription">Password for proxy authentication (leave empty if not required)</div>
|
||||
</div>
|
||||
<br />
|
||||
<h2>Network Settings</h2>
|
||||
<div class="inputContainer">
|
||||
<label class="inputLabel inputLabelUnfocused" for="PublicServerUrl">Public Server URL (Optional)</label>
|
||||
<input id="PublicServerUrl" name="PublicServerUrl" type="text" is="emby-input" placeholder="e.g., https://jellyfin.example.com:8920" />
|
||||
<div class="fieldDescription">
|
||||
The public/external URL for remote clients (Android, iOS, etc.) to access streaming proxy.
|
||||
<br />If not set, the plugin will use Jellyfin's automatic URL detection which may return local addresses.
|
||||
<br /><strong>Important for Android/remote playback!</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<button is="emby-button" type="submit" class="raised button-submit block emby-button">
|
||||
<span>Save</span>
|
||||
@ -110,6 +121,7 @@
|
||||
document.querySelector('#ProxyAddress').value = config.ProxyAddress || '';
|
||||
document.querySelector('#ProxyUsername').value = config.ProxyUsername || '';
|
||||
document.querySelector('#ProxyPassword').value = config.ProxyPassword || '';
|
||||
document.querySelector('#PublicServerUrl').value = config.PublicServerUrl || '';
|
||||
Dashboard.hideLoadingMsg();
|
||||
});
|
||||
});
|
||||
@ -129,6 +141,7 @@
|
||||
config.ProxyAddress = document.querySelector('#ProxyAddress').value;
|
||||
config.ProxyUsername = document.querySelector('#ProxyUsername').value;
|
||||
config.ProxyPassword = document.querySelector('#ProxyPassword').value;
|
||||
config.PublicServerUrl = document.querySelector('#PublicServerUrl').value;
|
||||
ApiClient.updatePluginConfiguration(SRFPlayConfig.pluginUniqueId, config).then(function (result) {
|
||||
Dashboard.processPluginConfigurationUpdateResult(result);
|
||||
});
|
||||
|
||||
@ -53,7 +53,13 @@ public class StreamProxyController : ControllerBase
|
||||
try
|
||||
{
|
||||
// Build the base proxy URL for this item (use original itemId from path to maintain URL structure)
|
||||
var baseProxyUrl = $"{Request.Scheme}://{Request.Host}/Plugins/SRFPlay/Proxy/{itemId}";
|
||||
// Always include the actualItemId as a query parameter to ensure proper resolution during transcoding
|
||||
var baseProxyUrl = $"{Request.Scheme}://{Request.Host}/Plugins/SRFPlay/Proxy/{itemId}?itemId={actualItemId}";
|
||||
|
||||
if (actualItemId != itemId)
|
||||
{
|
||||
_logger.LogDebug("Path itemId {PathId} differs from resolved itemId {ResolvedId}, adding query parameter", itemId, actualItemId);
|
||||
}
|
||||
|
||||
var manifestContent = await _proxyService.GetRewrittenManifestAsync(actualItemId, baseProxyUrl, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
@ -179,7 +185,9 @@ public class StreamProxyController : ControllerBase
|
||||
return queryItemId.ToString();
|
||||
}
|
||||
|
||||
// Use the path item ID as-is
|
||||
// If path ID and query ID don't match, it's likely a transcoding session
|
||||
// Try to use the proxy service fallback to find the correct stream
|
||||
_logger.LogDebug("No itemId query parameter found, using path ID as-is: {PathItemId}", pathItemId);
|
||||
return pathItemId;
|
||||
}
|
||||
|
||||
@ -191,6 +199,11 @@ public class StreamProxyController : ControllerBase
|
||||
/// <returns>The rewritten manifest.</returns>
|
||||
private string RewriteSegmentUrls(string manifestContent, string baseProxyUrl)
|
||||
{
|
||||
// Extract the itemId query parameter from the current request to propagate it
|
||||
var itemIdParam = Request.Query.TryGetValue("itemId", out var itemId) && !string.IsNullOrEmpty(itemId)
|
||||
? $"?itemId={itemId}"
|
||||
: string.Empty;
|
||||
|
||||
var lines = manifestContent.Split('\n');
|
||||
var result = new System.Text.StringBuilder();
|
||||
|
||||
@ -207,12 +220,12 @@ public class StreamProxyController : ControllerBase
|
||||
var uri = new Uri(line.Trim());
|
||||
var segments = uri.AbsolutePath.Split('/');
|
||||
var fileName = segments[^1];
|
||||
result.AppendLine(CultureInfo.InvariantCulture, $"{baseProxyUrl}/{fileName}");
|
||||
result.AppendLine(CultureInfo.InvariantCulture, $"{baseProxyUrl}/{fileName}{itemIdParam}");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Relative URL - rewrite to proxy
|
||||
result.AppendLine(CultureInfo.InvariantCulture, $"{baseProxyUrl}/{line.Trim()}");
|
||||
result.AppendLine(CultureInfo.InvariantCulture, $"{baseProxyUrl}/{line.Trim()}{itemIdParam}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -179,16 +179,21 @@ public class SRFMediaProvider : IMediaSourceProvider
|
||||
var itemIdStr = item.Id.ToString("N"); // Use hex format without dashes
|
||||
_proxyService.RegisterStream(itemIdStr, streamUrl);
|
||||
|
||||
// Get the server's local API URL so remote clients can access the proxy
|
||||
// Use the published server address configured in Jellyfin's network settings
|
||||
var serverUrl = _appHost.GetSmartApiUrl(string.Empty);
|
||||
// Get the server URL for proxy - prefer configured public URL for remote clients
|
||||
var serverUrl = !string.IsNullOrWhiteSpace(config.PublicServerUrl)
|
||||
? config.PublicServerUrl.TrimEnd('/') // Use configured public URL (important for Android/remote clients)
|
||||
: _appHost.GetSmartApiUrl(string.Empty); // Fall back to Jellyfin's smart URL resolution
|
||||
|
||||
// Create proxy URL as absolute HTTP URL (required for ffmpeg)
|
||||
// Use the actual server URL so remote clients can access it
|
||||
// Include item ID as query parameter to preserve it during transcoding
|
||||
var proxyUrl = $"{serverUrl}/Plugins/SRFPlay/Proxy/{itemIdStr}/master.m3u8?itemId={itemIdStr}";
|
||||
|
||||
_logger.LogInformation("Using proxy URL for item {ItemId}: {ProxyUrl}", itemIdStr, proxyUrl);
|
||||
_logger.LogInformation(
|
||||
"Using proxy URL for item {ItemId}: {ProxyUrl} (PublicServerUrl configured: {IsPublicConfigured})",
|
||||
itemIdStr,
|
||||
proxyUrl,
|
||||
!string.IsNullOrWhiteSpace(config.PublicServerUrl));
|
||||
|
||||
// Detect if this is a live stream
|
||||
var isLiveStream = chapter.Type == "SCHEDULED_LIVESTREAM" || urn.Contains("livestream", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
@ -403,6 +403,19 @@ public class StreamProxyService : IDisposable
|
||||
var baseUri = new Uri(originalBaseUrl);
|
||||
var baseUrl = $"{baseUri.Scheme}://{baseUri.Host}{string.Join('/', baseUri.AbsolutePath.Split('/')[..^1])}";
|
||||
|
||||
// Extract itemId query parameter from proxyBaseUrl to propagate it
|
||||
var itemIdParam = string.Empty;
|
||||
var queryMarker = "?itemId=";
|
||||
if (proxyBaseUrl.Contains(queryMarker, StringComparison.Ordinal))
|
||||
{
|
||||
var queryStart = proxyBaseUrl.IndexOf(queryMarker, StringComparison.Ordinal);
|
||||
if (queryStart >= 0)
|
||||
{
|
||||
itemIdParam = proxyBaseUrl[queryStart..];
|
||||
proxyBaseUrl = proxyBaseUrl[..queryStart]; // Remove query from base URL
|
||||
}
|
||||
}
|
||||
|
||||
// Pattern to match .m3u8 and .ts/.mp4 segment references
|
||||
var pattern = @"(?:^|\n)([^#\n][^\n]*\.(?:m3u8|ts|mp4|m4s|aac)[^\n]*)";
|
||||
|
||||
@ -416,11 +429,11 @@ public class StreamProxyService : IDisposable
|
||||
{
|
||||
// Rewrite absolute URLs to proxy
|
||||
var relativePath = url.Replace(baseUrl + "/", string.Empty, StringComparison.Ordinal);
|
||||
return $"\n{proxyBaseUrl}/{relativePath}";
|
||||
return $"\n{proxyBaseUrl}/{relativePath}{itemIdParam}";
|
||||
}
|
||||
|
||||
// Relative URL - rewrite to proxy
|
||||
return $"\n{proxyBaseUrl}/{url}";
|
||||
return $"\n{proxyBaseUrl}/{url}{itemIdParam}";
|
||||
});
|
||||
|
||||
return rewritten;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user