Skip to content

Commit

Permalink
更新下载选择功能与交互视频全选/全不选
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLiang-lzm committed Jun 5, 2022
1 parent c77380e commit ca822a6
Show file tree
Hide file tree
Showing 10 changed files with 408 additions and 52 deletions.
2 changes: 1 addition & 1 deletion BiliModule/About.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def accessWeb(self):

# 检查版本更新函数
def checkLatest(self):
self.cl = checkLatest(self.lab_version.text())
self.cl = checkLatest(Release_INFO[0])
self.btn_latest.setEnabled(False)
self.cl._feedback.connect(self.verShow)
self.cl.start()
Expand Down
22 changes: 22 additions & 0 deletions BiliModule/Interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def __init__(self, args, parent=None):
self.btn_downCurChoose.clicked.connect(self.dl_current_node)
self.btn_downALLChoose.clicked.connect(self.dl_all_chooses)
self.btn_stRecu.clicked.connect(self.st_recursion)
self.btn_select_All.clicked.connect(self.select_All)
self.btn_select_None.clicked.connect(self.select_None)
# 初始化变量
CurrentConfig.ONLINE_HOST = Echart_CDN
self.init_args = args
Expand Down Expand Up @@ -394,6 +396,26 @@ def st_recursion(self):
self.RTWindow.show()
return 0

# 全选节点
def select_All(self):
# print(self.treenode_select(self.treelist_dict, True))
self.treelist_dict = self.treenode_select(self.treelist_dict, True)
self.renew_show()

# 全不选节点
def select_None(self):
# print(self.treenode_select(self.treelist_dict, False))
self.treelist_dict = self.treenode_select(self.treelist_dict, False)
self.renew_show()

# 节点全部选中或不选中
def treenode_select(self, indic, choose: bool):
for ch in indic:
indic[ch]['isChoose'] = choose
if indic[ch].get('choices'):
indic[ch]['choices'] = self.treenode_select(indic[ch]['choices'], choose)
return indic


####################### RW Part #######################
# 鼠标点击事件产生
Expand Down
12 changes: 9 additions & 3 deletions BiliModule/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def __init__(self, parent=None):
else:
self.checkBox_sym.setChecked(False)
indict["sym"] = False
if tempr.get('dl_err'):
indict['dl_err'] = tempr.get('dl_err')
if tempr.get('chunk_size'):
indict['chunk_size'] = tempr.get('chunk_size')
except:
indict["Output"] = DF_Path
indict["sys"] = sys.platform
Expand Down Expand Up @@ -114,7 +118,9 @@ def closeEvent(self,QCloseEvent):
"sys":indict["sys"],
"output":indict["Output"],
"useProxy":indict["useProxy"],
"Proxy":indict["Proxy"]
"Proxy":indict["Proxy"],
"dl_err": indict["dl_err"],
"chunk_size": indict["chunk_size"]
}
f.write(json.dumps(temp_dict,sort_keys=True,indent=4))
f.close()
Expand Down Expand Up @@ -386,7 +392,7 @@ def speedCalc(self,inum):
self.after_size = 0
elif inum == 1:
# 1000/200ms
self.speed = (self.in_dict["Now"] - self.after_size)*5
self.speed = (self.in_dict["Now"] - self.after_size)*5*2
self.after_size = self.in_dict["Now"]


Expand Down Expand Up @@ -447,7 +453,7 @@ def setWindow_catch(self, in_dict):
global indict
if in_dict["code"] == 1:
indict = in_dict["indict"]
self.plainTextEdit.appendPlainText('设置成功(成功修改cookie与网络代理)')
self.plainTextEdit.appendPlainText('设置成功')
QApplication.processEvents()
elif in_dict["code"] == 0:
self.setWindowOPEN = False
Expand Down
4 changes: 4 additions & 0 deletions BiliModule/Setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def __init__(self, ins_dict, parent=None):
self.edit_cookies.setPlainText(ins_dict["cookie"])
self.cb_useProxy.setChecked(ins_dict["useProxy"])
self.lineEdit.setText(ins_dict["Proxy"]["http"])
self.dl_err.setValue(ins_dict["dl_err"])
self.chunk_size.setValue(ins_dict["chunk_size"])
# 设置父窗口阻塞与窗口透明
self.setWindowModality(Qt.ApplicationModal)
self.setWindowFlags(Qt.FramelessWindowHint)
Expand Down Expand Up @@ -79,6 +81,8 @@ def setConfig(self):
self.ins_dict["useProxy"] = False
proxy_url = self.lineEdit.text()
self.ins_dict["Proxy"] = {'http': proxy_url,'https':proxy_url,}
self.ins_dict["dl_err"] = self.dl_err.value()
self.ins_dict["chunk_size"] = self.chunk_size.value()
self._signal.emit({"code":1,"indict":self.ins_dict})
self.close()

