Update app.py
Browse files
app.py
CHANGED
@@ -40,7 +40,7 @@ class PostRequest(BaseModel):
|
|
40 |
url: str
|
41 |
|
42 |
class DownloadResponse(BaseModel):
|
43 |
-
|
44 |
|
45 |
def extract_shortcode(url: str) -> str:
|
46 |
"""Extract Instagram post shortcode from URL"""
|
@@ -113,19 +113,27 @@ async def download_post(request: PostRequest):
|
|
113 |
logger.error(f"Unexpected error: {e}")
|
114 |
raise HTTPException(status_code=500, detail="Internal server error")
|
115 |
|
116 |
-
|
117 |
-
if post.
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
119 |
else:
|
120 |
-
|
|
|
|
|
|
|
121 |
|
122 |
-
if not
|
123 |
logger.error("No media found in post")
|
124 |
raise HTTPException(status_code=404, detail="No media found in post")
|
125 |
|
126 |
-
return {"
|
127 |
|
128 |
|
129 |
@app.get("/api/health")
|
130 |
async def health_check():
|
131 |
-
return {"status": "healthy"}
|
|
|
40 |
url: str
|
41 |
|
42 |
class DownloadResponse(BaseModel):
|
43 |
+
download_urls: List[str]
|
44 |
|
45 |
def extract_shortcode(url: str) -> str:
|
46 |
"""Extract Instagram post shortcode from URL"""
|
|
|
113 |
logger.error(f"Unexpected error: {e}")
|
114 |
raise HTTPException(status_code=500, detail="Internal server error")
|
115 |
|
116 |
+
download_urls = []
|
117 |
+
if post.typename == 'GraphSidecar':
|
118 |
+
# Handle carousel posts
|
119 |
+
for node in post.get_sidecar_nodes():
|
120 |
+
if node.is_video:
|
121 |
+
download_urls.append(node.video_url)
|
122 |
+
else:
|
123 |
+
download_urls.append(node.display_url)
|
124 |
else:
|
125 |
+
if post.is_video:
|
126 |
+
download_urls.append(post.video_url)
|
127 |
+
else:
|
128 |
+
download_urls.append(post.url)
|
129 |
|
130 |
+
if not download_urls:
|
131 |
logger.error("No media found in post")
|
132 |
raise HTTPException(status_code=404, detail="No media found in post")
|
133 |
|
134 |
+
return {"download_urls": download_urls}
|
135 |
|
136 |
|
137 |
@app.get("/api/health")
|
138 |
async def health_check():
|
139 |
+
return {"status": "healthy"}
|