emby-toolbox/EmbyToolbox/Services/TrackStructureComparer.cs
Emby Toolbox 6264b487fe Initial commit: Emby Toolbox (conversion scroll fix, bulk Del for tracks).
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-12 21:33:47 +05:00

57 lines
1.5 KiB
C#

using System.Text;
using EmbyToolbox.Models;
namespace EmbyToolbox.Services;
public sealed class TrackStructureComparer
{
public string BuildSignature(IReadOnlyList<TrackOverrideEntry> tracks)
{
var sb = new StringBuilder(tracks.Count * 40);
for (var i = 0; i < tracks.Count; i++)
{
var t = tracks[i];
if (i > 0)
{
sb.Append("||");
}
sb.Append((int)t.Source);
sb.Append('|');
sb.Append((int)t.StreamKind);
sb.Append('|');
if (t.StreamKind is MediaStreamKind.Audio or MediaStreamKind.Subtitle)
{
sb.Append(NormalizeToken(t.Language));
sb.Append('|');
sb.Append(NormalizeToken(t.Title));
sb.Append('|');
}
sb.Append(NormalizeToken(ResolveCodecToken(t)));
}
return sb.ToString();
}
private static string ResolveCodecToken(TrackOverrideEntry t)
{
if (!string.IsNullOrWhiteSpace(t.ExternalStreamCodec))
{
return t.ExternalStreamCodec!;
}
return t.StreamKind == MediaStreamKind.Attachment ? "attachment" : string.Empty;
}
private static string NormalizeToken(string? value)
{
if (string.IsNullOrWhiteSpace(value))
{
return string.Empty;
}
var normalized = value.Trim().ToLowerInvariant();
return normalized.Replace(" ", " ", StringComparison.Ordinal);
}
}