using System;
using System.Security.Cryptography;
using System.Text;
namespace Jellyfin.Plugin.SRFPlay.Utilities;
///
/// Helper class for URN-related operations.
///
public static class UrnHelper
{
///
/// Generates a deterministic GUID from a URN.
/// This ensures the same URN always produces the same GUID.
/// MD5 is used for non-cryptographic purposes only (generating stable IDs).
///
/// The URN to convert.
/// A deterministic GUID string.
#pragma warning disable CA5351 // MD5 is used for non-cryptographic purposes (ID generation)
public static string ToGuid(string urn)
{
var hash = MD5.HashData(Encoding.UTF8.GetBytes(urn));
var guid = new Guid(hash);
return guid.ToString();
}
#pragma warning restore CA5351
///
/// Determines whether a URN refers to a livestream (scheduled or continuous).
/// This is a URN-only heuristic that needs no API call, so it stays usable long after
/// the broadcast has ended and the media composition is no longer worth fetching.
///
/// The URN to inspect. May be null or empty.
/// True if the URN identifies livestream content.
public static bool IsLivestreamUrn(string? urn)
{
return !string.IsNullOrEmpty(urn)
&& urn.Contains("livestream", StringComparison.OrdinalIgnoreCase);
}
}