Get the filename from the URL link.
(data_url: str)
| 356 | |
| 357 | |
| 358 | def get_filename_from_url(data_url: str) -> str: |
| 359 | """ |
| 360 | Get the filename from the URL link. |
| 361 | """ |
| 362 | try: |
| 363 | response = requests.head(data_url, allow_redirects=True) |
| 364 | content_disposition = response.headers.get("Content-Disposition") |
| 365 | if content_disposition: |
| 366 | filename = re.findall('filename="?([^";]+)"?', content_disposition) |
| 367 | if filename: |
| 368 | return str(filename[0]) |
| 369 | if "drive.google.com" in data_url: |
| 370 | response = requests.get(data_url) |
| 371 | if "text/html" in response.headers.get("Content-Type", ""): |
| 372 | soup = BeautifulSoup(response.text, "html.parser") |
| 373 | filename_div = soup.find("span", {"class": "uc-name-size"}) |
| 374 | if filename_div: |
| 375 | return str(filename_div.find("a").text) |
| 376 | return _basename(data_url) |
| 377 | except Exception as e: |
| 378 | raise Exception(f"Error processing URL: {e}") from e |
| 379 | |
| 380 | |
| 381 | def download_and_extract( |
no test coverage detected
searching dependent graphs…