-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdashcam-browse.py
executable file
·64 lines (55 loc) · 1.74 KB
/
dashcam-browse.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
#!/usr/bin/env python3
import xmltodict
import requests
import json
from bottle import route, run, template, request, response, static_file
# `property` must be "Normal" or "Event"
# ?backward=1&count=30&property=Normal&from=0&action=dir&format=all
@route('/list')
def list():
if debug:
f = open("sample_list.xml", "r")
xml = f.read()
f.close()
else:
r = requests.get("%scgi-bin/Config.cgi?%s" %
(config['CAMERA']['URL'],request.query_string))
assert r.status_code == 200, "HTTP error %d" % r.status_code
assert r.headers["Content-Type"] == "text/xml"
xml = r.content
response.headers['Content-Type'] = 'application/json'
j = xmltodict.parse(xml)
j['URL'] = config['CAMERA']['URL']
return json.dumps(j)
@route('/')
def index():
return static_file('index.html',root='.')
@route('/scripts.js')
def index():
return static_file('scripts.js', root='.')
# Params: path, width
@route('/show')
def show():
return """
<video width="{width}" controls autoplay>
<source src="{url}{path}" type="video/mp4">
</video>
<br><a href="{url}{path}">Download</a>
""".format(
url=config['CAMERA']['URL'],
path=request.query.path.strip('/'),
width=request.query.width
)
def main():
import argparse, configparser
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--config", default='dashcam.cfg', help="config file")
parser.add_argument("-d", '--debug', action='store_true')
args = parser.parse_args()
global debug
debug = args.debug
global config
config = configparser.ConfigParser()
config.read(args.config)
run(host=config['WEB']['host'], port=config['WEB']['port'])
main()