Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b8ac466c90 | ||
|
|
e26f2a2ab1 |
@@ -7,6 +7,7 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Plugin.SRFPlay.Services;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Channels;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Channels;
|
||||
@@ -27,6 +28,7 @@ public class SRFPlayChannel : IChannel, IHasCacheKey
|
||||
private readonly StreamUrlResolver _streamResolver;
|
||||
private readonly StreamProxyService _proxyService;
|
||||
private readonly CategoryService? _categoryService;
|
||||
private readonly IServerApplicationHost _appHost;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SRFPlayChannel"/> class.
|
||||
@@ -35,12 +37,14 @@ public class SRFPlayChannel : IChannel, IHasCacheKey
|
||||
/// <param name="contentRefreshService">The content refresh service.</param>
|
||||
/// <param name="streamResolver">The stream resolver.</param>
|
||||
/// <param name="proxyService">The stream proxy service.</param>
|
||||
/// <param name="appHost">The server application host.</param>
|
||||
/// <param name="categoryService">The category service (optional).</param>
|
||||
public SRFPlayChannel(
|
||||
ILoggerFactory loggerFactory,
|
||||
ContentRefreshService contentRefreshService,
|
||||
StreamUrlResolver streamResolver,
|
||||
StreamProxyService proxyService,
|
||||
IServerApplicationHost appHost,
|
||||
CategoryService? categoryService = null)
|
||||
{
|
||||
_loggerFactory = loggerFactory;
|
||||
@@ -48,6 +52,7 @@ public class SRFPlayChannel : IChannel, IHasCacheKey
|
||||
_contentRefreshService = contentRefreshService;
|
||||
_streamResolver = streamResolver;
|
||||
_proxyService = proxyService;
|
||||
_appHost = appHost;
|
||||
_categoryService = categoryService;
|
||||
|
||||
if (_categoryService == null)
|
||||
@@ -471,9 +476,14 @@ public class SRFPlayChannel : IChannel, IHasCacheKey
|
||||
// Register stream with proxy service
|
||||
_proxyService.RegisterStream(itemId, streamUrl);
|
||||
|
||||
// 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 localhost as Jellyfin should be able to access its own endpoints
|
||||
var proxyUrl = $"http://localhost:8096/Plugins/SRFPlay/Proxy/{itemId}/master.m3u8";
|
||||
// Use the actual server URL so remote clients can access it
|
||||
var proxyUrl = $"{serverUrl}/Plugins/SRFPlay/Proxy/{itemId}/master.m3u8";
|
||||
|
||||
// Build overview
|
||||
var overview = chapter.Description ?? chapter.Lead;
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Plugin.SRFPlay.Api;
|
||||
using Jellyfin.Plugin.SRFPlay.Services;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Dto;
|
||||
@@ -24,6 +25,7 @@ public class SRFMediaProvider : IMediaSourceProvider
|
||||
private readonly MetadataCache _metadataCache;
|
||||
private readonly StreamUrlResolver _streamResolver;
|
||||
private readonly StreamProxyService _proxyService;
|
||||
private readonly IServerApplicationHost _appHost;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SRFMediaProvider"/> class.
|
||||
@@ -32,17 +34,20 @@ public class SRFMediaProvider : IMediaSourceProvider
|
||||
/// <param name="metadataCache">The metadata cache.</param>
|
||||
/// <param name="streamResolver">The stream URL resolver.</param>
|
||||
/// <param name="proxyService">The stream proxy service.</param>
|
||||
/// <param name="appHost">The server application host.</param>
|
||||
public SRFMediaProvider(
|
||||
ILoggerFactory loggerFactory,
|
||||
MetadataCache metadataCache,
|
||||
StreamUrlResolver streamResolver,
|
||||
StreamProxyService proxyService)
|
||||
StreamProxyService proxyService,
|
||||
IServerApplicationHost appHost)
|
||||
{
|
||||
_loggerFactory = loggerFactory;
|
||||
_logger = loggerFactory.CreateLogger<SRFMediaProvider>();
|
||||
_metadataCache = metadataCache;
|
||||
_streamResolver = streamResolver;
|
||||
_proxyService = proxyService;
|
||||
_appHost = appHost;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -174,12 +179,21 @@ public class SRFMediaProvider : IMediaSourceProvider
|
||||
var itemIdStr = item.Id.ToString("N"); // Use hex format without dashes
|
||||
_proxyService.RegisterStream(itemIdStr, streamUrl);
|
||||
|
||||
// Create proxy URL as absolute HTTP URL (required for ffmpeg)
|
||||
// Use localhost as Jellyfin should be able to access its own endpoints
|
||||
// Include item ID as query parameter to preserve it during transcoding
|
||||
var proxyUrl = $"http://localhost:8096/Plugins/SRFPlay/Proxy/{itemIdStr}/master.m3u8?itemId={itemIdStr}";
|
||||
// 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
|
||||
|
||||
_logger.LogInformation("Using proxy URL for item {ItemId}: {ProxyUrl}", itemIdStr, proxyUrl);
|
||||
// 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} (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;
|
||||
|
||||
@@ -87,6 +87,17 @@ public class StreamUrlResolver : IDisposable
|
||||
chapter.Id,
|
||||
hlsResources.Count);
|
||||
|
||||
// Log all HLS resources with their quality info to help debug quality selection
|
||||
foreach (var resource in hlsResources)
|
||||
{
|
||||
_logger.LogInformation(
|
||||
"Available HLS resource - Quality={Quality}, Protocol={Protocol}, Streaming={Streaming}, URL={Url}",
|
||||
resource.Quality ?? "NULL",
|
||||
resource.Protocol ?? "NULL",
|
||||
resource.Streaming ?? "NULL",
|
||||
resource.Url);
|
||||
}
|
||||
|
||||
if (hlsResources.Count == 0)
|
||||
{
|
||||
_logger.LogWarning("No HLS resources found for chapter: {ChapterId}", chapter.Id);
|
||||
@@ -114,6 +125,10 @@ public class StreamUrlResolver : IDisposable
|
||||
}
|
||||
|
||||
// Select based on quality preference
|
||||
_logger.LogInformation(
|
||||
"Selecting stream with quality preference: {QualityPreference}",
|
||||
qualityPreference);
|
||||
|
||||
Resource? selectedResource = qualityPreference switch
|
||||
{
|
||||
QualityPreference.HD => SelectHDResource(hlsResources) ?? SelectBestAvailableResource(hlsResources),
|
||||
@@ -124,10 +139,10 @@ public class StreamUrlResolver : IDisposable
|
||||
|
||||
if (selectedResource != null)
|
||||
{
|
||||
_logger.LogDebug(
|
||||
"Selected stream for chapter {ChapterId}: Quality={Quality}, Protocol={Protocol}, URL={Url}",
|
||||
_logger.LogInformation(
|
||||
"✅ Selected stream for chapter {ChapterId}: Quality={Quality}, Protocol={Protocol}, URL={Url}",
|
||||
chapter.Id,
|
||||
selectedResource.Quality,
|
||||
selectedResource.Quality ?? "NULL",
|
||||
selectedResource.Protocol,
|
||||
selectedResource.Url);
|
||||
return selectedResource.Url;
|
||||
|
||||
Reference in New Issue
Block a user