dragxd commited on
Commit
1d00ee2
·
verified ·
1 Parent(s): 3641be3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -0
app.py CHANGED
@@ -2,6 +2,7 @@ from fastapi import FastAPI, HTTPException
2
  from pydantic import BaseModel, Field
3
  import yt_dlp
4
  import base64
 
5
 
6
  app = FastAPI(
7
  title="YouTube Download API",
@@ -25,6 +26,8 @@ class VideoResponse(BaseModel):
25
  status: str = Field(..., example="success")
26
  video_url: str = Field(..., description="Base64 encoded direct video URL")
27
 
 
 
28
  @app.post("/audio/", response_model=AudioResponse, summary="Get YouTube Audio URL")
29
  def get_audio_link(req: VideoRequest):
30
  """
@@ -37,6 +40,7 @@ def get_audio_link(req: VideoRequest):
37
  'format': 'bestaudio/best',
38
  'skip_download': True,
39
  'forceurl': True,
 
40
  }
41
  try:
42
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
@@ -62,6 +66,7 @@ def get_video_link(req: VideoRequest):
62
  'format': 'best[height<=720][width<=1280]',
63
  'skip_download': True,
64
  'forceurl': True,
 
65
  }
66
  try:
67
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
 
2
  from pydantic import BaseModel, Field
3
  import yt_dlp
4
  import base64
5
+ import os
6
 
7
  app = FastAPI(
8
  title="YouTube Download API",
 
26
  status: str = Field(..., example="success")
27
  video_url: str = Field(..., description="Base64 encoded direct video URL")
28
 
29
+ COOKIES_PATH = "cookies.txt"
30
+
31
  @app.post("/audio/", response_model=AudioResponse, summary="Get YouTube Audio URL")
32
  def get_audio_link(req: VideoRequest):
33
  """
 
40
  'format': 'bestaudio/best',
41
  'skip_download': True,
42
  'forceurl': True,
43
+ 'cookies': COOKIES_PATH if os.path.isfile(COOKIES_PATH) else None
44
  }
45
  try:
46
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
 
66
  'format': 'best[height<=720][width<=1280]',
67
  'skip_download': True,
68
  'forceurl': True,
69
+ 'cookies': COOKIES_PATH if os.path.isfile(COOKIES_PATH) else None
70
  }
71
  try:
72
  with yt_dlp.YoutubeDL(ydl_opts) as ydl: