parent
1a221d30b8
commit
c5e419752c
@ -0,0 +1,20 @@
|
||||
"""Downloads management."""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from bebop.fs import get_downloads_path
|
||||
|
||||
|
||||
def get_download_path(url: str, download_dir: Optional[str] =None) -> Path:
|
||||
"""Try to find the best download file path possible from this URL."""
|
||||
download_path = Path(download_dir) if download_dir else get_downloads_path()
|
||||
if not download_path.exists():
|
||||
download_path.mkdir(parents=True)
|
||||
url_parts = url.rsplit("/", maxsplit=1)
|
||||
if url_parts:
|
||||
filename = url_parts[-1]
|
||||
else:
|
||||
filename = url.split("://")[1] if "://" in url else url
|
||||
filename = filename.replace("/", "_")
|
||||
return download_path / filename
|
Loading…
Reference in new issue