Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
from flask import Flask, request, jsonify, render_template
|
4 |
+
from extract_m3u8 import extract_m3u8_urls
|
5 |
+
|
6 |
+
app = Flask(__name__)
|
7 |
+
|
8 |
+
@app.route('/')
|
9 |
+
def index():
|
10 |
+
return render_template('index.html')
|
11 |
+
|
12 |
+
@app.route('/extract', methods=['POST'])
|
13 |
+
def extract():
|
14 |
+
data = request.json
|
15 |
+
url = data.get('url')
|
16 |
+
wait_time = int(data.get('wait_time', 10))
|
17 |
+
|
18 |
+
headers = {}
|
19 |
+
if data.get('headers'):
|
20 |
+
for header in data.get('headers').split('\n'):
|
21 |
+
if ':' in header:
|
22 |
+
key, value = header.split(':', 1)
|
23 |
+
headers[key.strip()] = value.strip()
|
24 |
+
|
25 |
+
try:
|
26 |
+
result = extract_m3u8_urls(url, wait_time, headers)
|
27 |
+
return jsonify({
|
28 |
+
'success': True,
|
29 |
+
'urls': result
|
30 |
+
})
|
31 |
+
except Exception as e:
|
32 |
+
return jsonify({
|
33 |
+
'success': False,
|
34 |
+
'error': str(e)
|
35 |
+
}), 500
|
36 |
+
|
37 |
+
if __name__ == '__main__':
|
38 |
+
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|