Skip to content

Commit

Permalink
Added Support For Image File Types
Browse files Browse the repository at this point in the history
  • Loading branch information
NotCookey committed Aug 1, 2022
1 parent 41c96a8 commit db050a4
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 22 deletions.
2 changes: 1 addition & 1 deletion PyFileDownloader.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: PyFileDownloader
Version: 1.1.0
Version: 1.2.0
Summary: A Python module to download any file-type from the internet.
Home-page: https://github.com/NotCookey/PyFileDownloader
Author: NotCookey
Expand Down
38 changes: 28 additions & 10 deletions PyFileDownloader/PyFileDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,42 @@ def headers(self) -> dict:

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

if filename:
parsed_headers = werkzeug.http.parse_options_header(
re.findall("filename=(.+)", filename)[0]
)
parsed_headers = werkzeug.http.parse_options_header(filename)

for keys in parsed_headers:
if "filename" in keys:
filename = keys["filename"]
return {"filename": filename, "filesize": filesize, "filetype": filetype}
else:
if "image" in filetype:
return {
"filename": "download.jpg",
"filesize": filesize,
"filetype": filetype,
}
if filetype:
if "image" in filetype:
if "jpeg" in filetype:
return {
"filename": "download.jpg",
"filesize": filesize,
"filetype": filetype,
}
if "gif" in filetype:
return {
"filename": "download.gif",
"filesize": filesize,
"filetype": filetype,
}
if "png" in filetype:
return {
"filename": "download.png",
"filesize": filesize,
"filetype": filetype,
}
if "webp" in filetype:
return {
"filename": "download.webp",
"filesize": filesize,
"filetype": filetype,
}
else:
return {
"filename": "download.html",
Expand Down
38 changes: 28 additions & 10 deletions build/lib/PyFileDownloader/PyFileDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,42 @@ def headers(self) -> dict:

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

if filename:
parsed_headers = werkzeug.http.parse_options_header(
re.findall("filename=(.+)", filename)[0]
)
parsed_headers = werkzeug.http.parse_options_header(filename)

for keys in parsed_headers:
if "filename" in keys:
filename = keys["filename"]
return {"filename": filename, "filesize": filesize, "filetype": filetype}
else:
if "image" in filetype:
return {
"filename": "download.jpg",
"filesize": filesize,
"filetype": filetype,
}
if filetype:
if "image" in filetype:
if "jpeg" in filetype:
return {
"filename": "download.jpg",
"filesize": filesize,
"filetype": filetype,
}
if "gif" in filetype:
return {
"filename": "download.gif",
"filesize": filesize,
"filetype": filetype,
}
if "png" in filetype:
return {
"filename": "download.png",
"filesize": filesize,
"filetype": filetype,
}
if "webp" in filetype:
return {
"filename": "download.webp",
"filesize": filesize,
"filetype": filetype,
}
else:
return {
"filename": "download.html",
Expand Down
Binary file removed dist/PyFileDownloader-1.1.0-py3-none-any.whl
Binary file not shown.
Binary file removed dist/PyFileDownloader-1.1.0.tar.gz
Binary file not shown.
Binary file added dist/PyFileDownloader-1.2.0-py3-none-any.whl
Binary file not shown.
Binary file added dist/PyFileDownloader-1.2.0.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
with codecs.open(os.path.join(here, "README.md"), encoding="utf-8") as fh:
long_description = "\n" + fh.read()

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

Expand Down

0 comments on commit db050a4

Please sign in to comment.