From 59dd56ec779f3e2e1dc75bdfec5e986c5854d538 Mon Sep 17 00:00:00 2001 From: o5_null_company <1517808818@qq.com> Date: Fri, 2 Jun 2023 15:40:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=9B=A0=E4=B8=BA?= =?UTF-8?q?=E4=BD=9C=E5=93=81=E5=88=A0=E9=99=A4=E8=80=8C=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E6=8A=A5=E9=94=99=E3=80=82=E6=9A=82=E6=97=B6=E5=BC=83?= =?UTF-8?q?=E7=94=A8=E4=B8=8B=E8=BD=BD=E9=98=9F=E5=88=97=E6=8C=81=E4=B9=85?= =?UTF-8?q?=E5=8C=96=E3=80=82=E5=A4=A7=E5=B9=85=E5=BA=A6=E6=8F=90=E5=8D=87?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core.py | 24 +++++++++++++++++++++++- loftersaver_130_GUI.py | 18 ++++++++++++++---- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/core.py b/core.py index acef8d9..fe9a897 100644 --- a/core.py +++ b/core.py @@ -13,7 +13,8 @@ import time import json import pickle#数据持久化 - +list = [] +fin_list = [] brower = requests.Session() #创建浏览器 headers = { @@ -72,6 +73,7 @@ def clean_name(strs): strs = strs.replace('&','') strs = strs.replace(':',':') strs = strs.replace('?','?') + strs = strs.replace('|',' ') # 去除不可见字符 return strs @@ -88,7 +90,9 @@ def dic(info): #获取与修改下载列表 def downlist(set='null'): + global list if set == 'null': + return list if os.path.exists('downlist.obj') and os.path.getsize('downlist.obj') > 0: with open('downlist.obj','rb') as f: list = pickle.load(f) @@ -98,12 +102,15 @@ def downlist(set='null'): pickle.dump([],f) return [] else: + list = set with open('downlist.obj','wb') as f: pickle.dump(set,f) #获取与修改完成列表 def finlist(set='null'): + global fin_list if set == 'null': + return fin_list if os.path.exists('finlist.obj') and os.path.getsize('finlist.obj') > 0: with open('finlist.obj','rb') as f: list = pickle.load(f) @@ -113,6 +120,7 @@ def finlist(set='null'): pickle.dump([],f) return [] else: + fin_list = set with open('finlist.obj','wb') as f: pickle.dump(set,f) @@ -153,6 +161,7 @@ def clean_1(data): #获取网站正文文本 #获取txt格式 txt = doc.summary().replace('

','\n')#doc.summary()为提取的网页正文但包含html控制符,这一步是替换换行符 txt = re.sub(r']*>', '', txt) #这一步是去掉<****>内的内容 + txt = txt.replace(' ','') #创个字典存放数据 fine = {} fine['title'] = title @@ -272,6 +281,19 @@ def lofter_api(targetblogid:int,postid:int) -> dict: info['postid'] = postid info['status'] = json_answer['meta']['status']#api状态 info['msg'] = json_answer['meta']['msg']#状态信息 + #判断作品状态 + if str(info['status']) == '4202':#作品被删除 + print(info['msg']) + info['status'] = 404 + info['title'] = '错误' + info['writer'] = {} + info['writer']['name'] = '错误'#作者名 + info['writer']['img'] = ''#作者头图 + info['info'] = ''#文章内容 + info['type'] = 1#文章类型 1为文档 2为含有图片 3为音乐(? + info['img'] = [] + return info + try:#某些特殊玩意根本没有标题参数 info['title'] = json_answer['response']['posts'][0]['post']['title']#文章标题 except: diff --git a/loftersaver_130_GUI.py b/loftersaver_130_GUI.py index df027a1..3ab5236 100644 --- a/loftersaver_130_GUI.py +++ b/loftersaver_130_GUI.py @@ -28,9 +28,13 @@ #开始下载任务 def start_download(): list = core.downlist()#获取下载列表 + list = core.dic(list) + fin_list = 0 + all_list = len(list) + while len(list) != 0:#当下载任务不为0时 + fin_list += 1 lofter_info_down(list[0],set['download'])#下载任务 - time.sleep(0.3) core.del_downlist(list[0])#删除下载完成的任务 #添加到下载完成列表 @@ -39,7 +43,7 @@ def start_download(): core.finlist(fin) #刷新下载进度条 - value = len(fin) / len(list) + value = fin_list / all_list out.set_processbar('down_process',value) list = core.downlist()#刷新下载任务 out.toast('下载任务已清空', position='center', color='success', duration=0)#显示完成通知 @@ -85,7 +89,7 @@ def show_fin_list(): #加载任务列表 data_list = core.finlist()#获取需要下载的列表 if len(data_list) == 0:#如果列表为空则等待 - time.sleep(1) + time.sleep(0.5) show_fin_list() show_list = [] #初始化 @@ -193,6 +197,8 @@ def lofter_post_list(url): def lofter_print(info): #清除旧显示内容 out.clear('info') + if str(info['status']) == '404': + return 'out' with out.use_scope('info'):#进入视频信息域 with out.use_scope('up_info'):#切换到up信息域 face = requests.get(info['writer']['img']).content#缓存图片 @@ -230,6 +236,10 @@ def lofter_list_print(list:list): a += 1 print(url) answer = lofter_down(url)#申请数据 + #如果无法获取数据则跳过 + if str(answer['status']) == '404': + out.toast('哎呀,有作品无法获取',position='left', color='error', duration=1)#弹出提示 + continue out.set_processbar('get_api',a / len(list))#刷新进度条 info_list.append(answer) #遍历创建标题列表 @@ -265,7 +275,7 @@ def lofter_down(url): if answer['status'] != 200:#如果返回不正常 #弹出错误弹窗 out.toast(answer['msg'],color='error',duration='0')#弹出错误弹窗 - return + return answer return answer