fix: stop fodler name as names

This commit is contained in:
2026-04-05 17:22:35 +02:00
parent 6fd2638414
commit 82b34e288c

View File

@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
@@ -318,10 +319,11 @@ public class SmartNotifyBackgroundService : IHostedService, IDisposable
if (item is Episode episode)
{
// episode.SeriesName / SeriesId are often null with Shokofin VFS,
// but the Series navigation property usually works
var seriesObj = episode.Series;
notification.SeriesName = episode.SeriesName ?? seriesObj?.Name;
var rawSeriesName = episode.SeriesName ?? seriesObj?.Name;
// If the name still looks like a Sonarr folder name, leave it null
// so the incomplete-episode logic defers until metadata scrape is done.
notification.SeriesName = LooksLikeFolderName(rawSeriesName) ? null : rawSeriesName;
notification.SeriesId = (episode.SeriesId != Guid.Empty
? episode.SeriesId
: seriesObj?.Id ?? Guid.Empty).ToString();
@@ -430,18 +432,38 @@ public class SmartNotifyBackgroundService : IHostedService, IDisposable
var changed = false;
// Always refresh SeriesName from the library — at queue time the name
// may have been the Sonarr folder name (before metadata refresh).
// Refresh SeriesName from the library. At queue time the name is often
// the Sonarr folder name (e.g. "Chained Soldier (2024) [tmdbid-139060]").
// After Jellyfin's metadata scrape completes, the name changes to the
// correct provider name (e.g. "Demon Slave - The Chained Soldier").
// We detect the unscraped folder name by checking for bracket patterns
// like [tmdbid-...] or (2024) and clear the SeriesName so the
// incomplete-episode logic defers sending until the scrape is done.
{
var freshSeriesName = episode.SeriesName ?? episode.Series?.Name;
if (!string.IsNullOrEmpty(freshSeriesName) && freshSeriesName != notification.SeriesName)
if (!string.IsNullOrEmpty(freshSeriesName))
{
_logger.LogInformation(
"[DEBUG Refresh] SeriesName changed: '{Old}' -> '{New}'",
notification.SeriesName,
freshSeriesName);
notification.SeriesName = freshSeriesName;
changed = true;
if (LooksLikeFolderName(freshSeriesName))
{
// Still the Sonarr folder name — clear so we keep waiting
if (!string.IsNullOrEmpty(notification.SeriesName))
{
_logger.LogInformation(
"[DEBUG Refresh] SeriesName '{Name}' looks like a folder name, clearing to defer",
freshSeriesName);
notification.SeriesName = null;
changed = true;
}
}
else if (freshSeriesName != notification.SeriesName)
{
_logger.LogInformation(
"[DEBUG Refresh] SeriesName changed: '{Old}' -> '{New}'",
notification.SeriesName,
freshSeriesName);
notification.SeriesName = freshSeriesName;
changed = true;
}
}
}
@@ -705,6 +727,19 @@ public class SmartNotifyBackgroundService : IHostedService, IDisposable
}
}
/// <summary>
/// Detects Sonarr-style folder names that haven't been replaced by a metadata scrape yet.
/// Matches patterns like "[tmdbid-139060]", "[tvdbid-412656]", "[imdbid-tt1234]".
/// </summary>
private static readonly Regex FolderNamePattern = new(
@"\[(tmdbid|tvdbid|imdbid)-[^\]]+\]",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static bool LooksLikeFolderName(string? name)
{
return !string.IsNullOrEmpty(name) && FolderNamePattern.IsMatch(name);
}
/// <inheritdoc />
public void Dispose()
{