Expand Down
199 changes: 195 additions & 4 deletions BiliWorker/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def __init__(self, args, model=0):
self.re_playinfo = 'window.__playinfo__=([\s\S]*?)</script>'
self.re_INITIAL_STATE = 'window.__INITIAL_STATE__=([\s\S]*?);\(function'
self.vname_expression = '<title(.*?)</title>'
self.chunk_size = 1024
self.chunk_size = args["chunk_size"]
self.set_err = args["dl_err"]
self.index_headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
}
Expand Down Expand Up @@ -294,11 +295,11 @@ def d_processor(self, url_list, output_dir, output_file, dest):
video_bytes = request.get(line, headers=self.second_headers, stream=False, timeout=(5,10), proxies=self.Proxy)
vc_range = video_bytes.headers['Content-Range'].split('/')[1]
self.business_info.emit("获取{}流范围为:{}".format(dest,vc_range))
self.business_info.emit('{} 文件大小:{} MB'.format(dest,round(float(vc_range) / self.chunk_size / 1024), 4))
self.business_info.emit('{} 文件大小:{} MB'.format(dest,round(float(vc_range) / 1024 / 1024), 4))
# Get the full video stream
proc = {"Max": int(vc_range), "Now": 0, "finish": 0}
err = 0
while(err <= 3):
while(err <= self.set_err):
try:
self.second_headers['range'] = 'bytes=' + str(proc["Now"]) + '-' + vc_range
m4sv_bytes = request.get(line, headers=self.second_headers, stream=True, timeout=10, proxies=self.Proxy)
Expand Down Expand Up @@ -327,7 +328,7 @@ def d_processor(self, url_list, output_dir, output_file, dest):
if re.findall('10054',str(e),re.S) == []:
err += 1
print(e,err)
if err > 3:
if err > self.set_err:
raise Exception('线路出错,切换线路。')
proc["finish"] = 1
self.progr_bar.emit(proc)
Expand All @@ -341,6 +342,118 @@ def d_processor(self, url_list, output_dir, output_file, dest):
os.remove(output_file)
return 1

# # 线程部署 -> List
# def make_Thread_list(self, url: str, thread_num: int, byte_weight: int, tmp_dir) -> list:
# thread_list = []
# st_byte = -1
# for i in range(thread_num):
# # 确定线程下载范围
# st_byte += 1
# ed_byte = int(byte_weight/thread_num) * (i+1)
# if i == (thread_num - 1):
# ed_byte = byte_weight
# range_tuple = (st_byte, ed_byte)
# # 新建线程类
# t = DLThread(url, range_tuple, tmp_dir+'/{}.tmp'.format(i), self.second_headers, self.Proxy)
# tmp = []
# tmp.append(i)
# tmp.append(t)
# thread_list.append(tmp)
# st_byte = ed_byte
# return thread_list
#
#
# # Download Stream function (NEW)
# def d_processor(self, url_list, output_dir, output_file, dest):
# for line in url_list:
# self.business_info.emit('使用线路:{}'.format(line.split("?")[0]))
# try:
# # video stream length sniffing
# video_bytes = request.get(line, headers=self.second_headers, stream=False, timeout=(5, 10),
# proxies=self.Proxy)
# vc_range = video_bytes.headers['Content-Range'].split('/')[1]
# self.business_info.emit("获取{}流范围为:{}".format(dest, vc_range))
# self.business_info.emit(
# '{} 文件大小:{} MB'.format(dest, round(float(vc_range) / self.chunk_size / 1024), 4))
# # 开始线程分配与文件夹制作
# thread_num = 4
# tmp_dir = output_dir + '/tmp_{}'.format(int(time.time()*1000))
# if not os.path.exists(tmp_dir):
# os.makedirs(tmp_dir)
# thread_queue = self.make_Thread_list(line, thread_num, int(vc_range), tmp_dir)
# # Get the full video stream
# proc = {"Max": int(vc_range), "Now": 0, "finish": 0}
# err = 0
# self.business_info.emit("下载线程数:{}".format(thread_num))
# # 激活线程
# for t in thread_queue:
# t[1].start()
# # 下载线程遍历监视代码
# while(err <= 3):
# # 暂停下载
# if self.pauseprocess:
# for th in thread_queue:
# th[1].pause()
# while self.pauseprocess:
# sleep(1.5)
# if self.killprocess:
# for th in thread_queue:
# th[1].stop()
# return -1
# # 停止下载
# if self.killprocess:
# for th in thread_queue:
# th[1].stop()
# return -1
# # 获取总状态
# progress = 0
# finished_thread = 0
# for th in thread_queue:
# status = th[1].get_status()
# if status['status'] == 3:
# err += 1
# th[1].start()
# if status['now'] >= status['end']:
# finished_thread += 1
# progress += status['progress']
# proc['Now'] = progress
# self.progr_bar.emit(proc)
# sleep(0.5)
# if finished_thread == thread_num:
# break
# if err > 3:
# for th in thread_queue:
# th[1].stop()
# # 删除临时文件与文件夹
# for i in os.listdir(tmp_dir):
# os.remove(tmp_dir + '/{}'.format(i))
# os.remove(tmp_dir)
# raise Exception('线路出错,切换线路。')
# # 进行文件拼接
# self.business_info.emit("正在进行文件拼接.....")
# if os.path.isfile(output_file):
# os.remove(output_file)
# with open(output_file, 'ab') as f:
# for p in thread_queue:
# with open(tmp_dir+'/{}.tmp'.format(p[0]), 'rb') as bf:
# f.write(bf.read())
# # 删除临时文件与文件夹
# for i in os.listdir(tmp_dir):
# os.remove(tmp_dir + '/{}'.format(i))
# os.remove(tmp_dir)
# # 结束下载进程
# proc["finish"] = 1
# self.progr_bar.emit(proc)
# self.business_info.emit("{}成功!".format(dest))
# return 0
# except Exception as e:
# print(e)
# self.business_info.emit("{}出错:{}".format(dest, e))
# if os.path.exists(output_file):
# os.remove(output_file)
# return 1


