Chrunos commited on
Commit
9f55880
·
verified ·
1 Parent(s): 5750b74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -40,7 +40,7 @@ class PostRequest(BaseModel):
40
  url: str
41
 
42
  class DownloadResponse(BaseModel):
43
- download_url: str
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
- # Get download URL based on media type
117
- if post.is_video:
118
- download_url = post.video_url
 
 
 
 
 
119
  else:
120
- download_url = post.url
 
 
 
121
 
122
- if not download_url:
123
  logger.error("No media found in post")
124
  raise HTTPException(status_code=404, detail="No media found in post")
125
 
126
- return {"download_url": download_url}
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"}