Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert HDHomeRun Prime Listings to M3U Format
#!/usr/bin/env python
#
# 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)
#
# Converted to Python 3 and revised to support Jellyfin by Casey Avila
import sys
import urllib.requests
import json
# * 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' : sys.argv[1],
'duration' : '7200',
}
hdhr_url = "http://{}/lineup.json?show=unprotected".format(config['hdhr-ip'])
response_obj = urllib.requests.urlopen(hdhr_url)
listings_res = response_obj.read()
print("#EXTM3U")
listings = json.loads(listings_res)
for l in listings:
channel = l['GuideNumber']
name = l['GuideName']
print('#EXTINF:-1 tvg-chno="{}" tvg-name="{}",{}'.format(channel, name, name))
print("http://{}:5004/auto/v{}?duration={}".format(
config['hdhr-ip'],
channel,
config['duration']
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment