Skip to content

Instantly share code, notes, and snippets.

@softworkz
Last active February 11, 2023 17:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save softworkz/a7658c16e621fad8868a959636b9169a to your computer and use it in GitHub Desktop.
Save softworkz/a7658c16e621fad8868a959636b9169a to your computer and use it in GitHub Desktop.
Generate M3U Playlist for SiliconDust HDHomerun Tuners

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!

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://github.com/softworkz)
Date:   May 14, 2021
<#
.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="'&#13;'" />
<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, '&quot; tvg-chno=&quot;', GuideNumber, '&quot; tvg-name=&quot;', GuideName, '&quot; group-title=&quot;')" />
<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('&quot; tvg-type=&quot;live&quot;,', GuideName, '&#13;')" />
<xsl:value-of select="concat(URL, '&#13;')" />
</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
@Gbreezy83
Copy link

Why not just use

http://hdhomerun.local/lineup.m3u http://HDHomeRun-device-name-here/lineup.m3u http://HDHomeRun-IP-here/lineup.m3u

The list gets exported from the units it self directly ?

Hi sorry to bother so do you have to put the dash before the ip address?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment