-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47c86b8
commit b873d1e
Showing
7 changed files
with
224 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from pyaiodl import Downloader, errors | ||
import asyncio | ||
url = "https://speed.hetzner.de/100MB.bin" | ||
|
||
|
||
async def main(): | ||
dl = Downloader() | ||
|
||
# or | ||
# dl = Downloader(download_path="/your_dir/", chunk_size=10000) | ||
|
||
uuid = await dl.download(url) | ||
|
||
|
||
try: | ||
while await dl.is_active(uuid): | ||
|
||
r = await dl.status(uuid) | ||
|
||
#cancel | ||
if r['progress'] > 0: | ||
try: | ||
await dl.cancel("your_uuid") | ||
except errors.DownloadNotActive as na: | ||
print(na) | ||
|
||
|
||
print(f""" | ||
Filename: {r['filename']} | ||
Total : {r['total_size_str']} | ||
Downloaded : {r['downloaded_str']} | ||
Download Speed : {r['download_speed']} | ||
progress: {r['progress']} | ||
""") | ||
|
||
# let him breath for a second:P | ||
await asyncio.sleep(1) | ||
|
||
# If You are putting uuid manually Than its better handle This Exception | ||
except errors.InvalidId: | ||
print("not valid uuid") | ||
return | ||
|
||
# when loop Breaks There are 2 Possibility either Its An error Or Download Complete | ||
# Cancelled Is also count as error | ||
if await dl.iserror(uuid): | ||
print(await dl.iserror(uuid)) | ||
|
||
else: | ||
# Final filename / path | ||
print("Download completed : ", r['download_path']) | ||
|
||
|
||
asyncio.get_event_loop().run_until_complete(main()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
__all_ = ['download_not_active'] | ||
__all_ = ['DownloadNotActive', 'InvalidId'] | ||
|
||
|
||
class DownloadNotActive(Exception): | ||
""" Download Not active """ | ||
|
||
|
||
class download_not_active(Exception): | ||
""" Download Not active """ | ||
class InvalidId(Exception): | ||
""" on Invalid uuid """ |
Oops, something went wrong.