MCPcopy
hub / github.com/ahujasid/blender-mcp / get_sketchfab_model_preview

Method get_sketchfab_model_preview

addon.py:1692–1776  ·  view source on GitHub ↗

Get thumbnail preview image of a Sketchfab model by its UID

(self, uid)

Source from the content-addressed store, hash-verified

1690 return {"error": str(e)}
1691
1692 def get_sketchfab_model_preview(self, uid):
1693 """Get thumbnail preview image of a Sketchfab model by its UID"""
1694 try:
1695 import base64
1696
1697 api_key = self._get_sketchfab_api_key()
1698 if not api_key:
1699 return {"error": "Sketchfab API key is not configured"}
1700
1701 headers = {"Authorization": f"Token {api_key}"}
1702
1703 # Get model info which includes thumbnails
1704 response = requests.get(
1705 f"https://api.sketchfab.com/v3/models/{uid}",
1706 headers=headers,
1707 timeout=30
1708 )
1709
1710 if response.status_code == 401:
1711 return {"error": "Authentication failed (401). Check your API key."}
1712
1713 if response.status_code == 404:
1714 return {"error": f"Model not found: {uid}"}
1715
1716 if response.status_code != 200:
1717 return {"error": f"Failed to get model info: {response.status_code}"}
1718
1719 data = response.json()
1720 thumbnails = data.get("thumbnails", {}).get("images", [])
1721
1722 if not thumbnails:
1723 return {"error": "No thumbnail available for this model"}
1724
1725 # Find a suitable thumbnail (prefer medium size ~640px)
1726 selected_thumbnail = None
1727 for thumb in thumbnails:
1728 width = thumb.get("width", 0)
1729 if 400 <= width <= 800:
1730 selected_thumbnail = thumb
1731 break
1732
1733 # Fallback to the first available thumbnail
1734 if not selected_thumbnail:
1735 selected_thumbnail = thumbnails[0]
1736
1737 thumbnail_url = selected_thumbnail.get("url")
1738 if not thumbnail_url:
1739 return {"error": "Thumbnail URL not found"}
1740
1741 # Download the thumbnail image
1742 img_response = requests.get(thumbnail_url, timeout=30)
1743 if img_response.status_code != 200:
1744 return {"error": f"Failed to download thumbnail: {img_response.status_code}"}
1745
1746 # Encode image as base64
1747 image_data = base64.b64encode(img_response.content).decode('ascii')
1748
1749 # Determine format from content type or URL

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected