Skip to content

Commit 42a019d

Browse files
committed
Add return download path
1 parent 8e91df4 commit 42a019d

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
First stable release: `1.0.0`
88

9-
Current: `1.0.5`
9+
Current: `1.0.6`
1010

1111
*Do not require authentication.*
1212

onedrivedownloader/main.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def _create_if_not_exists(path: str, remove=True) -> None:
2626

2727
os.makedirs(path, exist_ok=True)
2828

29-
def download(url: str, filename: str, unzip=False, unzip_path: str = None, force_download=False, force_unzip=False, clean=False) -> None:
29+
def download(url: str, filename: str, unzip=False, unzip_path: str = None, force_download=False, force_unzip=False, clean=False) -> str:
3030
"""
3131
Download a file from a OneDrive url.
3232
@@ -38,10 +38,14 @@ def download(url: str, filename: str, unzip=False, unzip_path: str = None, force
3838
:param force_download: Whether to force download the file even if it already exists.
3939
:param force_unzip: Whether to force unzip and overwrite the file even if it already exists.
4040
:param clean: Whether to clean the unzipped files after unzipping.
41+
42+
:returns: Path of the downloaded (and extracted if 'unzip') file.
4143
"""
4244
assert url is not None, "URL cannot be None!"
4345
assert filename is not None, "Parameter filename cannot be None!"
4446

47+
ret_path = None
48+
4549
if not url.endswith("?download=1"):
4650
# replace everithing after the last ? with ?download=1
4751
url = url.split("?")[0] + "?download=1"
@@ -60,6 +64,8 @@ def download(url: str, filename: str, unzip=False, unzip_path: str = None, force
6064
progress_bar = tqdm(total=total_size_in_bytes, unit='iB', unit_scale=True) if total_size_in_bytes > 1024 else None
6165
block_size = 1024
6266

67+
ret_path = filename
68+
6369
if not os.path.exists(filename) or force_download:
6470
_create_if_not_exists(filename)
6571

@@ -81,7 +87,8 @@ def download(url: str, filename: str, unzip=False, unzip_path: str = None, force
8187
if filename.endswith(".zip"):
8288
unzip_path = unzip_path if unzip_path is not None else os.path.split(filename)[0]
8389
clean_unzip_path = force_unzip and os.path.realpath(unzip_path) not in os.path.realpath(filename)
84-
90+
ret_path = unzip_path
91+
8592
_create_if_not_exists(unzip_path, remove=clean_unzip_path)
8693

8794
if force_unzip:
@@ -95,6 +102,7 @@ def download(url: str, filename: str, unzip=False, unzip_path: str = None, force
95102
if clean:
96103
os.remove(filename)
97104

105+
return ret_path
98106
except Exception as e:
99107
print(e)
100108
raise Exception("ERROR, something went wrong, see error above!")
@@ -103,4 +111,5 @@ def download(url: str, filename: str, unzip=False, unzip_path: str = None, force
103111
if __name__ == "__main__":
104112
ln = "https://unimore365-my.sharepoint.com/:u:/g/personal/215580_unimore_it/EQ-DxzGOF7lBt90A601kvVEBR_ca9PtUdN_asesZ-F80bw?download=1"
105113
print('Downloading dataset')
106-
download(ln, filename="./tmp/", unzip=True)
114+
ret = download(ln, filename="./tmp/", unzip=True)
115+
print(ret)

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
setup(
77
name='onedrivedownloader',
88
packages=find_packages(),
9-
version='1.0.5',
9+
version='1.0.6',
1010
license='MIT',
1111
description='Python utility to download files through OneDrive',
1212
long_description=long_description,
1313
long_description_content_type="text/markdown",
1414
author='Lorenzo Bonicelli',
1515
author_email='[email protected]',
1616
url='https://github.com/loribonna/onedrivedownloader',
17-
download_url='https://github.com/loribonna/onedrivedownloader/archive/refs/tags/v1.0.5.zip',
17+
download_url='https://github.com/loribonna/onedrivedownloader/archive/refs/tags/v1.0.6.zip',
1818
keywords=['onedrive', 'downloader', 'download', 'python', 'utility'],
1919
install_requires=["requests","tqdm"],
2020
classifiers=[

0 commit comments

Comments
 (0)