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
@mkanet
Copy link

mkanet commented Oct 10, 2022

Thank you! This is exactly what I needed!

@Daniel15
Copy link

Thank you! This worked perfectly for me 😄

@softworkz
Copy link
Author

Thanks, I'm glad to hear - I had almost forgotten about this 😆

@Gbreezy83
Copy link

Hi, how do you do this? It's confusing lol. Do you have other instructions I can follow lol? Trying to convert my HDHomerun to m3u

@Gbreezy83
Copy link

Thank you! This worked perfectly for me 😄

Hi sorry to bother trying to do this but a little confusing do I need to put this script in notepad++?

@Daniel15
Copy link

Daniel15 commented Jan 24, 2023

@Gbreezy83
Save it somewhere as hdhr_get_m3u.ps1. You can copy-paste it into Notepad++ and save it, that's fine
Open either Windows Terminal (if you've installed it via the Microsoft Store - it's free and very nice), or a PowerShell console
Change to the directory the script is in, for example:

cd C:\Users\Daniel\Downloads

Run it:

./hdhr_get_m3u.ps1 10.1.2.10

(with the correct IP)

If you've never ran a PowerShell script before, you may need to modify the settings to allow script execution: https://superuser.com/questions/106360/how-to-enable-execution-of-powershell-scripts

PowerShell scripts are the modern replacement for batch files.

@Gbreezy83
Copy link

@Daniel15 Thanks for the quick reply oh okay not too good with this kind of stuff lol.🙏🏾

@wazerstar
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 ?

@softworkz
Copy link
Author

I think it didn't in May 2021 when I had posted this.

@wazerstar
Copy link

I think it didn't in May 2021 when I had posted this.

Ahh yes you are right.

HDHomeRun Firmware (20220831beta1)
Add /lineup.m3u for use with VLC and other apps that import m3u channel lists.

btw, Is there anywhere I can contact you directly?

@Daniel15
Copy link

Daniel15 commented Feb 7, 2023

I think it didn't in May 2021 when I had posted this.

Ahh yes you are right.

HDHomeRun Firmware (20220831beta1) Add /lineup.m3u for use with VLC and other apps that import m3u channel lists.

btw, Is there anywhere I can contact you directly?

Oh nice! I haven't upgraded my HDHomeRun in a long time so I didn't have this feature. Just upgraded it now.

@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