(obj)
| 1012 | try: |
| 1013 | extracted_media = [] |
| 1014 | def extract_urls(obj): |
| 1015 | if isinstance(obj, dict): |
| 1016 | if "image_versions2" in obj: |
| 1017 | cands = obj["image_versions2"].get("candidates", []) |
| 1018 | if cands: |
| 1019 | cands_sorted = sorted( |
| 1020 | [c for c in cands if c.get("url")], |
| 1021 | key=lambda x: int(x.get("width") or 0), |
| 1022 | reverse=True |
| 1023 | ) |
| 1024 | extracted_media.append(cands_sorted[0].get("url")) |
| 1025 | if "video_versions" in obj: |
| 1026 | cands = obj["video_versions"] |
| 1027 | if cands: extracted_media.append(cands[0].get("url")) |
| 1028 | if "display_url" in obj: |
| 1029 | extracted_media.append(obj["display_url"]) |
| 1030 | if "video_url" in obj: |
| 1031 | extracted_media.append(obj["video_url"]) |
| 1032 | |
| 1033 | for k, v in obj.items(): extract_urls(v) |
| 1034 | elif isinstance(obj, list): |
| 1035 | for item in obj: extract_urls(item) |
| 1036 | |
| 1037 | extract_urls(api_data) |
| 1038 |
nothing calls this directly
no outgoing calls
no test coverage detected