bestpedro commited on
Commit
1eb5925
·
verified ·
1 Parent(s): 1b3696e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -189,12 +189,13 @@ def get_creative_assets(ad_id):
189
  "fields": "source",
190
  "access_token": ACCESS_TOKEN,
191
  }
192
- video_source = call_graph_api(video_url, video_params)["source"]
193
  ext = video_source.split("?")[0].split(".")[-1]
194
- if len(ext) > 4:
195
- ext = "mp4"
196
- saved = save_image_from_url(video_source, os.path.join("assets", f'{ad_id}.{ext}'))
197
- split_video_in_frames(os.path.join("assets", f'{ad_id}.{ext}'))
 
198
 
199
  elif "image_url" in creative:
200
  image_url = creative["image_url"]
@@ -209,7 +210,7 @@ def get_creative_assets(ad_id):
209
  "fields": "attachments",
210
  "access_token": ACCESS_TOKEN,
211
  }
212
- attachments = call_graph_api(object_story_url, object_story_params)["attachments"]
213
  if "media" in attachments:
214
  media = attachments["media"]
215
  if "source" in media or "video" in media:
 
189
  "fields": "source",
190
  "access_token": ACCESS_TOKEN,
191
  }
192
+ video_source = call_graph_api(video_url, video_params).get("source", "")
193
  ext = video_source.split("?")[0].split(".")[-1]
194
+ if video_source != "":
195
+ if len(ext) > 4:
196
+ ext = "mp4"
197
+ saved = save_image_from_url(video_source, os.path.join("assets", f'{ad_id}.{ext}'))
198
+ split_video_in_frames(os.path.join("assets", f'{ad_id}.{ext}'))
199
 
200
  elif "image_url" in creative:
201
  image_url = creative["image_url"]
 
210
  "fields": "attachments",
211
  "access_token": ACCESS_TOKEN,
212
  }
213
+ attachments = call_graph_api(object_story_url, object_story_params).get("attachments", [])
214
  if "media" in attachments:
215
  media = attachments["media"]
216
  if "source" in media or "video" in media: