async def download_frames(self, infos: List[FrameInfo]) -> List[Image]: # loop infos images = [] for info in infos: # make sure it's the correct FrameInfo if not isinstance(info, PyobsArchiveFrameInfo): log.warning("Incorrect type for frame info.") continue # download url = urllib.parse.urljoin(self._url, info.url) async with aiohttp.ClientSession() as session: async with session.get(url, headers=self._headers, timeout=60) as response: if response.status != 200: log.exception("Error downloading file %s.", info.filename) # create image try: image = Image.from_bytes(await response.read()) images.append(image) except OSError: log.exception("Error downloading file %s.", info.filename) # return all return images
async def read_image(self, filename: str) -> Image: """Convenience function that wraps around open_file() to read an Image. Args: filename: Name of file to download. Returns: An image object """ async with self.open_file(filename, "rb") as f: data = await f.read() return Image.from_bytes(data)