fix: fix server mode crop application, request rewrite, and prevent infinite library scan loop
Build and Release Plugin / release (push) Failing after 1m7s
Build and Release Plugin / release (push) Failing after 1m7s
This commit is contained in:
@@ -44,37 +44,34 @@ namespace JellyfinPlugin
|
||||
return;
|
||||
}
|
||||
|
||||
// Pobieramy obecną konfigurację kodowania
|
||||
var encodingConfig = _configManager.GetConfiguration("encoding");
|
||||
if (encodingConfig == null) return;
|
||||
// Przygotowujemy zamianę pliku ffmpeg bezpośrednio w /usr/lib/jellyfin-ffmpeg/ffmpeg
|
||||
string defaultFfmpeg = "/usr/lib/jellyfin-ffmpeg/ffmpeg";
|
||||
string origFfmpeg = "/usr/lib/jellyfin-ffmpeg/ffmpeg.original";
|
||||
string realFfmpegPath = origFfmpeg;
|
||||
|
||||
// Używamy dynamic, aby ominąć potrzebę rzutowania na konkretny, wewnętrzny typ Jellyfin (EncodingOptions)
|
||||
dynamic dynConfig = encodingConfig;
|
||||
string currentFfmpegPath = dynConfig.EncoderAppPath ?? "/usr/lib/jellyfin-ffmpeg/ffmpeg";
|
||||
if (!File.Exists(origFfmpeg))
|
||||
{
|
||||
if (File.Exists(defaultFfmpeg))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Move(defaultFfmpeg, origFfmpeg);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Nie udało się przenieść {DefaultFfmpeg} do {OrigFfmpeg}", defaultFfmpeg, origFfmpeg);
|
||||
realFfmpegPath = defaultFfmpeg;
|
||||
}
|
||||
}
|
||||
else if (File.Exists("/usr/bin/ffmpeg"))
|
||||
{
|
||||
realFfmpegPath = "/usr/bin/ffmpeg";
|
||||
}
|
||||
}
|
||||
|
||||
string wrapperDir = Path.Combine(_appPaths.PluginsPath, "BlackBarRemover");
|
||||
Directory.CreateDirectory(wrapperDir);
|
||||
string wrapperPath = Path.Combine(wrapperDir, "ffmpeg-wrapper.sh");
|
||||
|
||||
// Jeśli obecna ścieżka to już nasz wrapper, nie robimy pętli w nieskończoność.
|
||||
// Znajdujemy poprzednio zapisaną prawdziwą ścieżkę z pliku.
|
||||
string realFfmpegPath = currentFfmpegPath;
|
||||
if (currentFfmpegPath == wrapperPath)
|
||||
{
|
||||
if (File.Exists(wrapperPath))
|
||||
{
|
||||
var lines = File.ReadAllLines(wrapperPath);
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (line.StartsWith("REAL_FFMPEG="))
|
||||
{
|
||||
realFfmpegPath = line.Split('=')[1].Trim('"');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (realFfmpegPath == wrapperPath) realFfmpegPath = "/usr/lib/jellyfin-ffmpeg/ffmpeg";
|
||||
}
|
||||
string wrapperPath = Path.Combine(wrapperDir, "ffmpeg");
|
||||
|
||||
string script = $@"#!/bin/bash
|
||||
REAL_FFMPEG=""{realFfmpegPath}""
|
||||
@@ -124,7 +121,7 @@ if [ -n ""$INPUT_FILE"" ]; then
|
||||
if [ $next_idx -le $# ]; then
|
||||
next_arg=""${{!next_idx}}""
|
||||
fi
|
||||
NEW_ARGS+=(""crop=$CROP_DATA,$next_arg"")
|
||||
NEW_ARGS+=(""$next_arg,crop=$CROP_DATA"")
|
||||
let i++
|
||||
continue
|
||||
fi
|
||||
@@ -151,21 +148,37 @@ fi
|
||||
exec ""$REAL_FFMPEG"" ""$@""
|
||||
";
|
||||
File.WriteAllText(wrapperPath, script);
|
||||
|
||||
if (Environment.OSVersion.Platform == PlatformID.Unix)
|
||||
if (File.Exists(origFfmpeg) || defaultFfmpeg != origFfmpeg)
|
||||
{
|
||||
System.Diagnostics.Process.Start("chmod", $"+x \"{wrapperPath}\"");
|
||||
try
|
||||
{
|
||||
File.WriteAllText(defaultFfmpeg, script);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Nie udało się zapisać skryptu wrappera do {DefaultFfmpeg}", defaultFfmpeg);
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInformation("Wygenerowano skrypt FFmpeg Wrapper w lokalizacji: {Path}", wrapperPath);
|
||||
|
||||
// Teraz automagicznie podmieniamy ścieżkę w Jellyfin!
|
||||
if (dynConfig.EncoderAppPath != wrapperPath)
|
||||
if (OperatingSystem.IsLinux() || OperatingSystem.IsFreeBSD() || OperatingSystem.IsMacOS())
|
||||
{
|
||||
dynConfig.EncoderAppPath = wrapperPath;
|
||||
_configManager.SaveConfiguration("encoding", encodingConfig);
|
||||
_logger.LogInformation("Automatycznie zmieniono ścieżkę FFmpeg w konfiguracji Jellyfin na wrapper wtyczki.");
|
||||
string[] pathsToChmod = new[] { wrapperPath, defaultFfmpeg };
|
||||
foreach (var path in pathsToChmod)
|
||||
{
|
||||
if (!File.Exists(path)) continue;
|
||||
try
|
||||
{
|
||||
File.SetUnixFileMode(path, UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute | UnixFileMode.GroupRead | UnixFileMode.GroupExecute | UnixFileMode.OtherRead | UnixFileMode.OtherExecute);
|
||||
}
|
||||
catch
|
||||
{
|
||||
var proc = System.Diagnostics.Process.Start("chmod", $"+x \"{path}\"");
|
||||
proc?.WaitForExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInformation("Wygenerowano skrypt FFmpeg Wrapper w lokalizacji: {Path} oraz {DefaultFfmpeg}", wrapperPath, defaultFfmpeg);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user