Return the contents of the asset file, as bytes
(self)
| 20 | |
| 21 | @property |
| 22 | def data(self) -> bytes: |
| 23 | """ |
| 24 | Return the contents of the asset file, as bytes |
| 25 | """ |
| 26 | if self._data is None: |
| 27 | # Download and cache |
| 28 | rq = requests.get(f"https://assets.scratch.mit.edu/internalapi/asset/{self.filename}/get/") |
| 29 | # print(f"Downloaded {url}") |
| 30 | if rq.status_code != 200: |
| 31 | raise ValueError(f"Can't download asset {self.filename}\nIs not uploaded to scratch! Response: {rq.text}") |
| 32 | |
| 33 | self._data = rq.content |
| 34 | |
| 35 | return self._data |
| 36 | |
| 37 | @data.setter |
| 38 | def data(self, data: bytes): |