forked from jkaberg/tvhProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tvhProxy.py
103 lines (77 loc) · 3.1 KB
/
tvhProxy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from gevent import monkey; monkey.patch_all()
import time
import os
import requests
from gevent.pywsgi import WSGIServer
from requests.auth import HTTPBasicAuth
from flask import Flask, Response, request, jsonify, abort, render_template
app = Flask(__name__)
# URL format: <protocol>://<username>:<password>@<hostname>:<port>, example: https://test:1234@localhost:9981
config = {
'username': 'admin',
'password': 'admin',
'port': 9981,
'domain': 'bzzoiro.duckdns.org',
#'domain': '192.168.1.156', #'bzzoiro.duckdns.org',
'persistent_auth_code': 'Pln4KmwBo51FkZhmTdWmG1ai2mlw',
'bindAddr': os.environ.get('TVH_BINDADDR') or '',
'tvhURL': os.environ.get('TVH_URL') or 'http://admin:admin@bzzoiro.duckdns.org:9981',
'tvhProxyURL': os.environ.get('TVH_PROXY_URL') or 'http://bzzoiro.duckdns.org',
'tunerCount': os.environ.get('TVH_TUNER_COUNT') or 1, # number of tuners in tvh
'tvhWeight': os.environ.get('TVH_WEIGHT') or 300, # subscription priority
'chunkSize': os.environ.get('TVH_CHUNK_SIZE') or 1024*1024, # usually you don't need to edit this
'streamProfile': os.environ.get('TVH_PROFILE') or 'pass' # specifiy a stream profile that you want to use for adhoc transcoding in tvh, e.g. mp4
}
discoverData = {
'FriendlyName': 'tvhProxy',
'Manufacturer' : 'Silicondust',
'ModelNumber': 'HDTC-2US',
'FirmwareName': 'hdhomeruntc_atsc',
'TunerCount': int(config['tunerCount']),
'FirmwareVersion': '20150826',
'DeviceID': '12345678',
'DeviceAuth': 'test1234',
'BaseURL': '%s' % config['tvhProxyURL'],
'LineupURL': '%s/lineup.json' % config['tvhProxyURL']
}
def compose_root_url():
return 'http://{}:{}@{}:{}'.format(config['username'], config['password'], config['domain'], config['port'])
@app.route('/discover.json')
def discover():
return jsonify(discoverData)
@app.route('/lineup_status.json')
def status():
return jsonify({
'ScanInProgress': 0,
'ScanPossible': 1,
'Source': "Cable",
'SourceList': ['Cable']
})
@app.route('/lineup.json')
def lineup():
lineup = []
for c in _get_channels():
if c['enabled']:
url = '{}/stream/channel/{}?ticket={}&profile=htsp'.format(compose_root_url(), c['uuid'], config['persistent_auth_code'])
lineup.append({'GuideNumber': str(c['number']),
'GuideName': c['name'],
'URL': url
})
return jsonify(lineup)
@app.route('/lineup.post', methods=['GET', 'POST'])
def lineup_post():
return ''
@app.route('/')
@app.route('/device.xml')
def device():
return render_template('device.xml',data = discoverData),{'Content-Type': 'application/xml'}
def _get_channels():
ts_url = 'api/channel/grid?start=0&limit=999999'
url = '%s/%s' % (compose_root_url(),ts_url,)
print(url)
r = requests.get(url)
return r.json()['entries']
if __name__ == '__main__':
print('----------------------------------------------------------------------------')
http = WSGIServer((config['bindAddr'], 5004), app.wsgi_app)
http.serve_forever()