Skip to content

Instantly share code, notes, and snippets.

@jwmoss
Created October 7, 2021 02:11
Show Gist options
  • Save jwmoss/194fbcfc43b69a66f3a0f608f848bcad to your computer and use it in GitHub Desktop.
Save jwmoss/194fbcfc43b69a66f3a0f608f848bcad to your computer and use it in GitHub Desktop.
function Search-M3UFile {
[CmdletBinding()]
param (
[string[]]
$Filter,
[string]
$Path
)
begin {
$preload = Get-Content $Path
$regex_filter = ($filter | ForEach-Object {
[regex]::escape($_)
}
) –join "|"
}
process {
## Preload the variable with said M3U content.
## Start loading the Arrays used to build the menu
$TSLinkArray = $preload | Select-String '^.*\.ts$'
$StreamData = $preload | Select-String '(?<=tvg-name=")[^"]+' | ForEach-Object { $_.Matches.Value }
$Group = $preload | Select-String '(?<=group-title=")[^"]+' | ForEach-Object { $_.Matches.Value }
## Setup Array for loading Menus Properly
$linkdata = if ($TSLinkArray.count -eq $StreamData.count) {
for ($i = 1; $i -le $StreamData.count; $i++) {
[pscustomobject]@{
StreamLink = $TSLinkArray[$i]
StreamData = $StreamData[$i]
Group = $Group[$i]
}
}
}
$linkdata |
Where-Object {$PSItem.StreamData -match $regex_filter}
}
End {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment