This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "save password", "speed limit" and "new dir"
add three new feature and fix program crash while downloads same file in the same time
- Loading branch information
Showing
8 changed files
with
257 additions
and
45 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
Binary file not shown.
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,62 @@ | ||
from PyQt5 import QtCore | ||
import os | ||
from time import sleep | ||
|
||
|
||
class DownloadQueue(QtCore.QThread): | ||
def __init__(self, parent, did, session, path, name, | ||
url, force=False, speed=500): | ||
super(DownloadQueue, self).__init__() | ||
self.parent = parent | ||
self.session = session | ||
self.path = path | ||
self.name = name | ||
self.url = url | ||
self.force = force | ||
self.speed = speed | ||
self.did = did | ||
|
||
def run(self): | ||
if not self.force: | ||
self.parent.LogInfo.emit("[MSG]ID:{}\tBegin Download {}\n" | ||
.format(self.did, self.name)) | ||
target = os.path.join(self.path, self.name) | ||
r = self.session.get(self.url, stream=True) | ||
if not self.force: | ||
try: | ||
with open("{}".format(target), 'xb') as f: | ||
for chunk in r.iter_content(chunk_size=1024): | ||
if chunk: | ||
f.write(chunk) | ||
if self.speed != 0: | ||
sleep(1/self.speed) | ||
except FileExistsError: | ||
self.parent.LogInfo.emit("[ERROR]ID:{}\tFile Already Exists!\n" | ||
.format(self.did)) | ||
self.parent.dq.pop(self.did) | ||
self.parent.ExistedFile.emit(self.path, self.name, self.url) | ||
return | ||
else: | ||
self.parent.LogInfo.emit("[MSG]ID:{}\tDownloads Finish\n" | ||
.format(self.did)) | ||
self.parent.dq.pop(self.did) | ||
self.parent.DownloadFinish.emit() | ||
return | ||
else: | ||
self.parent.LogInfo.emit("[MSG]ID:{}\tWaiting to Download {}...\n" | ||
.format(self.did, self.name)) | ||
while(len(self.parent.dq)) > 1: | ||
sleep(1) | ||
self.parent.LogInfo.emit("[MSG]Begin to Downloads {}\n" | ||
.format(self.name)) | ||
with open("{}".format(target), 'wb') as f: | ||
for chunk in r.iter_content(chunk_size=1024): | ||
if chunk: | ||
f.write(chunk) | ||
if self.speed != 0: | ||
sleep(1/self.speed) | ||
self.parent.LogInfo.emit("[MSG]ID:{}\tReplace Finish!\n" | ||
.format(self.did)) | ||
self.parent.dq.pop(self.did) | ||
self.parent.DownloadFinish.emit() | ||
return |
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
Oops, something went wrong.