Skip to content

Commit 8e91df4

Browse files
committed
Fix filename inference for some url formats
1 parent 5f215f0 commit 8e91df4

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-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.4`
9+
Current: `1.0.5`
1010

1111
*Do not require authentication.*
1212

onedrivedownloader/main.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ def download(url: str, filename: str, unzip=False, unzip_path: str = None, force
4848

4949
try:
5050
response = requests.get(url, stream=True)
51-
fname = response.url.split("id=")[-1].split("&")[0].split("%2F")[-1]
51+
if 'id=' in response.url and '&' in response.url:
52+
fname = response.url.split("id=")[-1].split("&")[0].split("%2F")[-1]
53+
else:
54+
fname = response.url.split('/')[-1]
5255

5356
if os.path.split(filename)[-1] == '' or '.' not in os.path.split(filename)[-1]:
5457
filename = os.path.join(filename, fname)
@@ -98,6 +101,6 @@ def download(url: str, filename: str, unzip=False, unzip_path: str = None, force
98101

99102

100103
if __name__ == "__main__":
101-
ln = "https://unimore365-my.sharepoint.com/:u:/g/personal/215580_unimore_it/EUmqgpzRz3tPlD2KiVNRqdABBJl7qQYcIeROtMc4g2UeIA?e=zZtkLr"
104+
ln = "https://unimore365-my.sharepoint.com/:u:/g/personal/215580_unimore_it/EQ-DxzGOF7lBt90A601kvVEBR_ca9PtUdN_asesZ-F80bw?download=1"
102105
print('Downloading dataset')
103-
download(ln, filename="files.zip", unzip=True)
106+
download(ln, filename="./tmp/", unzip=True)

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.4',
9+
version='1.0.5',
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.4.zip',
17+
download_url='https://github.com/loribonna/onedrivedownloader/archive/refs/tags/v1.0.5.zip',
1818
keywords=['onedrive', 'downloader', 'download', 'python', 'utility'],
1919
install_requires=["requests","tqdm"],
2020
classifiers=[

0 commit comments

Comments
 (0)