2014-05-12, 21:10
For those with a SiliconDust HDHomeRun Prime - I used a powershell script written by user wtg on the silicondust forums that I slightly modified. this will work on windows 7 or 8 while running powershell as admin.
Code:
<#
.Synopsis
Creates .strm files that can be used by XBMC to view live TV using a Silicon Dust HDHomeRun.
.Parameter device
If unspecified the script discovers your device id automatically, which should be fine unless you
have multiple HDHomeRuns. If you do have multiple devices, supply the ID of the device you wish
to generate strm files for.
.Parameter tuner
(Optional, default = 0) Supply a different tuner number if desired.
.Parameter outputDir
(Optional, default = %TEMP%) Directory to write the .strm files to. Supply another directory name
if desired, or a period for the current directory.
.Parameter LineUpXML
(Optional, default = "%ProgramData%\SiliconDust\HDHomeRun\Digital*.xml") If you have both a
"Digital Cable.XML" and "Digital Antenna.XML" scan file because you're using the original HDHomeRun
with both cable and antenna inputs - or have at least run a GUI scan from both sources at some
point - you'll need to specify the filename. By the default the script grabs whichever file it finds
in the Silicon Dust program data directory.
.Parameter pad
(Optional) Zero-pad the channel numbers to the specified number of digits.
.Parameter scan
Specify this option if you want the process to generate the files by running a command-line scan
and processing the results. If unspecified the file is generated via the XML file in which the
HDHomeRun stores the last gui scan results. It's much slower to force a scan and the stream files
won't be named as meaningfully.
.Example
.\gen_strms.ps1 -outputDir c:\temp
Generate streams for tuner 0 and write the files to c:\temp.
.Example
.\gen_strms.ps1 -tuner 1 -out c:\temp
Generate streams for tuner 1 and write to c:\temp. Parms don't need to be spelled out completely.
.Example
.\gen_strms.ps1 -out . -LineUpXML 'c:\ProgramData\SiliconDust\HDHomeRun\Digital Cable.xml'
Generate streams for tuner 0 and write files to the current directory, using the Digital Cable.xml
file.
.NOTES
Date Version Comments
-------- ------- -------------------------------------------------------
10/22/12 1.0 Initial release
11/08/12 1.1 Added ability to specify a scan file on the command line;
added error message if two XML scan files are found; added
tuner to the output file name; added support for padding
channel numbers; improved support for scan file.
#>
Param(
[string] $device = 'FFFFFFFF',
[string] $tuner = '0',
[string] $outputDir = "$env:temp",
[int] $pad = 1,
[string] $LineUpXML = "$env:ProgramData\SiliconDust\HDHomeRun\CableCard*.xml",
[switch] $scan = $false,
[string] $ScanFile = "")
# create a regex pattern to find invalid characters in a filename
$invalid_chars = "[{0}]" -f ([Regex]::Escape([System.IO.Path]::GetInvalidFileNameChars()-join''))
if ( $device -eq 'FFFFFFFF' ) {
# discover the device id, or the last one reported if more than one
& "$env:programfiles\silicondust\hdhomerun\hdhomerun_config.exe" discover | %{
switch -regex ($_) {
"device (\w+) found" { $device = $matches[1] }
}
}
write-host "Creating streams for device id $device"
}
if ( $scan -or $ScanFile -gt '' ) {
if ( $scan ) {
write-host "Starting scan - this can take a while..."
$scan_data = & "$env:programfiles\silicondust\hdhomerun\hdhomerun_config.exe" $device scan $tuner
} else {
Write-Host "Reading scan file $ScanFile..."
$scan_data = get-content $ScanFile
}
$scan_data | % {
switch -regex ( $_ ) {
"SCANNING.*:(?<chan>\d+)" { $chan = $matches.chan
write-verbose "Processing physical channel $chan"
break
}
"PROGRAM (?<PID>\d+): (?<prog>\d*\.*\d*)\s*(?<chan_name>.*)" {
$ProgID = $matches.PID
$prog = $matches.prog
$chan_name = $matches.chan_name
if ( $chan_name -eq "" ) { $chan_name = 'Blank' }
if ( $chan_name -match "(\(encrypted\)|\(control\)|\(no data\))" ) {
write-verbose "Channel $chan_name, program $prog is encrypted or has no data"
break
}
# write the data to the file.
if ( $chan -match '[.]' ) {
# The guide number has a period in it and thus shouldn't be padded
$number = $chan
} else {
$number = ("{0:d$pad}" -f [int]$chan)
}
$file = "$number-$ProgID ($tuner)-$chan_name.strm"
$file = Join-Path $OutputDir ([Regex]::Replace($file, $invalid_chars, ''))
write-host "Writing stream file $file."
"hdhomerun://$device-$tuner/tuner$tuner`?channel=auto:$chan&program=$ProgID" `
| out-file -FilePath $file -encoding "ASCII"
}
}
}
} else {
# Verify path to GUI listing file.
switch ( ([array](dir $LineUpXML)).count ) {
1 {
write-output "Loading HDHomeRun's lineup file from last GUI scan..."
$xml = [xml](get-content $LineUpXML)
}
{$_ -gt 1} { throw "More than 1 file exists matching $LineUpXML. Use -LineUpXML option to specify while file to use." }
default { throw "ERROR: Cannot find HDHomeRun's GUI's lineup file $LineUpXML. " }
}
Write-Output "Number of channels found: " $xml.LineUp.Program.Count
$xml.LineUp.Program | %{
if ($_.Enabled -eq 'true') {
if ( $_.GuideNumber -match '[.]' ) {
# The guide number has a period in it and thus shouldn't be padded
$number = $_.GuideNumber
} else {
$number = ("{0:d$pad}" -f [int]$_.GuideNumber)
}
$file = "$number ($tuner)-" + $_.Name + '.strm'
$file = Join-Path $OutputDir ([Regex]::Replace($file, $invalid_chars, ''))
write-host "Writing stream file $file."
"hdhomerun://$device-$tuner/tuner$tuner`?channel=$($_.Modulation):$($_.Frequency)&program=$($_.ProgramNumber)" `
| out-file -FilePath $file -encoding "ASCII"
}
}
}