diff --git a/JellyfinPlugin/Api/BlackBarService.cs b/JellyfinPlugin/Api/BlackBarService.cs index 367863b..7d7f242 100644 --- a/JellyfinPlugin/Api/BlackBarService.cs +++ b/JellyfinPlugin/Api/BlackBarService.cs @@ -25,6 +25,7 @@ namespace JellyfinPlugin.Api public ContentResult GetCropByPath([FromQuery] string path) { if (string.IsNullOrEmpty(path)) return Content(string.Empty, "text/plain"); + path = path.Trim('"').Trim('\''); var mode = Plugin.Instance!.Configuration.PlaybackMode; if (mode == "Client") return Content(string.Empty, "text/plain"); diff --git a/JellyfinPlugin/CropHelper.cs b/JellyfinPlugin/CropHelper.cs index eb6498e..05d03ca 100644 --- a/JellyfinPlugin/CropHelper.cs +++ b/JellyfinPlugin/CropHelper.cs @@ -9,6 +9,13 @@ namespace JellyfinPlugin { public static class CropHelper { + private static string GetFFmpegPath() + { + if (File.Exists("/usr/lib/jellyfin-ffmpeg/ffmpeg")) return "/usr/lib/jellyfin-ffmpeg/ffmpeg"; + if (File.Exists("/usr/bin/ffmpeg")) return "/usr/bin/ffmpeg"; + return "ffmpeg"; + } + public static async Task DetectCropAsync(string filePath, double limit) { // FFmpeg w nowych wersjach przyjmuje limit w formie ułamka, np. 24/255 to ok 0.094 @@ -17,7 +24,7 @@ namespace JellyfinPlugin var startInfo = new ProcessStartInfo { - FileName = "ffmpeg", + FileName = GetFFmpegPath(), // KLUCZOWE: reset=1, żeby oceniał każdą klatkę niezależnie! Arguments = $"-skip_frame nokey -i \"{filePath}\" -vf \"cropdetect=limit={limitStr}:round=16:reset=1\" -f null -", RedirectStandardError = true, diff --git a/JellyfinPlugin/LibraryMonitor.cs b/JellyfinPlugin/LibraryMonitor.cs index e9c1363..7c8f31c 100644 --- a/JellyfinPlugin/LibraryMonitor.cs +++ b/JellyfinPlugin/LibraryMonitor.cs @@ -57,7 +57,9 @@ namespace JellyfinPlugin { try { - if (video.ProviderIds != null && video.ProviderIds.ContainsKey("BlackBarCrop")) + if (video.ProviderIds != null && + video.ProviderIds.TryGetValue("BlackBarCrop", out string? existingCrop) && + !string.IsNullOrEmpty(existingCrop)) { return; } diff --git a/JellyfinPlugin/Tasks/LibraryRetroactiveScanTask.cs b/JellyfinPlugin/Tasks/LibraryRetroactiveScanTask.cs index 6b6ce51..4b19445 100644 --- a/JellyfinPlugin/Tasks/LibraryRetroactiveScanTask.cs +++ b/JellyfinPlugin/Tasks/LibraryRetroactiveScanTask.cs @@ -48,7 +48,9 @@ namespace JellyfinPlugin.Tasks { cancellationToken.ThrowIfCancellationRequested(); - if (item.ProviderIds != null && item.ProviderIds.ContainsKey("BlackBarCrop")) + if (item.ProviderIds != null && + item.ProviderIds.TryGetValue("BlackBarCrop", out string? existingCrop) && + !string.IsNullOrEmpty(existingCrop)) { processed++; progress.Report((processed / (double)total) * 100); @@ -62,18 +64,16 @@ namespace JellyfinPlugin.Tasks { string cropData = await CropHelper.DetectCropAsync(path, config.CropDetectLimit); - if (item.ProviderIds == null) - { - item.ProviderIds = new Dictionary(); - } - - // Zawsze dodajemy flagę, nawet jak puste, żeby nie skanować drugi raz tego samego pliku - // (puste oznacza że nie ma czarnych pasów do ucięcia) - item.ProviderIds["BlackBarCrop"] = cropData ?? string.Empty; - await _libraryManager.UpdateItemAsync(item, item, ItemUpdateType.MetadataEdit, cancellationToken); - if (!string.IsNullOrEmpty(cropData)) + { + if (item.ProviderIds == null) + { + item.ProviderIds = new Dictionary(); + } + item.ProviderIds["BlackBarCrop"] = cropData; + await _libraryManager.UpdateItemAsync(item, item, ItemUpdateType.MetadataEdit, cancellationToken); _logger.LogInformation("Found black bars {Crop} in {Path}", cropData, path); + } } catch (Exception ex) { diff --git a/JellyfinPlugin/WrapperGenerator.cs b/JellyfinPlugin/WrapperGenerator.cs index 1ba0ce5..95bad56 100644 --- a/JellyfinPlugin/WrapperGenerator.cs +++ b/JellyfinPlugin/WrapperGenerator.cs @@ -92,9 +92,7 @@ for (( i=1; i<=$#; i++ )); do done if [ -n ""$INPUT_FILE"" ]; then - # Jellyfin przekazuje ścieżkę z prefiksem file: (np. file:""/home/...""). - # Shell usuwa cudzysłowy automatycznie – zostaje nam tylko file: do usunięcia. - CLEAN_PATH=""${{INPUT_FILE#file:}}"" + CLEAN_PATH=$(echo ""$INPUT_FILE"" | tr -d '""' | sed 's/^file://') CROP_DATA=$(curl -s --max-time 1 -G --data-urlencode ""Path=$CLEAN_PATH"" http://127.0.0.1:8096/BlackBarRemover/CropByPath)