Skip to content

Instantly share code, notes, and snippets.

@shmick
Created May 21, 2026 23:37
Show Gist options
  • Select an option

  • Save shmick/f935fb570231542630b4e747801ec451 to your computer and use it in GitHub Desktop.

Select an option

Save shmick/f935fb570231542630b4e747801ec451 to your computer and use it in GitHub Desktop.
Use HDHomeRun EPG with Jellyfin
#!/usr/bin/env bash
set -euo pipefail
OUTPUT="/mnt/pool0/docker-vols/jellyfin/config/hdhr-epg.xml"
TMPFILE="$(mktemp)"
IPS=("192.168.1.31" "192.168.1.32")
AUTH=""
SUCCESS=0
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"
}
# Try each device until we get a valid DeviceAuth
for ip in "${IPS[@]}"; do
log "Trying HDHomeRun at $ip"
AUTH=$(curl -fsS --max-time 5 "http://$ip/discover.json" | jq -r '.DeviceAuth' || true)
if [[ -n "$AUTH" && "$AUTH" != "null" ]]; then
log "Got DeviceAuth from $ip"
# Download XMLTV data
if curl -fsS --max-time 20 \
-H 'Accept-Encoding: gzip' --compressed \
"https://api.hdhomerun.com/api/xmltv?DeviceAuth=$AUTH" \
-o "$TMPFILE"; then
# Validate XML
if xmllint --noout "$TMPFILE" 2>/dev/null; then
log "XML validated successfully"
SUCCESS=1
break
else
log "Invalid XML from $ip, trying next..."
fi
else
log "Failed to download XML from API using auth from $ip"
fi
else
log "Failed to get DeviceAuth from $ip"
fi
done
# Replace the file only if everything succeeded
if [[ $SUCCESS -eq 1 ]]; then
mv "$TMPFILE" "$OUTPUT"
log "EPG successfully updated at $OUTPUT"
else
log "Failed to update EPG from all sources"
rm -f "$TMPFILE"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment