|
<# |
|
.SYNOPSIS |
|
|
|
Creates an M3U playlist for an HDHomerun tuner |
|
|
|
.DESCRIPTION |
|
|
|
Downloads the lineup from an HDHR tuner, specified by IP address and transforms it into an M3U plalist |
|
|
|
When you don't specify an output file, the m3u content will be printed out for preview. |
|
|
|
The output file will be generated as UTF-8 without BOM, which isn't the case when you just pipe the output into a file! |
|
|
|
Author: softworkz (https://gist.github.com/softworkz/a7658c16e621fad8868a959636b9169a) |
|
Date: May 14, 2021 |
|
|
|
.PARAMETER $ipaddress |
|
|
|
The IP address of the tuner |
|
|
|
.PARAMETER $outfile |
|
|
|
An optional filename to which to save the M3U |
|
|
|
.EXAMPLE |
|
|
|
C:\PS> |
|
.\hdhr_get_m3u.ps1 192.168.1.1 out.m3u |
|
|
|
.EXAMPLE |
|
|
|
C:\PS> |
|
.\hdhr_get_m3u.ps1 192.168.1.1 |
|
|
|
.NOTES |
|
|
|
Author: softworkz (https://gist.github.com/softworkz/a7658c16e621fad8868a959636b9169a) |
|
Date: May 14, 2021 |
|
#> |
|
|
|
param( |
|
[Parameter(Mandatory=$true)] |
|
[string]$ipaddress, |
|
[Parameter(Mandatory=$false)] |
|
[string]$outfile |
|
) |
|
|
|
$xslt = @' |
|
<?xml version="1.0" encoding="utf-8"?> |
|
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
|
<xsl:output method="text" encoding="utf-8" /> |
|
<xsl:template match="/" xml:space="default"> |
|
<xsl:text>#EXTM3U</xsl:text> |
|
<xsl:value-of select="' '" /> |
|
<xsl:apply-templates select="Lineup/Program"/> |
|
</xsl:template> |
|
<xsl:template match="Program"> |
|
<xsl:text>#EXTINF:-1 tvg-id="</xsl:text> |
|
<xsl:value-of select="concat(GuideNumber, '" tvg-chno="', GuideNumber, '" tvg-name="', GuideName, '" group-title="')" /> |
|
<xsl:choose> |
|
<xsl:when test="Favorite = 1"> |
|
<xsl:text>Favorites</xsl:text> |
|
</xsl:when> |
|
<xsl:otherwise> |
|
<xsl:text>Other</xsl:text> |
|
</xsl:otherwise> |
|
</xsl:choose> |
|
<xsl:value-of select="concat('" tvg-type="live",', GuideName, ' ')" /> |
|
<xsl:value-of select="concat(URL, ' ')" /> |
|
</xsl:template> |
|
</xsl:stylesheet> |
|
'@ |
|
|
|
$stringreader = new-object System.IO.StringReader($xslt) |
|
$xsltreader = [System.Xml.XmlReader]::create($stringreader) |
|
|
|
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform |
|
$xslt.Load($xsltreader) |
|
|
|
$url = "http://" + $ipaddress + "/lineup.xml" |
|
$output = New-Object System.IO.MemoryStream |
|
$arglist = new-object System.Xml.Xsl.XsltArgumentList |
|
|
|
$xslt.Transform($url, $arglist, $output) |
|
|
|
$output.position = 0 |
|
$reader = new-object System.IO.StreamReader($output) |
|
$transformed = [string]$reader.ReadToEnd() |
|
$reader.Close() |
|
|
|
if ($outfile) { |
|
|
|
$dir = Split-Path -LiteralPath $outfile |
|
if ($dir) { $dir = Convert-Path -ErrorAction Stop -LiteralPath $dir } else { $dir = $pwd.ProviderPath} |
|
$outfile = [IO.Path]::Combine($dir, [IO.Path]::GetFileName($outfile)) |
|
$sw = New-Object System.IO.StreamWriter $outfile |
|
$sw.Write($transformed) |
|
$sw.Close() |
|
exit |
|
} |
|
|
|
Write-Output $transformed |
Thank you! This is exactly what I needed!