[I had posted this on the DVR software forum, but this seems to be a more appropriate place for it.]
This post is for folks who would like to bring in external recordings into the HDHomeRun environment.
HDHomeRun identifies compatible files by looking for a JSON structure in the first 12032 bytes of a TS file.
Editing this block manually is tricky as it requires a 4-byte separator sequence every 188 bytes (184+4).
Below is a simple PowerShell script that will spit out the appropriate JSON block to the console and to a file. You will need to populate your data and edit the path for your environment.
The script is simple since it doesn't directly edit the video file (yet). I use a byte editor such as HxD Hex Editor (on Windows) to copy/paste the desired JSON to the desired video file (after using MCEBuddy with the HDHomeRun profile to prepare the file).
There are others who have worked on this problem (garybuhrmaster & TPeterson), though I didn't know about them when I put this together. The only advantage of this script is that it does not require a programming environment.
One more note: for the system to display the remaining time properly, you will also need to put proper values in the JSON fields: RecordStartTime and RecordEndTime. I have a separate spreadsheet for that but, in brief, the start time should be the number of seconds from 1/1/1970 and the end time should be that number plus the video length in seconds.
Enjoy,
Michael
# PowerShell script to generate a JSON-like byte array with 184-character blocks, separated by a specific sequence
# Function to generate a JSON-like byte array with separators
Function GenerateJSONByteArrayWithSeparators {
param (
[hashtable]$jsonFields,
[int]$blockSize,
[byte[]]$separatorBytes
)
# Initialize a byte array to hold the full data
$byteArray = @()
# Add the initial separator
$byteArray += $separatorBytes
# Initialize character count and add the opening curly brace
$charCount = 1
$byteArray += [System.Text.Encoding]::UTF8.GetBytes("{")
# Iterate over each key-value pair in the JSON fields
foreach ($key in $jsonFields.Keys) {
# Generate the text block for the key-value pair
$textBlock = "`"$key`":`"$($jsonFields[$key])`","
# Convert the text block to a byte array using UTF8 encoding
$textBlockBytes = [System.Text.Encoding]::UTF8.GetBytes($textBlock)
# Add each byte to the full byte array
foreach ($byte in $textBlockBytes) {
# Check if adding the next byte will exceed the block size
if ($charCount -eq $blockSize) {
# Insert the separator at the current position
$byteArray += $separatorBytes
# Reset character count after the separator
$charCount = 0
}
$byteArray += $byte
$charCount++
}
}
# Trim the trailing comma bytes and add the closing curly brace byte
$byteArray = $byteArray[0..($byteArray.Length - 2)] + [System.Text.Encoding]::UTF8.GetBytes("}")
# Add a final separator if the last block is exactly the block size
if ($charCount -eq $blockSize) {
$byteArray += $separatorBytes
}
# Return the full byte array with separators
return $byteArray
}
# Define the JSON fields as a hashtable
$jsonFields = @{
"Category" = "series"
"ChannelAffiliate" = "PBS"
"ChannelImageURL" = "https://img.hdhomerun.com/channels/US44690.png"
"ChannelName" = "KQEHDT"
"ChannelNumber" = "710"
"EndTime" = "1714942800"
"EpisodeNumber" = "S18E03"
"EpisodeTitle" = "Florencia en el Amazonas"
"FirstAiring" = 1
"ImageURL" = "https://img.hdhomerun.com/titles/C241428ENQ05X.jpg"
"OriginalAirdate" = "1712448000"
"ProgramID" = "EP008811450179"
"RecordEndTime" = "1714942830"
"RecordStartTime" = "1714935571"
"Resume" = "1425"
"SeriesID" = "C241428ENQ05X"
"StartTime" = "1714935600"
"Synopsis" = "Mexican composer Daniel Catán's opera tells the story of an opera diva who returns to her native South America to perform at the Manaus opera house and to search for her lost lover."
"Title" = "Great Performances at the Met"
}
# Define the block size and separator bytes
$blockSize = 184
$separatorBytes = @(0x47, 0x5F, 0xFA, 0x10)
# Call the function to generate the JSON-like byte array with separators
$jsonByteArrayWithSeparators = GenerateJSONByteArrayWithSeparators -jsonFields $jsonFields -blockSize $blockSize -separatorBytes $separatorBytes
# Convert byte array to a readable string with separators for console output
$readableString = [System.Text.Encoding]::UTF8.GetString($jsonByteArrayWithSeparators)
# Output the readable string to the console
Write-Output $readableString
# Write the byte array to a file
$filePath = "C:\Users\michael\Downloads\output.txt"
[System.IO.File]::WriteAllBytes($filePath, $jsonByteArrayWithSeparators)
Populating HDHomeRun Metadata - PowerShell Script
-
- Posts: 672
- Joined: Tue Oct 06, 2015 1:25 pm
- x 1
Re: Populating HDHomeRun Metadata - PowerShell Script
Not sure this is needed as mcebuddy should handle the metadata in the correct format for the hdhrdvr by itself.
Re: Populating HDHomeRun Metadata - PowerShell Script
Yes and no.techpro2004 wrote: ↑Sat Oct 19, 2024 1:05 pm Not sure this is needed as mcebuddy should handle the metadata in the correct format for the hdhrdvr by itself.
Mcebuddy does insert some basic metadata so that the program shows up in the HDHomeRun front-end.
However, the limitations are:
- Each recording gets a new gray block with its title but no graphic (as Mcebuddy doesn't know where to place it)
- There is no begin/end times entered, so you can't easily fast forward or know how much time remains
- There is no description beyond the file name