Spaces:
Paused
Paused
Update main.py
Browse files
main.py
CHANGED
|
@@ -4,6 +4,7 @@ from fastapi.responses import JSONResponse
|
|
| 4 |
import cloudinary
|
| 5 |
import cloudinary.uploader
|
| 6 |
from cloudinary.utils import cloudinary_url
|
|
|
|
| 7 |
|
| 8 |
app = FastAPI()
|
| 9 |
|
|
@@ -36,10 +37,27 @@ async def compress_image(image_url: str = Query(..., description="URL of the ima
|
|
| 36 |
# Handle any error and return a response
|
| 37 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
# Root endpoint
|
| 40 |
@app.get("/")
|
| 41 |
def root():
|
| 42 |
-
return "Welcome to the Image Compression API"
|
| 43 |
|
| 44 |
if __name__ == "__main__":
|
| 45 |
import uvicorn
|
|
|
|
| 4 |
import cloudinary
|
| 5 |
import cloudinary.uploader
|
| 6 |
from cloudinary.utils import cloudinary_url
|
| 7 |
+
from y2mate_api import Handler # Importing the Y2Mate handler
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
|
|
|
| 37 |
# Handle any error and return a response
|
| 38 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|
| 39 |
|
| 40 |
+
# YouTube video download endpoint
|
| 41 |
+
@app.get("/download_youtube_video")
|
| 42 |
+
async def download_youtube_video(video_url: str = Query(..., description="URL of the YouTube video to download")):
|
| 43 |
+
try:
|
| 44 |
+
# Step 1: Create a handler object for the Y2Mate API
|
| 45 |
+
api = Handler(video_url)
|
| 46 |
+
|
| 47 |
+
# Step 2: Fetch video metadata and download links
|
| 48 |
+
video_metadata = [metadata for metadata in api.run()]
|
| 49 |
+
|
| 50 |
+
# Step 3: Return the metadata or download links
|
| 51 |
+
return JSONResponse(content={"video_metadata": video_metadata})
|
| 52 |
+
|
| 53 |
+
except Exception as e:
|
| 54 |
+
# Handle any error and return a response
|
| 55 |
+
return JSONResponse(content={"error": str(e)}, status_code=500)
|
| 56 |
+
|
| 57 |
# Root endpoint
|
| 58 |
@app.get("/")
|
| 59 |
def root():
|
| 60 |
+
return "Welcome to the Image Compression and YouTube Downloader API"
|
| 61 |
|
| 62 |
if __name__ == "__main__":
|
| 63 |
import uvicorn
|