Skip to content

Instantly share code, notes, and snippets.

@wmcbrine
Created August 1, 2022 02:07
Show Gist options
  • Save wmcbrine/52fab2d8a54eceee585b08963694749a to your computer and use it in GitHub Desktop.
Save wmcbrine/52fab2d8a54eceee585b08963694749a to your computer and use it in GitHub Desktop.
List virtual and physical channel numbers found by HDHomeRun
#!/usr/bin/env python
""" List virtual and physical channel numbers found by HDHomeRun """
import json
try:
from urllib import request as r # Python 3
except:
import urllib as r # Python 2
ADDR = '192.168.1.80' # HDHomeRun IP
TEMP = 'http://%s/lineup.json?show=all&tuning'
# MHz to channel numbers 2-51
FREQS = {
# low VHF
57: 2, 63: 3, 69: 4, 79: 5, 85: 6,
# high VHF
177: 7, 183: 8, 189: 9, 195: 10, 201: 11, 207: 12, 213: 13,
# core UHF
473: 14, 479: 15, 485: 16, 491: 17, 503: 19, 509: 20, 515: 21,
521: 22, 527: 23, 533: 24, 539: 25, 545: 26, 551: 27, 557: 28,
563: 29, 569: 30, 575: 31, 581: 32, 587: 33, 593: 34, 599: 35,
605: 36,
# reserved
611: 37,
# shared with cell
617: 38, 623: 39, 629: 40, 635: 41, 641: 42, 647: 43, 653: 44,
659: 45, 665: 46, 671: 47, 677: 48, 683: 49, 689: 50, 695: 51
}
def getf(num):
return FREQS.get(num // 1000000, num)
def getn(item, name):
return ['', name][item.get(name, 0)]
raw = r.urlopen(TEMP % ADDR).read()
data = json.loads(raw)
# Physical number, virtual number, name, codecs, flags
output = ['%2d.%04d %5s %-7.7s %-5.5s %-3.3s %-2.2s %s' % (
getf(item.get('Frequency', 0)), item.get('ProgramNumber', 0),
item.get('GuideNumber', ''), item.get('GuideName', ''),
item.get('VideoCodec', ''), item.get('AudioCodec', ''),
getn(item, 'HD'), getn(item, 'ATSC3')
) for item in data]
# HDHR reports in virtual channel order, but I want physical order
output.sort()
for item in output:
print(item)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment