Skip to content

Commit

Permalink
更新下载模块
Browse files Browse the repository at this point in the history
  • Loading branch information
ZSAIm committed May 13, 2019
1 parent dff3fb0 commit 787d2e3
Show file tree
Hide file tree
Showing 14 changed files with 668 additions and 680 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@


## 程序更新
* **2019/05/13**
* 更新下载器。

* **2019/05/12**
* 更新优化下载器。
Expand Down
10 changes: 4 additions & 6 deletions flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ def _process(event):
dlm = dlg.dlm
runs = dlm.getRunQueue()
if runs:
dl = dlm.getHandler(id=runs[0])
dl = dlm.get(id=runs[0])
dlg.update(dl.getIncByte(), dl.getFileSize())
if dlm.isEnd():
dones = dlm.getDoneQueue()
if dones:
dl = dlm.getHandler(id=dones[0])
dl = dlm.get(id=dones[0])
dlg.update(dl.getFileSize(), dl.getFileSize())
event.Timer.Stop()
dlg.EndModal(wx.ID_OK)
Expand Down Expand Up @@ -274,10 +274,6 @@ class FrameParser:
@staticmethod
def handle():
gui.frame_parse.Show()
# if gui.frame_parse.ShowModal() == cv.ID_PARSER_GODOWNLOAD:
# FrameDownload.handle()
# else:
# ShutDown.handle()



Expand Down Expand Up @@ -538,6 +534,8 @@ def handle():

if FrameParser.MenuGoDownload.handler_audio(sel_res):
threading.Thread(target=FrameParser.MenuGoDownload._download, args=(sel_res,)).start()
else:
gui.frame_parse.listctrl_parse.menu.godownload.Enable(True)

@staticmethod
def handler_audio(sel_res):
Expand Down
18 changes: 9 additions & 9 deletions handler/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@ def is_all_files_done(self):
return False

def insert_new_item(self, run_queue):
new = list(filter(lambda x: self.dlm.getNameFromId(x) not in gui.frame_downloader.getItemsDict(),
new = list(filter(lambda x: self.dlm.getNameById(x) not in gui.frame_downloader.getItemsDict(),
run_queue))

for i in new:
dl = self.dlm.getHandler(id=i)
dl = self.dlm.get(id=i)
size = dl.getFileSize()
cur_name = self.dlm.getNameFromId(i)
cur_name = self.dlm.getNameById(i)
gui.frame_downloader.insertItem(cur_name, size)
gui.frame_downloader.updateBlock(cur_name, gui.COLOR_RUN)

Expand All @@ -274,11 +274,11 @@ def insert_new_item(self, run_queue):
# gui.frame_main.sizer_items.Layout()

def delete_end_item(self, done_queue):
end = list(filter(lambda x: self.dlm.getIdFromName(x) in done_queue,
end = list(filter(lambda x: self.dlm.getIdByName(x) in done_queue,
gui.frame_downloader.getItemsDict()))

for i in end:
dl = self.dlm.getHandler(name=i)
dl = self.dlm.get(name=i)
size = dl.getFileSize()
item = gui.frame_downloader.getItem(i)
item.update(size, dl.getInsSpeed(), size)
Expand All @@ -291,20 +291,20 @@ def delete_end_item(self, done_queue):

def update_item(self, run_queue):
for i in run_queue:
dl = self.dlm.getHandler(id=i)
dl = self.dlm.get(id=i)
inc_byte = dl.getIncByte()
size = dl.getFileSize()
item = gui.frame_downloader.getItem(self.dlm.getNameFromId(i))
item = gui.frame_downloader.getItem(self.dlm.getNameById(i))
if item:
item.update(inc_byte, dl.getInsSpeed(), size)

def update_total(self, run_queue, done_queue):
cur_inc = 0
for i in done_queue:
dl = self.dlm.getHandler(id=i)
dl = self.dlm.get(id=i)
cur_inc += dl.getFileSize()
for i in run_queue:
dl = self.dlm.getHandler(id=i)
dl = self.dlm.get(id=i)
cur_inc += dl.getIncByte()

gui.frame_downloader.updateTotal(cur_inc + self._inc_progress, self.dlm.getInsSpeed(), self.dlm.getTotalSize() + self._inc_progress)
Expand Down
10 changes: 5 additions & 5 deletions nbdler/DLAllotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def __init__(self, Handler, GlobalProgress):
self.globalprog = GlobalProgress
self.handler = Handler

self.__allotter_lock__ = threading.Lock()
# self.__allotter_lock__ = threading.Lock()

def makeBaseConn(self):
ranges = self.blockToRange(self.makeEvenBlock(len(self.handler.url.getAllUrl())))
Expand Down Expand Up @@ -71,7 +71,7 @@ def makeEvenBlock(self, block_num):


def getUrlsThread(self):
url_thread_table = [[] for i in range(len(self.handler.url.id_map))]
url_thread_table = [[] for i in range(len(self.handler.url.getAllId()))]

for i in self.globalprog.progresses.values():
if not i.isGoEnd():
Expand Down Expand Up @@ -104,8 +104,8 @@ def assignUrlid(self):
break
put_urlid = url_health_table.pop(-1)[0]

if self.handler.url.dict[put_urlid].max_thread == -1 or \
len(url_thread_table[put_urlid]) < self.handler.url.dict[put_urlid].max_thread:
if self.handler.url.getAllUrl()[put_urlid].max_thread == -1 or \
len(url_thread_table[put_urlid]) < self.handler.url.getAllUrl()[put_urlid].max_thread:
break

else:
Expand Down Expand Up @@ -137,7 +137,7 @@ def getUrlsHealth(self):

for i in self.globalprog.progresses.values():
if not i.isEnd():
urlspeed[i.urlid] = (urlspeed.get(i.urlid, (0, 0))[0]+1,
urlspeed[i.urlid] = (urlspeed.get(i.urlid, (0, 0))[0] + 1,
urlspeed.get(i.urlid, (0, 0))[1] + i.getAvgSpeed())

for i, j in urlspeed.items():
Expand Down
13 changes: 13 additions & 0 deletions nbdler/DLCommon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@



# thread name

ADDNODE = 'Nb-AddNode'
LAUNCHER = 'Nb-Launcher'
MANAGER = 'Nb-Manager'
PROCESSOR = 'Nb-Processor'
RELEASE_BUFF = 'Nb-ReleaseBuff'
INSPECTOR = 'Nb-Inspector'
ALLOTTER = 'Nb-Allotter'
THREADPOOL = 'Nb-ThreadPool'
18 changes: 11 additions & 7 deletions nbdler/DLError.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,38 @@


class DLUrlError(Exception):
def __init__(self, thread, progress, res):
self.thread = thread
self.progress = progress
def __init__(self, handler, res):
# self.thread = thread
self.handler = handler
self.respond = res

def __repr__(self):
return '<%s> - %s' % (self.handler.file.name, self.respond.__repr__())


class HTTPErrorCounter:
ERR_4XX_THRESHOLD = 3
ERR_4XX_THRESHOLD = 4
ERR_TIMEOUT_THRESHOLD = 100
ERR_UNKNOWN_THRESHOLD = 20

def __init__(self):
self._counter = {}

def http_timeout(self, handler, res):

self._counter['timeout'] = self._counter.get('timeout', 0) + 1
if self._counter['timeout'] % HTTPErrorCounter.ERR_TIMEOUT_THRESHOLD == 0:
raise DLUrlError(threading.current_thread(), handler, res)
raise DLUrlError(handler, res)

def http_4xx(self, handler, res):
self._counter[res.status] = self._counter.get(res.status, 0) + 1
if self._counter[res.status] % HTTPErrorCounter.ERR_4XX_THRESHOLD == 0:
raise DLUrlError(threading.current_thread(), handler, res)
raise DLUrlError(handler, res)

def http_unknown(self, handler, res):
self._counter['unknown'] = self._counter.get('unknown', 0) + 1
if self._counter['unkown'] % HTTPErrorCounter.ERR_UNKNOWN_THRESHOLD == 0:
raise DLUrlError(threading.current_thread(), handler, res)
raise DLUrlError(handler, res)

def getCounter(self, status):
return self._counter[status]
Expand Down
Loading

0 comments on commit 787d2e3

Please sign in to comment.