-
Notifications
You must be signed in to change notification settings - Fork 0
/
stremio-addon.py
84 lines (63 loc) · 2.14 KB
/
stremio-addon.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
#!/usr/bin/env python3
from generate_static_files import GenerateStaticFiles, METAHUB_URL, OPTIONAL_META
from flask import Flask, Response, jsonify, url_for, abort
from functools import wraps
app = Flask(__name__)
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True
MANIFEST = GenerateStaticFiles.getFiles("src/MANIFEST")
CATALOG = GenerateStaticFiles.getFiles("src/CATALOG")
STREAMS = GenerateStaticFiles.getFiles("src/STREAMS")
def respond_with(data):
resp = jsonify(data)
resp.headers['Access-Control-Allow-Origin'] = '*'
resp.headers['Access-Control-Allow-Headers'] = '*'
return resp
@app.route('/manifest.json')
def addon_manifest():
return respond_with(MANIFEST)
@app.route('/catalog/<type>/<id>.json')
def addon_catalog(type, id):
if type not in MANIFEST['types']:
abort(404)
catalog = CATALOG[type] if type in CATALOG else []
metaPreviews = {
'metas': [
{
'id': item['id'],
'type': type,
'name': item['name'],
'genres': item['genres'],
'poster': METAHUB_URL.format(item['id'])
} for item in catalog
]
}
return respond_with(metaPreviews)
@app.route('/meta/<type>/<id>.json')
def addon_meta(type, id):
if type not in MANIFEST['types']:
abort(404)
def mk_item(item):
meta = dict((key, item[key])
for key in item.keys() if key in OPTIONAL_META)
meta['id'] = item['id']
meta['type'] = type
meta['name'] = item['name']
meta['genres'] = item['genres']
meta['poster'] = METAHUB_URL.format(item['id'])
return meta
meta = {
'meta': next((mk_item(item)
for item in CATALOG[type] if item['id'] == id),
None)
}
return respond_with(meta)
@app.route('/stream/<type>/<id>.json')
def addon_stream(type, id):
if type not in MANIFEST['types']:
abort(404)
streams = {'streams': []}
if type in STREAMS and id in STREAMS[type]:
streams['streams'] = STREAMS[type][id]
return respond_with(streams)
if __name__ == '__main__':
app.run()