-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (41 loc) · 1.48 KB
/
Copy pathmain.py
File metadata and controls
48 lines (41 loc) · 1.48 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
import os
import subprocess
import json
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/api/transcript', methods=['GET'])
def get_transcript():
video_id = request.args.get('videoId')
if not video_id:
return jsonify({"error": "videoId is required"}), 400
try:
# Run the existing script as a subprocess to preserve existing behavior exactly
script_path = os.path.join(os.path.dirname(__file__), "python", "get_transcript.py")
result = subprocess.run(
["python", script_path, video_id],
capture_output=True,
text=True
)
try:
data = json.loads(result.stdout)
if result.returncode != 0:
return jsonify(data), 500
return jsonify(data)
except json.JSONDecodeError:
# Fallback if the script didn't output JSON
if result.returncode != 0:
return jsonify({
"error": "No transcript is available for this video."
}), 500
return jsonify({
"error": "Failed to parse script output",
"stdout": result.stdout
}), 500
except Exception as e:
return jsonify({"error": str(e)}), 500
@app.route('/health', methods=['GET'])
def health():
return jsonify({"status": "healthy"})
if __name__ == '__main__':
port = int(os.environ.get('PORT', 8080))
app.run(host='0.0.0.0', port=port)