Skip to content

Instantly share code, notes, and snippets.

@caseyavila
Forked from aaearon/hdhr-listings-to-m3u.py
Last active September 19, 2024 06:07
Show Gist options
  • Save caseyavila/f37abe5490d4abfc83a75e65056bda6c to your computer and use it in GitHub Desktop.
Save caseyavila/f37abe5490d4abfc83a75e65056bda6c to your computer and use it in GitHub Desktop.
Convert HDHomeRun Prime Listings to M3U Format
#!/usr/bin/env python3
#
# 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
#
# original author Josh Kastang (josh[dot]kastang[at]gmail[dot]com)
#
# Converted to Python 3 and revised to support Jellyfin by Casey Avila
# - Added automatic finding of HDHomeRun ip address
# - Added ability to opt out of duration
import requests
import json
ip_request = requests.get("http://ipv4-api.hdhomerun.com/discover");
use_duration = True
config = {
# Uses first HDHomeRun found on network
'hdhr-ip' : json.loads(ip_request.text)[0]["LocalIP"],
'duration' : '7200',
}
hdhr_url = "http://{}/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:-1 tvg-chno="{}" tvg-name="{}",{}'.format(channel, name, name))
if use_duration:
print("http://{}:5004/auto/v{}?duration={}".format(
config['hdhr-ip'],
channel,
config['duration'])
)
else:
print("http://{}:5004/auto/v{}".format(
config['hdhr-ip'],
channel)
)
@PilotBob42
Copy link

A very handy little script! Thank you. I used it to make an .m3u file to use with Hypnotix on Linux Mint.

@hmj78
Copy link

hmj78 commented Nov 24, 2022

python hdhr-listing-to-m3u.py > hdr.m3u

Traceback (most recent call last):
File "hdhr-listing-to-m3u.py", line 18, in
import requests
ModuleNotFoundError: No module named 'requests'

@caseyavila
Copy link
Author

@hmj78 use pip install requests

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