-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathstremio-addon.py
More file actions
187 lines (157 loc) · 5.79 KB
/
stremio-addon.py
File metadata and controls
187 lines (157 loc) · 5.79 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env python3
from flask import Flask, Response, jsonify, url_for, abort
from functools import wraps
MANIFEST = {
'id': 'org.stremio.helloworldPython',
'version': '1.0.0',
'name': 'Hello World Python Addon',
'description': 'Sample addon made with Express providing a few public domain movies',
'types': ['movie', 'series'],
'catalogs': [
{'type': 'movie', 'id': 'Hello, Python'},
{'type': 'series', 'id': 'Hello, Python'}
],
'resources': [
'catalog',
# The meta call will be invoked only for series with ID starting with hpy
{'name': "meta", 'types': ["series"], 'idPrefixes': ["hpy"]},
{'name': 'stream', 'types': [
'movie', 'series'], 'idPrefixes': ['tt', 'hpy']}
]
}
CATALOG = {
'movie': [
{'id': 'tt0032138', 'name': 'The Wizard of Oz', 'genres': [
'Adventure', 'Family', 'Fantasy', 'Musical']},
{'id': 'tt0017136', 'name': 'Metropolis',
'genres': ['Drama', 'Sci-Fi']},
{'id': 'tt0051744', 'name': 'House on Haunted Hill',
'genres': ['Horror', 'Mystery']},
{'id': 'tt1254207', 'name': 'Big Buck Bunny',
'genres': ['Animation', 'Short', 'Comedy'], },
{'id': 'tt0031051', 'name': 'The Arizona Kid',
'genres': ['Music', 'War', 'Western']},
{'id': 'tt0137523', 'name': 'Fight Club', 'genres': ['Drama']}
],
'series': [
{
'id': 'tt1748166',
'name': 'Pioneer One',
'genres': ['Drama'],
'videos': [
{'season': 1, 'episode': 1, 'id': 'tt1748166:1:1',
'title': 'Earthfall', 'released': '2010-06-16'}
]
},
{
'id': 'hpytt0147753',
'name': 'Captain Z-Ro',
'description': 'From his secret laboratory, Captain Z-Ro and his associates use their time machine, the ZX-99, to learn from the past and plan for the future.',
'releaseInfo': '1955-1956',
'logo': 'https://fanart.tv/fanart/tv/70358/hdtvlogo/captain-z-ro-530995d5e979d.png',
'imdbRating': 6.9,
'genres': ['Sci-Fi'],
'videos': [
{'season': 1, 'episode': 1, 'id': 'hpytt0147753:1:1',
'title': 'Christopher Columbus', 'released': '1955-12-18'},
{'season': 1, 'episode': 2, 'id': 'hpytt0147753:1:2',
'title': 'Daniel Boone', 'released': '1955-12-25'}
]
}
]
}
STREAMS = {
'movie': {
'tt0032138': [
{'title': 'Torrent',
'infoHash': '24c8802e2624e17d46cd555f364debd949f2c81e', 'fileIdx': 0}
],
'tt0017136': [
{'title': 'Torrent',
'infoHash': 'dca926c0328bb54d209d82dc8a2f391617b47d7a', 'fileIdx': 1}
],
'tt0051744': [
{'title': 'Torrent', 'infoHash': '9f86563ce2ed86bbfedd5d3e9f4e55aedd660960'}
],
'tt1254207': [
{'title': 'HTTP URL', 'url': 'http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4'}
],
'tt0031051': [
{'title': 'YouTube', 'ytId': 'm3BKVSpP80s'}
],
'tt0137523': [
{'title': 'External URL',
'externalUrl': 'https://www.netflix.com/watch/26004747'}
]
},
'series': {
'tt1748166:1:1': [
{'title': 'Torrent', 'infoHash': '07a9de9750158471c3302e4e95edb1107f980fa6'}
],
'hpytt0147753:1:1': [
{'title': 'YouTube', 'ytId': '5EQw5NYlbyE'}
],
'hpytt0147753:1:2': [
{'title': 'YouTube', 'ytId': 'ZzdBKcVzx9Y'}
]
}
}
# This is template we'll be using to construct URL for the item poster
METAHUB_URL = 'https://images.metahub.space/poster/medium/{}/img'
OPTIONAL_META = ["posterShape", "background", "logo", "videos", "description", "releaseInfo", "imdbRating", "director", "cast",
"dvdRelease", "released", "inTheaters", "certification", "runtime", "language", "country", "awards", "website", "isPeered"]
app = Flask(__name__)
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()