Skip to content

Commit db050a4

Browse files
committed
Added Support For Image File Types
1 parent 41c96a8 commit db050a4

File tree

8 files changed

+58
-22
lines changed

8 files changed

+58
-22
lines changed

PyFileDownloader.egg-info/PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: PyFileDownloader
3-
Version: 1.1.0
3+
Version: 1.2.0
44
Summary: A Python module to download any file-type from the internet.
55
Home-page: https://github.com/NotCookey/PyFileDownloader
66
Author: NotCookey

PyFileDownloader/PyFileDownloader.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,42 @@ def headers(self) -> dict:
2121

2222
filename = response.headers.get("Content-Disposition")
2323
filesize = response.headers.get("Content-Length")
24-
filetype = response.headers.get("Content-Type").split(";")[0]
24+
filetype = response.headers.get("Content-Type")
2525

2626
if filename:
27-
parsed_headers = werkzeug.http.parse_options_header(
28-
re.findall("filename=(.+)", filename)[0]
29-
)
27+
parsed_headers = werkzeug.http.parse_options_header(filename)
3028

3129
for keys in parsed_headers:
3230
if "filename" in keys:
3331
filename = keys["filename"]
3432
return {"filename": filename, "filesize": filesize, "filetype": filetype}
3533
else:
36-
if "image" in filetype:
37-
return {
38-
"filename": "download.jpg",
39-
"filesize": filesize,
40-
"filetype": filetype,
41-
}
34+
if filetype:
35+
if "image" in filetype:
36+
if "jpeg" in filetype:
37+
return {
38+
"filename": "download.jpg",
39+
"filesize": filesize,
40+
"filetype": filetype,
41+
}
42+
if "gif" in filetype:
43+
return {
44+
"filename": "download.gif",
45+
"filesize": filesize,
46+
"filetype": filetype,
47+
}
48+
if "png" in filetype:
49+
return {
50+
"filename": "download.png",
51+
"filesize": filesize,
52+
"filetype": filetype,
53+
}
54+
if "webp" in filetype:
55+
return {
56+
"filename": "download.webp",
57+
"filesize": filesize,
58+
"filetype": filetype,
59+
}
4260
else:
4361
return {
4462
"filename": "download.html",

build/lib/PyFileDownloader/PyFileDownloader.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,42 @@ def headers(self) -> dict:
2121

2222
filename = response.headers.get("Content-Disposition")
2323
filesize = response.headers.get("Content-Length")
24-
filetype = response.headers.get("Content-Type").split(";")[0]
24+
filetype = response.headers.get("Content-Type")
2525

2626
if filename:
27-
parsed_headers = werkzeug.http.parse_options_header(
28-
re.findall("filename=(.+)", filename)[0]
29-
)
27+
parsed_headers = werkzeug.http.parse_options_header(filename)
3028

3129
for keys in parsed_headers:
3230
if "filename" in keys:
3331
filename = keys["filename"]
3432
return {"filename": filename, "filesize": filesize, "filetype": filetype}
3533
else:
36-
if "image" in filetype:
37-
return {
38-
"filename": "download.jpg",
39-
"filesize": filesize,
40-
"filetype": filetype,
41-
}
34+
if filetype:
35+
if "image" in filetype:
36+
if "jpeg" in filetype:
37+
return {
38+
"filename": "download.jpg",
39+
"filesize": filesize,
40+
"filetype": filetype,
41+
}
42+
if "gif" in filetype:
43+
return {
44+
"filename": "download.gif",
45+
"filesize": filesize,
46+
"filetype": filetype,
47+
}
48+
if "png" in filetype:
49+
return {
50+
"filename": "download.png",
51+
"filesize": filesize,
52+
"filetype": filetype,
53+
}
54+
if "webp" in filetype:
55+
return {
56+
"filename": "download.webp",
57+
"filesize": filesize,
58+
"filetype": filetype,
59+
}
4260
else:
4361
return {
4462
"filename": "download.html",
-3.53 KB
Binary file not shown.

dist/PyFileDownloader-1.1.0.tar.gz

-2.35 KB
Binary file not shown.
3.55 KB
Binary file not shown.

dist/PyFileDownloader-1.2.0.tar.gz

2.37 KB
Binary file not shown.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
with codecs.open(os.path.join(here, "README.md"), encoding="utf-8") as fh:
88
long_description = "\n" + fh.read()
99

10-
VERSION = '1.1.0'
10+
VERSION = '1.2.0'
1111
DESCRIPTION = 'A Python module to download any file-type from the internet.'
1212
LONG_DESCRIPTION = 'A Python module to download any file-type from the internet.'
1313

0 commit comments

Comments
 (0)