Project

General

Profile

RE: HDHomerun getting channels setup to export to m3u ยป hdhr-listing-to-m3u.py

G Kazaroth, 2020-12-25 23:30

 
1

    
2
# this script will convert the hdhomerun listings (channels) to
3
# m3u format for use with external media players. before running
4
# this script, be sure to modify the <<config>> variable settings
5
# below.
6
#
7
# Suggested Usage: This script should be run on a cron to keep
8
# the channel lineup to date. Below is an example of how to execute this script:
9
# python /path/to/script/hdhomerun-prime-listings-to-m3u.py > /path/to/playlist.m3u
10
#
11
# @author Josh Kastang (josh[dot]kastang[at]gmail[dot]com)
12
# @tested Python 2.7, but should work with Python 2.6 as well.
13
#
14

    
15
# use cmd to find all devices:
16
#   hdhomerun_config discover
17

    
18
import requests
19
import json
20
from pprint import pprint
21

    
22
# * hdhr-ip: ip address of your hdhr prime unit
23
# * duration: the duration the stream should play for. some
24
# players seem to require this while others do not. default
25
# is set for 7200 minutes (2 hours)
26
config = {
27
#    'hdhr-ip'   : 'HDHR-1072AB1A',   # HR4
28
#    'hdhr-ip'   : 'HDHR-10531CD0',   # HR
29
    'hdhr-ip'   : 'HDHR-104ED41E',   # HR2
30

    
31
    'duration'  : '7200',
32
}
33

    
34
hdhr_url        = "http://{0}/lineup.json?show=unprotected".format(config['hdhr-ip'])
35
response_obj    = requests.get(hdhr_url)
36
listings_res    = response_obj.text
37

    
38
print( "#EXTM3U" )
39
listings = json.loads(listings_res)
40
for l in listings:
41
    channel = l['GuideNumber']
42
    name    = l['GuideName']
43

    
44
    print( "#EXTINF:{0},{1} {2}".format(channel,channel, name) )
45
    print( "http://{0}:5004/auto/v{1}".format(
46
            config['hdhr-ip'],
47
            channel,
48
    ))
49

    
    (1-1/1)