File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 22
33import logging
44import os
5+ from pathlib import PurePosixPath
56import shutil
67from tempfile import NamedTemporaryFile
78from typing import TYPE_CHECKING
9+ from urllib .parse import urlparse
810
911from more_itertools import chunked
1012from requests .exceptions import ChunkedEncodingError , ConnectionError
@@ -126,7 +128,14 @@ def get_license(session: IsicCliSession, license_type: str) -> str:
126128 before_sleep = before_sleep_log (logger , logging .DEBUG ),
127129)
128130def download_image (image : dict , to : Path , progress , task ) -> None :
129- dest_path = to / f'{ image ["isic_id" ]} .jpg'
131+ url = image ["files" ]["full" ]["url" ]
132+ parsed_url = urlparse (url )
133+ path = parsed_url .path
134+ # defaulting to jpg is simply a convenience for development where the images
135+ # are extension-less since they come from a synthetic image generator.
136+ extension = PurePosixPath (path ).suffix .lstrip ("." ) or "jpg"
137+
138+ dest_path = to / f'{ image ["isic_id" ]} .{ extension } '
130139
131140 # Avoid re downloading the image if one of the same name/size exists. This is a decent
132141 # enough proxy for detecting file differences without going through a hashing mechanism.
You can’t perform that action at this time.
0 commit comments