Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function ConvertTo-ChannelForgeGuideEvidenceFromPlaylist {
- Channel has programmes: XMLTV evidence. StartUtc/EndUtc is the span the guide covers for that channel.
The guide is Stale when that span ended before BuildTimeUtc, else Current. State is SafeCandidate:
one source, never cross-checked. Source relationship stays Unknown.
- Channel has no programmes (or no usable tvg-id): ProviderM3UMetadata evidence, Unresolved, reasons
- Channel has no programmes (or no tvg-id): ProviderM3UMetadata evidence, Unresolved, reasons
EvidenceMissing and NoEventData. It is never dropped.
- Title is the channel display name, so each channel is one readiness group. Programme titles are not used.
Channels are sorted first, so the result does not depend on input order.
Expand Down Expand Up @@ -39,20 +39,22 @@ function ConvertTo-ChannelForgeGuideEvidenceFromPlaylist {
$ordered = @($Channel | Where-Object { $null -ne $_ } | Sort-Object { [string]$_.TvgId }, { [string]$_.DisplayName })
foreach ($c in $ordered) {
$tvgId = [string]$c.TvgId
$usable = $tvgId -cmatch '^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$'
$hasId = -not [string]::IsNullOrEmpty($tvgId)
$reference = if ($tvgId -cmatch '^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$') { $tvgId }
elseif ($hasId) { 'id-' + (Get-ChannelForgeDomainHash -Domain 'channelforge/guide-id/v1' -Bytes ([System.Text.UTF8Encoding]::new($false).GetBytes($tvgId))).Substring(0, 32) }
$name = [string]$c.DisplayName
$common = @{ SourceId = $SourceId; DisplayName = $name; Group = [string]$c.Group }
if ($usable) { $common.ChannelReference = $tvgId; $common.Title = $name }
if ($hasId) { $common.ChannelReference = $reference; $common.Title = $name }

if ($usable -and $span.ContainsKey($tvgId)) {
if ($hasId -and $span.ContainsKey($tvgId)) {
$s = $span[$tvgId]
New-ChannelForgeGuideEvidence -EvidenceType XMLTV @common `
-StartUtc $s.Start.UtcDateTime.ToString($format, $culture) -EndUtc $s.End.UtcDateTime.ToString($format, $culture) `
-ConfidenceState SafeCandidate -ConfidenceScore 70 `
-FreshnessState $(if ($s.End.UtcDateTime -lt $build) { 'Stale' } else { 'Current' })
}
else {
$codes = if ($span.ContainsKey($tvgId)) { @('InvalidGuideId') } else { @('EvidenceMissing', 'NoEventData') }
$codes = @('EvidenceMissing', 'NoEventData')
New-ChannelForgeGuideEvidence -EvidenceType ProviderM3UMetadata @common -ReasonCodes $codes
}
}
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/GuideEvidenceFromPlaylist.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,24 @@ Describe 'Guide evidence from a playlist and one guide' {
($two.Readiness | ConvertTo-Json -Depth 8) | Should -Be ($one.Readiness | ConvertTo-Json -Depth 8)
}
}

Describe 'Guide evidence for tvg-ids with spaces and symbols' {
BeforeAll {
$script:Odd = @((New-Chan 'BBC One (HD) | UK' 'One'), (New-Chan 'BBC One (HD) & UK' 'Two'), (New-Chan 'No Guide #1' 'Three'))
$script:OddProg = @((New-Prog 'BBC One (HD) | UK' '2026-10-01T10:00:00Z'), (New-Prog 'BBC One (HD) & UK' '2026-10-01T10:00:00Z'))
}

It 'counts a channel with programmes as guided, not missing, and keeps two odd ids apart' {
$r = Get-Ready $script:Odd $script:OddProg
@($r.Readiness.Records).Count | Should -Be 3
$r.Readiness.StateCounts.SafeCandidate | Should -Be 2
$r.Readiness.StateCounts.Unresolved | Should -Be 1
@($r.Evidence.ChannelReference | Where-Object { $_ } | Select-Object -Unique).Count | Should -Be 3
}

It 'gives the same result whatever the channel order' {
$one = Get-Ready $script:Odd $script:OddProg
$two = Get-Ready @($script:Odd[2..0]) @($script:OddProg[1..0])
($two.Readiness | ConvertTo-Json -Depth 8) | Should -Be ($one.Readiness | ConvertTo-Json -Depth 8)
}
}
Loading