@@ -327,17 +327,18 @@ def download_and_extract(
327327 be False.
328328 progress: whether to display progress bar.
329329 """
330- urlFilenameExtension = '' .join (Path ("." , _basename (url )).resolve ().suffixes )
331- if filepath :
332- FilepathExtenstion = '' .join (Path ("." , _basename (filepath )).resolve ().suffixes )
333- if urlFilenameExtension != FilepathExtenstion :
334- raise NotImplementedError (
335- f'The file types do not match: url={ urlFilenameExtension } , but filepath={ FilepathExtenstion } '
330+ url_filename_ext = "" .join (Path ("." , _basename (url )).resolve ().suffixes )
331+ filepath_ext = "" .join (Path ("." , _basename (filepath )).resolve ().suffixes )
332+ if filepath not in ["" , "." ]:
333+ if filepath_ext == "" :
334+ new_filepath = filepath + url_filename_ext
335+ logger .warning (
336+ f"filepath={ filepath } , which missing file extension. Auto-appending extension to: { new_filepath } "
336337 )
338+ filepath = new_filepath
339+ if filepath_ext and filepath_ext != url_filename_ext :
340+ logger .warning (f"Expected extension { url_filename_ext } , but get { filepath_ext } , may cause unexpected errors!" )
337341 with tempfile .TemporaryDirectory () as tmp_dir :
338- if filepath :
339- filename = filepath
340- else :
341- filename = Path (tmp_dir , _basename (url )).resolve ()
342+ filename = filepath or Path (tmp_dir , _basename (url )).resolve ()
342343 download_url (url = url , filepath = filename , hash_val = hash_val , hash_type = hash_type , progress = progress )
343344 extractall (filepath = filename , output_dir = output_dir , file_type = file_type , has_base = has_base )
0 commit comments