Maouu commited on
Commit
2515173
·
verified ·
1 Parent(s): cb50585

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -12
app.py CHANGED
@@ -1,24 +1,26 @@
1
  from pytubefix import YouTube
2
  from pytubefix.cli import on_progress
3
- from flask import Flask
4
- from flask_cors import CORS
5
 
6
- app = Flask(__name__)
7
- CORS(app)
 
 
 
 
 
 
8
 
9
- @app.route('/')
10
  def index():
11
- return "Hello, World!"
12
 
13
-
14
- @app.route('/api/video/<id>')
15
- def video_id(id):
16
  url = f"https://www.youtube.com/watch?v={id}"
17
-
18
  yt = YouTube(url, on_progress_callback=on_progress)
19
-
20
  ys = yt.streams.get_highest_resolution()
21
-
22
  return {
23
  "title": yt.title,
24
  "url": ys.url,
 
1
  from pytubefix import YouTube
2
  from pytubefix.cli import on_progress
3
+ from fastapi import FastAPI
4
+ from fastapi.middleware.cors import CORSMiddleware
5
 
6
+ app = FastAPI()
7
+ app.add_middleware(
8
+ CORSMiddleware,
9
+ allow_origins=["*"], # Adjust as needed
10
+ allow_credentials=True,
11
+ allow_methods=["*"],
12
+ allow_headers=["*"],
13
+ )
14
 
15
+ @app.get("/")
16
  def index():
17
+ return {"message": "Hello, World!"}
18
 
19
+ @app.get("/api/video/{id}")
20
+ def video_id(id: str):
 
21
  url = f"https://www.youtube.com/watch?v={id}"
 
22
  yt = YouTube(url, on_progress_callback=on_progress)
 
23
  ys = yt.streams.get_highest_resolution()
 
24
  return {
25
  "title": yt.title,
26
  "url": ys.url,