-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsearch.py
67 lines (56 loc) · 1.84 KB
/
search.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
import sys
from distutils.util import split_quoted
from flask import Flask, request, Response
from acestream_search.acestream_search import main as engine, get_options, __version__
app = Flask(__name__)
if sys.version_info[0] > 2:
def u_code(string):
return string
else:
def u_code(string):
return string.encode("utf8")
def get_args():
opts = {'prog': request.base_url}
for item in request.args:
opts[item] = u_code(request.args[item])
if 'name' in opts:
opts['name'] = split_quoted(opts['name'])
if 'query' not in opts:
opts['query'] = ''
args = get_options(opts)
return args
# Use two routing rules of Your choice where playlist extension does matter.
@app.route('/search.m3u')
@app.route('/search.m3u8')
def main():
args = get_args()
# return str(args)
if args.xml_epg:
content_type = 'text/xml'
elif args.json:
content_type = 'application/json'
else:
content_type = 'application/x-mpegURL'
def generate():
for page in engine(args):
yield page + '\n'
if 'version' in args:
return Response(__version__ + '\n', content_type='text/plain')
if 'help' in args:
return Response(args.help, content_type='text/plain')
if 'usage' in args:
return Response(args.usage, content_type='text/plain')
if args.url:
redirect_url = next(x for x in generate()).strip('\n')
response = Response('', content_type='')
response.headers['Location'] = redirect_url
response.headers['Content-Type'] = ''
response.status_code = 302
return response
return Response(generate(), content_type=content_type)
if __name__ == '__main__':
if len(sys.argv) > 1:
port = sys.argv[1]
else:
port = 8088
app.run(debug=True, host='0.0.0.0', port=port)