anym3u8python / app.py
iptvrd's picture
Create app.py
3af868f verified
raw
history blame contribute delete
997 Bytes
import os
import json
from flask import Flask, request, jsonify, render_template
from extract_m3u8 import extract_m3u8_urls
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/extract', methods=['POST'])
def extract():
data = request.json
url = data.get('url')
wait_time = int(data.get('wait_time', 10))
headers = {}
if data.get('headers'):
for header in data.get('headers').split('\n'):
if ':' in header:
key, value = header.split(':', 1)
headers[key.strip()] = value.strip()
try:
result = extract_m3u8_urls(url, wait_time, headers)
return jsonify({
'success': True,
'urls': result
})
except Exception as e:
return jsonify({
'success': False,
'error': str(e)
}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))