Skip to content

Commit ae126cc

Browse files
committed
Build wheels
1 parent d06d536 commit ae126cc

File tree

10 files changed

+140
-2
lines changed

10 files changed

+140
-2
lines changed

PyFileDownloader.egg-info/PKG-INFO

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Metadata-Version: 2.1
2+
Name: PyFileDownloader
3+
Version: 1.0
4+
Summary: A Python module to download any file-type from the internet.
5+
Home-page: https://github.com/NotCookey/FileDownloader
6+
Author: NotCookey
7+
Author-email: [email protected]
8+
License: UNKNOWN
9+
Description:
10+
# PyFileDownloader
11+
**A Python module to download any file-type from the internet**
12+
13+
## How To Download
14+
- **Downloading a File**
15+
```py
16+
from FileDownloader import Downloader
17+
18+
download=Downloader(url="DOWNLOAD LINK")
19+
20+
headers=download.headers()
21+
22+
is_downloadable=download.validate_url()
23+
24+
download.save()
25+
```
26+
## Code Breakdown
27+
- **`.headers()` returns you about the file data like filename, filetype, filesize**
28+
- **`.validate_url()` returns True if the provided url is valid**
29+
- **`.save()` downloads the file and saves it with the name provided in the file header**
30+
31+
## Save A File With A Custom Name
32+
- **If you would like to download and save a file with a custom name, you can do so with the `.save()` method. It takes a `filename` parameter that is set to `None` by default.**
33+
```py
34+
from FileDownloader import Downloader
35+
36+
download=Downloader(url="DOWNLOAD LINK")
37+
download.save(filename="custom_name.extension")
38+
```
39+
## Thank you <3
40+
> **Hope you found this useful!**
41+
42+
Keywords: python,file,stream,download,downloader,file downloader,requests,save file,download file
43+
Platform: UNKNOWN
44+
Classifier: Programming Language :: Python :: 3
45+
Classifier: Operating System :: Unix
46+
Classifier: Operating System :: MacOS :: MacOS X
47+
Classifier: Operating System :: Microsoft :: Windows
48+
Description-Content-Type: text/markdown
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
README.md
2+
setup.py
3+
PyFileDownloader/PyFileDownloader.py
4+
PyFileDownloader/__init__.py
5+
PyFileDownloader.egg-info/PKG-INFO
6+
PyFileDownloader.egg-info/SOURCES.txt
7+
PyFileDownloader.egg-info/dependency_links.txt
8+
PyFileDownloader.egg-info/requires.txt
9+
PyFileDownloader.egg-info/top_level.txt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
werkzeug
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PyFileDownloader

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## How To Download
55
- **Downloading a File**
66
```py
7-
from FileDownloader import Downloader
7+
from PyFileDownloader import Downloader
88

99
download=Downloader(url="DOWNLOAD LINK")
1010

@@ -22,7 +22,7 @@ download.save()
2222
## Save A File With A Custom Name
2323
- **If you would like to download and save a file with a custom name, you can do so with the `.save()` method. It takes a `filename` parameter that is set to `None` by default.**
2424
```py
25-
from FileDownloader import Downloader
25+
from PyFileDownloader import Downloader
2626

2727
download=Downloader(url="DOWNLOAD LINK")
2828
download.save(filename="custom_name.extension")
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import re
2+
import sys
3+
import random
4+
import requests
5+
import werkzeug
6+
7+
8+
class Downloader:
9+
def __init__(self, url):
10+
self.url = url
11+
12+
def validate_url(self) -> bool:
13+
response = requests.get(self.url, stream=True)
14+
if response.status_code in range(200, 299):
15+
return True
16+
else:
17+
return False
18+
19+
def headers(self) -> dict:
20+
response = requests.head(self.url)
21+
22+
filename = response.headers.get("Content-Disposition")
23+
filesize = response.headers.get("Content-Length")
24+
filetype = response.headers.get("Content-Type").split(";")[0]
25+
26+
if filename:
27+
parsed_headers = werkzeug.http.parse_options_header(
28+
re.findall("filename=(.+)", filename)[0]
29+
)
30+
31+
for keys in parsed_headers:
32+
if "filename" in keys:
33+
filename = keys["filename"]
34+
return {"filename": filename, "filesize": filesize, "filetype": filetype}
35+
else:
36+
if "image" in filetype:
37+
return {
38+
"filename": "download.jpg",
39+
"filesize": filesize,
40+
"filetype": filetype,
41+
}
42+
else:
43+
return {
44+
"filename": "download.html",
45+
"filesize": filesize,
46+
"filetype": filetype,
47+
}
48+
49+
def get_file_chunks(self, filename: str = None):
50+
file_info = self.headers()
51+
file_name = file_info["filename"]
52+
response = requests.get(self.url, stream=True)
53+
54+
if filename:
55+
file_name = filename
56+
57+
with open(file_name, "wb") as file:
58+
if file_info["filesize"]:
59+
size = int(file_info["filesize"])
60+
current = 0
61+
for chunk in response.iter_content(chunk_size=4096):
62+
current += len(chunk)
63+
downloaded = current / size * 100
64+
file.write(chunk)
65+
else:
66+
file.write(requests.get(self.url, stream=True).content)
67+
68+
return file_name
69+
70+
def save(self, filename: str = None):
71+
if filename:
72+
self.get_file_chunks(filename)
73+
return True
74+
else:
75+
self.get_file_chunks()
76+
return True
77+
return False
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from PyFileDownloader.PFileDownloader import Downloader
3.51 KB
Binary file not shown.

dist/PyFileDownloader-1.0.tar.gz

2.34 KB
Binary file not shown.

0 commit comments

Comments
 (0)