# FFMPEG Synthesis Function
def ffmpeg_synthesis(self,input_v,input_a,output_add):
if os.path.exists(output_add):
Expand Down Expand Up @@ -826,3 +939,81 @@ def run(self):
self.is_finished.emit(2)
else:
self.is_finished.emit(2)

#
# # 下载线程类
# class DLThread(QThread):
# # 初始化
# def __init__(self, url_str: str, byte_range: tuple, tmp_dir: str, header_dict: dict, proxy_dict: dict):
# super(DLThread, self).__init__()
# assert len(byte_range) == 2
# self.url = url_str
# self.tmpf_dir = tmp_dir
# self.st_byte = byte_range[0]
# self.now_byte = byte_range[0]
# self.ed_byte = byte_range[1]
# self.header = header_dict
# self.Proxy = proxy_dict
# self.chunk_size = 1024
# self.err = 0
# # 线程状态status:0为正常下载,1为暂停下载,2为停止下载,3为下载出错
# self.status = 0
#
# # 获取线程状态
# def get_status(self):
# feedback = {}
# feedback['status'] = self.status
# feedback['start'] = self.st_byte
# feedback['end'] = self.ed_byte
# feedback['now'] = self.now_byte
# feedback['progress'] = self.now_byte - self.st_byte
# feedback['err'] = self.err
# return feedback
#
# def pause(self):
# if self.status == 0:
# self.status = 1
#
# def stop(self):
# self.status = 2
#
# def resume(self):
# if self.status == 1:
# self.status = 0
#
# def run(self) -> None:
# while (self.err <= 3):
# try:
# self.header['range'] = 'bytes=' + str(self.st_byte) + '-' + str(self.ed_byte)
# m4sv_bytes = request.get(self.url, headers=self.header, stream=True, timeout=10, proxies=self.Proxy)
# # if not os.path.exists(output_dir):
# # os.makedirs(output_dir)
# with open(self.tmpf_dir, 'wb') as f:
# for chunks in m4sv_bytes.iter_content(chunk_size=self.chunk_size):
# # 暂停事件函数
# while self.status == 1:
# sleep(1)
# if (self.status == 2) or (self.status == 3):
# return None
# else:
# continue
# if chunks:
# f.write(chunks)
# self.now_byte += self.chunk_size
# # self.progr_bar.emit(proc)
# if self.status == 2:
# m4sv_bytes.close()
# return None
# if self.now_byte >= self.ed_byte:
# m4sv_bytes.close()
# break
# else:
# print("线程范围:{}-{} -> 服务器断开连接,重新连接下载端口....".format(self.st_byte, self.ed_byte))
# except Exception as e:
# if re.findall('10054', str(e), re.S) == []:
# self.err += 1
# print(e, self.err)
# if self.err > 3:
# self.status = 3
# # raise Exception('线路出错,切换线路。')
#
Loading

0 comments on commit ca822a6

Please sign in to comment.