Compare commits

...
8 Commits
Author SHA1 Message Date
dtourolle a6ae4994e9 CI fix
🏗️ Build Plugin / build (push) Successful in 44s
🧪 Test Plugin / test (push) Successful in 36s
🚀 Release Plugin / build-and-release (push) Failing after 42s
2026-02-28 12:21:35 +01:00
dtourolle 12af9bddb1 CI fix
🏗️ Build Plugin / build (push) Failing after 46s
🧪 Test Plugin / test (push) Successful in 36s
2026-02-28 12:19:14 +01:00
dtourolle 92a840cf42 CI fix
🏗️ Build Plugin / build (push) Failing after 27s
🧪 Test Plugin / test (push) Failing after 41s
2026-02-28 12:17:48 +01:00
dtourolle 9210532cf1 CI fix
🏗️ Build Plugin / build (push) Failing after 42s
🧪 Test Plugin / test (push) Successful in 52s
2026-02-28 12:14:41 +01:00
dtourolle 66d5faead2 build system cleans before build
🏗️ Build Plugin / build (push) Failing after 37s
🧪 Test Plugin / test (push) Successful in 48s
2026-02-28 12:12:37 +01:00
dtourolle 65c7a16cee Add missing deps
🏗️ Build Plugin / build (push) Failing after 1s
🧪 Test Plugin / test (push) Failing after 2s
2026-02-28 12:09:22 +01:00
dtourolle 46684402e6 Use docker on CI
🚀 Release Plugin / build-and-release (push) Failing after 2s
🧪 Test Plugin / test (push) Failing after 50s
🏗️ Build Plugin / build (push) Failing after 50s
2026-02-28 12:05:41 +01:00
dtourolle d75e69249b Live-stream starts 6 seconds from edge not at oldest segment.
🧪 Test Plugin / test (push) Failing after 5s
🚀 Release Plugin / build-and-release (push) Failing after 4s
🏗️ Build Plugin / build (push) Successful in 2m55s
2026-02-28 11:55:05 +01:00
7 changed files with 197 additions and 52 deletions
+21 -20
View File
@@ -15,47 +15,48 @@ on:
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: linux/amd64
container:
image: gitea.tourolle.paris/dtourolle/srfplay-builder:latest
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
- name: Verify .NET installation path: build-${{ github.run_id }}
run: dotnet --version
- name: Restore dependencies - name: Restore dependencies
working-directory: build-${{ github.run_id }}
run: dotnet restore Jellyfin.Plugin.SRFPlay.sln run: dotnet restore Jellyfin.Plugin.SRFPlay.sln
- name: Build solution - name: Build solution
run: dotnet build Jellyfin.Plugin.SRFPlay.sln --configuration Release --no-restore --no-self-contained working-directory: build-${{ github.run_id }}
run: dotnet build Jellyfin.Plugin.SRFPlay.sln --configuration Release --no-restore --no-self-contained /m:1
- name: Run tests - name: Run tests
working-directory: build-${{ github.run_id }}
run: dotnet test Jellyfin.Plugin.SRFPlay.sln --no-build --configuration Release --verbosity normal run: dotnet test Jellyfin.Plugin.SRFPlay.sln --no-build --configuration Release --verbosity normal
- name: Install JPRM
run: |
python3 -m venv /tmp/jprm-venv
/tmp/jprm-venv/bin/pip install jprm
- name: Build Jellyfin Plugin - name: Build Jellyfin Plugin
id: jprm id: jprm
working-directory: build-${{ github.run_id }}
run: | run: |
# Create artifacts directory for JPRM output
mkdir -p artifacts mkdir -p artifacts
jprm --verbosity=debug plugin build .
# Build plugin using JPRM ARTIFACT=$(find . -name "*.zip" -type f -print -quit | sed 's|^\./||')
/tmp/jprm-venv/bin/jprm --verbosity=debug plugin build . LATEST="artifacts/srfplay_latest.zip"
cp "${ARTIFACT}" "${LATEST}"
# Find the generated zip file echo "artifact=${LATEST}" >> $GITHUB_OUTPUT
ARTIFACT=$(find . -name "*.zip" -type f -print -quit) echo "Found artifact: ${ARTIFACT} -> ${LATEST}"
echo "artifact=${ARTIFACT}" >> $GITHUB_OUTPUT
echo "Found artifact: ${ARTIFACT}"
- name: Upload build artifact - name: Upload build artifact
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: jellyfin-srfplay-plugin name: jellyfin-srfplay-plugin
path: ${{ steps.jprm.outputs.artifact }} path: build-${{ github.run_id }}/${{ steps.jprm.outputs.artifact }}
retention-days: 30 retention-days: 30
if-no-files-found: error if-no-files-found: error
- name: Cleanup
if: always()
run: rm -rf build-${{ github.run_id }}
+20 -17
View File
@@ -13,14 +13,15 @@ on:
jobs: jobs:
build-and-release: build-and-release:
runs-on: ubuntu-latest runs-on: linux/amd64
container:
image: gitea.tourolle.paris/dtourolle/srfplay-builder:latest
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
- name: Verify .NET installation path: release-${{ github.run_id }}
run: dotnet --version
- name: Get version - name: Get version
id: get_version id: get_version
@@ -35,36 +36,31 @@ jobs:
echo "Building version: ${VERSION}" echo "Building version: ${VERSION}"
- name: Update build.yaml with version - name: Update build.yaml with version
working-directory: release-${{ github.run_id }}
run: | run: |
VERSION="${{ steps.get_version.outputs.version_number }}" VERSION="${{ steps.get_version.outputs.version_number }}"
sed -i "s/^version:.*/version: \"${VERSION}\"/" build.yaml sed -i "s/^version:.*/version: \"${VERSION}\"/" build.yaml
cat build.yaml cat build.yaml
- name: Restore dependencies - name: Restore dependencies
working-directory: release-${{ github.run_id }}
run: dotnet restore Jellyfin.Plugin.SRFPlay.sln run: dotnet restore Jellyfin.Plugin.SRFPlay.sln
- name: Build solution - name: Build solution
run: dotnet build Jellyfin.Plugin.SRFPlay.sln --configuration Release --no-restore --no-self-contained working-directory: release-${{ github.run_id }}
run: dotnet build Jellyfin.Plugin.SRFPlay.sln --configuration Release --no-restore --no-self-contained /m:1
- name: Run tests - name: Run tests
working-directory: release-${{ github.run_id }}
run: dotnet test Jellyfin.Plugin.SRFPlay.sln --no-build --configuration Release --verbosity normal run: dotnet test Jellyfin.Plugin.SRFPlay.sln --no-build --configuration Release --verbosity normal
- name: Install JPRM
run: |
python3 -m venv /tmp/jprm-venv
/tmp/jprm-venv/bin/pip install jprm
- name: Build Jellyfin Plugin - name: Build Jellyfin Plugin
id: jprm id: jprm
working-directory: release-${{ github.run_id }}
run: | run: |
# Create artifacts directory for JPRM output
mkdir -p artifacts mkdir -p artifacts
jprm --verbosity=debug plugin build ./
# Build plugin using JPRM ARTIFACT=$(find . -name "*.zip" -type f -print -quit | sed 's|^\./||')
/tmp/jprm-venv/bin/jprm --verbosity=debug plugin build ./
# Find the generated zip file
ARTIFACT=$(find . -name "*.zip" -type f -print -quit)
ARTIFACT_NAME=$(basename "${ARTIFACT}") ARTIFACT_NAME=$(basename "${ARTIFACT}")
echo "artifact=${ARTIFACT}" >> $GITHUB_OUTPUT echo "artifact=${ARTIFACT}" >> $GITHUB_OUTPUT
echo "artifact_name=${ARTIFACT_NAME}" >> $GITHUB_OUTPUT echo "artifact_name=${ARTIFACT_NAME}" >> $GITHUB_OUTPUT
@@ -72,12 +68,14 @@ jobs:
- name: Calculate checksum - name: Calculate checksum
id: checksum id: checksum
working-directory: release-${{ github.run_id }}
run: | run: |
CHECKSUM=$(md5sum "${{ steps.jprm.outputs.artifact }}" | awk '{print $1}') CHECKSUM=$(md5sum "${{ steps.jprm.outputs.artifact }}" | awk '{print $1}')
echo "checksum=${CHECKSUM}" >> $GITHUB_OUTPUT echo "checksum=${CHECKSUM}" >> $GITHUB_OUTPUT
echo "Checksum: ${CHECKSUM}" echo "Checksum: ${CHECKSUM}"
- name: Create Release - name: Create Release
working-directory: release-${{ github.run_id }}
env: env:
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: | run: |
@@ -135,6 +133,7 @@ jobs:
echo "View at: ${GITEA_URL}/${REPO_OWNER}/${REPO_NAME}/releases/tag/${{ steps.get_version.outputs.version }}" echo "View at: ${GITEA_URL}/${REPO_OWNER}/${REPO_NAME}/releases/tag/${{ steps.get_version.outputs.version }}"
- name: Update manifest.json - name: Update manifest.json
working-directory: release-${{ github.run_id }}
env: env:
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: | run: |
@@ -168,3 +167,7 @@ jobs:
git add manifest.json git add manifest.json
git commit -m "Update manifest.json for version ${VERSION}" git commit -m "Update manifest.json for version ${VERSION}"
git push origin master git push origin master
- name: Cleanup
if: always()
run: rm -rf release-${{ github.run_id }}
+14 -6
View File
@@ -17,22 +17,26 @@ on:
jobs: jobs:
test: test:
runs-on: ubuntu-latest runs-on: linux/amd64
container:
image: gitea.tourolle.paris/dtourolle/srfplay-builder:latest
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
- name: Verify .NET installation path: test-${{ github.run_id }}
run: dotnet --version
- name: Restore dependencies - name: Restore dependencies
working-directory: test-${{ github.run_id }}
run: dotnet restore Jellyfin.Plugin.SRFPlay.sln run: dotnet restore Jellyfin.Plugin.SRFPlay.sln
- name: Build solution - name: Build solution
run: dotnet build Jellyfin.Plugin.SRFPlay.sln --configuration Debug --no-restore --no-self-contained working-directory: test-${{ github.run_id }}
run: dotnet build Jellyfin.Plugin.SRFPlay.sln --configuration Debug --no-restore --no-self-contained /m:1
- name: Run tests - name: Run tests
working-directory: test-${{ github.run_id }}
run: dotnet test Jellyfin.Plugin.SRFPlay.sln --no-build --configuration Debug --verbosity normal --logger "trx;LogFileName=test-results.trx" run: dotnet test Jellyfin.Plugin.SRFPlay.sln --no-build --configuration Debug --verbosity normal --logger "trx;LogFileName=test-results.trx"
- name: Upload test results - name: Upload test results
@@ -40,5 +44,9 @@ jobs:
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: test-results name: test-results
path: '**/test-results.trx' path: test-${{ github.run_id }}/**/test-results.trx
retention-days: 7 retention-days: 7
- name: Cleanup
if: always()
run: rm -rf test-${{ github.run_id }}
+19
View File
@@ -0,0 +1,19 @@
# SRFPlay Builder Image
# Pre-built image with .NET SDK and JPRM for building Jellyfin plugins
# Build: docker build -f Dockerfile.builder -t gitea.tourolle.paris/dtourolle/srfplay-builder:latest .
# Push: docker push gitea.tourolle.paris/dtourolle/srfplay-builder:latest
FROM mcr.microsoft.com/dotnet/sdk:8.0
RUN apt-get update && apt-get install -y \
python3 \
python3-pip \
git \
jq \
nodejs \
npm \
&& rm -rf /var/lib/apt/lists/*
RUN pip install --break-system-packages jprm
WORKDIR /src
@@ -58,16 +58,28 @@ public class StreamProxyController : ControllerBase
/// Livestreams need frequent manifest refresh, VOD can be cached longer. /// Livestreams need frequent manifest refresh, VOD can be cached longer.
/// </summary> /// </summary>
/// <param name="itemId">The item ID to check.</param> /// <param name="itemId">The item ID to check.</param>
private void AddManifestCacheHeaders(string itemId) /// <param name="isVariantManifest">Whether this is a variant (sub) manifest with segment lists.</param>
private void AddManifestCacheHeaders(string itemId, bool isVariantManifest = false)
{ {
var metadata = _proxyService.GetStreamMetadata(itemId); var metadata = _proxyService.GetStreamMetadata(itemId);
var isLiveStream = metadata?.IsLiveStream ?? false; var isLiveStream = metadata?.IsLiveStream ?? false;
if (isLiveStream) if (isLiveStream)
{ {
// Livestreams need frequent manifest refresh (segments rotate every ~6-10s) if (isVariantManifest)
{
// Variant manifests contain the segment list which changes every target duration.
// Use no-cache to ensure the player always gets the freshest segment list,
// preventing requests for segments that have been rotated out of the sliding window.
Response.Headers["Cache-Control"] = "no-cache, no-store";
}
else
{
// Master manifest is relatively stable (just lists quality variants)
Response.Headers["Cache-Control"] = "max-age=2, must-revalidate"; Response.Headers["Cache-Control"] = "max-age=2, must-revalidate";
_logger.LogDebug("Setting livestream cache headers for {ItemId}", itemId); }
_logger.LogDebug("Setting livestream cache headers for {ItemId} (variant={IsVariant})", itemId, isVariantManifest);
} }
else else
{ {
@@ -215,7 +227,8 @@ public class StreamProxyController : ControllerBase
var rewrittenContent = _proxyService.RewriteVariantManifestUrls(manifestContent, baseProxyUrl, queryParams); var rewrittenContent = _proxyService.RewriteVariantManifestUrls(manifestContent, baseProxyUrl, queryParams);
// Set cache headers based on stream type (live vs VOD) // Set cache headers based on stream type (live vs VOD)
AddManifestCacheHeaders(actualItemId); // Variant manifests use stricter no-cache for live streams
AddManifestCacheHeaders(actualItemId, isVariantManifest: true);
_logger.LogDebug("Returning variant manifest for item {ItemId} ({Length} bytes)", itemId, rewrittenContent.Length); _logger.LogDebug("Returning variant manifest for item {ItemId} ({Length} bytes)", itemId, rewrittenContent.Length);
return Content(rewrittenContent, "application/vnd.apple.mpegurl; charset=utf-8"); return Content(rewrittenContent, "application/vnd.apple.mpegurl; charset=utf-8");
@@ -253,9 +266,12 @@ public class StreamProxyController : ControllerBase
{ {
// Pass the original query string to preserve segment-specific parameters (e.g., ?m=timestamp) // Pass the original query string to preserve segment-specific parameters (e.g., ?m=timestamp)
var queryString = Request.QueryString.HasValue ? Request.QueryString.Value : null; var queryString = Request.QueryString.HasValue ? Request.QueryString.Value : null;
var segmentData = await _proxyService.GetSegmentAsync(actualItemId, segmentPath, queryString, cancellationToken).ConfigureAwait(false);
if (segmentData == null) // Use streaming proxy: starts forwarding data to the client before the full segment
// is downloaded from the CDN, reducing time-to-first-byte for live streams
using var upstreamResponse = await _proxyService.GetSegmentStreamAsync(actualItemId, segmentPath, queryString, cancellationToken).ConfigureAwait(false);
if (upstreamResponse == null)
{ {
_logger.LogWarning("Segment not found - ItemId: {ItemId}, Path: {SegmentPath}", itemId, segmentPath); _logger.LogWarning("Segment not found - ItemId: {ItemId}, Path: {SegmentPath}", itemId, segmentPath);
return NotFound(); return NotFound();
@@ -263,9 +279,18 @@ public class StreamProxyController : ControllerBase
// Determine content type based on file extension // Determine content type based on file extension
var contentType = MimeTypeHelper.GetSegmentContentType(segmentPath); var contentType = MimeTypeHelper.GetSegmentContentType(segmentPath);
Response.ContentType = contentType;
_logger.LogDebug("Returning segment {SegmentPath} ({Length} bytes, {ContentType})", segmentPath, segmentData.Length, contentType); if (upstreamResponse.Content.Headers.ContentLength.HasValue)
return File(segmentData, contentType); {
Response.ContentLength = upstreamResponse.Content.Headers.ContentLength.Value;
}
// Stream directly from CDN to client without buffering the entire segment in memory
await upstreamResponse.Content.CopyToAsync(Response.Body, cancellationToken).ConfigureAwait(false);
_logger.LogDebug("Streamed segment {SegmentPath} ({ContentType})", segmentPath, contentType);
return new EmptyResult();
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -1,3 +1,4 @@
using System.Net.Http;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -52,6 +53,18 @@ public interface IStreamProxyService
/// <returns>The segment content as bytes.</returns> /// <returns>The segment content as bytes.</returns>
Task<byte[]?> GetSegmentAsync(string itemId, string segmentPath, string? queryString = null, CancellationToken cancellationToken = default); Task<byte[]?> GetSegmentAsync(string itemId, string segmentPath, string? queryString = null, CancellationToken cancellationToken = default);
/// <summary>
/// Fetches a segment from the original source as a streaming response.
/// Returns the HttpResponseMessage for streaming directly to the client, reducing TTFB.
/// The caller is responsible for disposing the response.
/// </summary>
/// <param name="itemId">The item ID.</param>
/// <param name="segmentPath">The segment path.</param>
/// <param name="queryString">The original query string from the request.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>The HTTP response for streaming, or null if not found.</returns>
Task<HttpResponseMessage?> GetSegmentStreamAsync(string itemId, string segmentPath, string? queryString = null, CancellationToken cancellationToken = default);
/// <summary> /// <summary>
/// Rewrites URLs in a variant (sub) manifest to point to the proxy. /// Rewrites URLs in a variant (sub) manifest to point to the proxy.
/// </summary> /// </summary>
@@ -647,6 +647,21 @@ public class StreamProxyService : IStreamProxyService
// Rewrite the manifest to replace Akamai URLs with proxy URLs // Rewrite the manifest to replace Akamai URLs with proxy URLs
var rewrittenContent = RewriteManifestUrls(manifestContent, authenticatedUrl, baseProxyUrl); var rewrittenContent = RewriteManifestUrls(manifestContent, authenticatedUrl, baseProxyUrl);
// For live streams, inject #EXT-X-START to tell the player to start near the live edge
// Without this, players may start at the beginning of the sliding window and stutter
// as old segments get rotated out by the CDN
if (_streamMappings.TryGetValue(itemId, out var streamInfoForManifest) && streamInfoForManifest.IsLiveStream)
{
if (!rewrittenContent.Contains("#EXT-X-START", StringComparison.Ordinal))
{
rewrittenContent = rewrittenContent.Replace(
"#EXTM3U",
"#EXTM3U\n#EXT-X-START:TIME-OFFSET=-6,PRECISE=NO",
StringComparison.Ordinal);
_logger.LogDebug("Injected #EXT-X-START tag for live stream {ItemId}", itemId);
}
}
_logger.LogDebug("Rewritten manifest for item {ItemId} ({Length} bytes):\n{Content}", itemId, rewrittenContent.Length, rewrittenContent); _logger.LogDebug("Rewritten manifest for item {ItemId} ({Length} bytes):\n{Content}", itemId, rewrittenContent.Length, rewrittenContent);
return rewrittenContent; return rewrittenContent;
} }
@@ -720,6 +735,67 @@ public class StreamProxyService : IStreamProxyService
} }
} }
/// <summary>
/// Fetches a segment as a streaming response for direct forwarding to the client.
/// Uses HttpCompletionOption.ResponseHeadersRead to start streaming before the full
/// segment is downloaded, reducing time-to-first-byte for live streams.
/// </summary>
/// <param name="itemId">The item ID.</param>
/// <param name="segmentPath">The segment path.</param>
/// <param name="queryString">The original query string from the request.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>The HTTP response for streaming, or null if not found.</returns>
public async Task<HttpResponseMessage?> GetSegmentStreamAsync(
string itemId,
string segmentPath,
string? queryString = null,
CancellationToken cancellationToken = default)
{
var authenticatedUrl = await GetAuthenticatedUrlAsync(itemId, cancellationToken).ConfigureAwait(false);
if (authenticatedUrl == null)
{
return null;
}
try
{
var baseUri = new Uri(authenticatedUrl);
var baseUrl = $"{baseUri.Scheme}://{baseUri.Host}{string.Join('/', baseUri.AbsolutePath.Split('/')[..^1])}";
var queryParams = string.Empty;
if (!string.IsNullOrEmpty(queryString))
{
queryParams = queryString.StartsWith('?') ? queryString : $"?{queryString}";
}
else if (!segmentPath.Contains("hdntl=", StringComparison.OrdinalIgnoreCase))
{
queryParams = baseUri.Query;
}
var segmentUrl = $"{baseUrl}/{segmentPath}{queryParams}";
_logger.LogDebug("Streaming segment - SegmentPath: {SegmentPath}, FullUrl: {FullUrl}", segmentPath, segmentUrl);
var httpClient = _httpClientFactory.CreateClient(NamedClient.Default);
var request = new HttpRequestMessage(HttpMethod.Get, segmentUrl);
var response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
{
_logger.LogWarning("Segment stream request failed with {StatusCode} for {SegmentPath}", response.StatusCode, segmentPath);
response.Dispose();
return null;
}
return response;
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to stream segment {SegmentPath} for item {ItemId}", segmentPath, itemId);
return null;
}
}
/// <summary> /// <summary>
/// Rewrites URLs in HLS manifest to point to proxy. /// Rewrites URLs in HLS manifest to point to proxy.
/// </summary> /// </summary>