-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
92 lines (74 loc) · 2.33 KB
/
main.py
File metadata and controls
92 lines (74 loc) · 2.33 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
from pathlib import Path
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.openapi.docs import get_swagger_ui_html
from fastapi.responses import HTMLResponse
from fastapi.middleware.cors import CORSMiddleware
from app.api.video_api import router as video_router
# ===============================
# Paths & Templates
# ===============================
BASE_DIR = Path(__file__).resolve().parent
TEMPLATES_DIR = BASE_DIR / "templates"
INDEX_FILE = TEMPLATES_DIR / "index.html"
# ===============================
# FastAPI App
# ===============================
app = FastAPI(
title="Python Video Server",
version="1.0.0",
description="Video Processing API (FFmpeg/HLS)",
docs_url=None, # Deshabilitamos docs default
redoc_url=None,
openapi_url="/openapi.json",
)
# ===============================
# UI Home (HLS Converter)
# ===============================
@app.get("/", include_in_schema=False)
def home():
"""
Página principal con UI del conversor HLS.
"""
if not INDEX_FILE.exists():
return HTMLResponse(
"<h1>Templates not found</h1><p>Missing templates/index.html</p>",
status_code=500,
)
html = INDEX_FILE.read_text(encoding="utf-8")
return HTMLResponse(content=html, media_type="text/html")
# ===============================
# Swagger Custom
# ===============================
@app.get("/swagger", include_in_schema=False)
def swagger_ui():
return get_swagger_ui_html(
openapi_url="/openapi.json",
title="Video Server Swagger",
)
# ===============================
# API Routes
# ===============================
app.include_router(video_router, prefix="/videos")
# ===============================
# Static HLS Streaming
# ===============================
# Sirve:
# /streams/<videoId>/index.m3u8
# /streams/<videoId>/index.ts
# etc.
app.mount(
"/streams",
StaticFiles(directory="upload/videos"),
name="streams",
)
# ===============================
# (Opcional) CORS for frontend
# ===============================
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # puedes restringir si lo usas en prod
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)