Skip to content

Instantly share code, notes, and snippets.

@aaearon
Last active January 10, 2023 05:32
Show Gist options
  • Save aaearon/3e1d4958cf726066c8f55d15da7d86b4 to your computer and use it in GitHub Desktop.
Save aaearon/3e1d4958cf726066c8f55d15da7d86b4 to your computer and use it in GitHub Desktop.
Convert HDHomeRun Prime Listings to M3U Format
#
# this script will convert the hdhomerun listings (channels) to
# m3u format for use with external media players. before running
# this script, be sure to modify the <<config>> variable settings
# below.
#
# Suggested Usage: This script should be run on a cron to keep
# the channel lineup to date. Below is an example of how to execute this script:
# python /path/to/script/hdhomerun-prime-listings-to-m3u.py > /path/to/playlist.m3u
#
# @author Josh Kastang (josh[dot]kastang[at]gmail[dot]com)
# @tested Python 2.7, but should work with Python 2.6 as well.
#
import requests
import json
from pprint import pprint
# * hdhr-ip: ip address of your hdhr prime unit
# * duration: the duration the stream should play for. some
# players seem to require this while others do not. default
# is set for 7200 minutes (2 hours)
config = {
'hdhr-ip' : '192.168.1.100',
'duration' : '7200',
}
hdhr_url = "http://{0}/lineup.json?show=unprotected".format(config['hdhr-ip'])
response_obj = requests.get(hdhr_url)
listings_res = response_obj.text
print "#EXTM3U"
listings = json.loads(listings_res)
for l in listings:
channel = l['GuideNumber']
name = l['GuideName']
#print "#EXTINF:{0},{1}: {2}".format(channel,channel, name)
print '#EXTINF:-1 tvg-name="{1}" tvh-chnum="{0}",{1}'.format(channel, name)
print "http://{0}:5004/auto/v{1}?duration={2}".format(
config['hdhr-ip'],
channel,
config['duration']
)
@caseyavila
Copy link

Just a heads up, I ported this over to Python 3 and added dynamic IP address finding here: https://gist.github.com/caseyavila/f37abe5490d4abfc83a75e65056bda6c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment