Skip to content

Commit

Permalink
修复:Ctrl+C退出时保存数据,增加稿件时自动保存,以免意外退出使已添加稿件信息未保存
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel2022 committed Jul 24, 2020
1 parent 549d738 commit f680ac5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 8 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@

firststart = True

def exitAction():
def save():
savedata = open(savefile,'wb')
pickle.dump(item_group,savedata)
savedata.close()

def exitAction():
save()
os.system('cls')
print("脚本已退出,记录已保存至" + savefile)
os._exit(0)
Expand Down Expand Up @@ -149,6 +152,7 @@ def action(self):
item = bili_Video(bvid=bvid)
item_group.append(item)
print("已添加%s\n%s" % (bvid,item.title))
save()
elif self.keyword.lower() == 'd':
item_group.pop(len(item_group)-1)
elif self.keyword.lower() == 'cl':
Expand Down Expand Up @@ -378,4 +382,6 @@ def switch(self):
State.statetag = NORMAL
except IndexError:
print("Error:索引错误")
input(ErrorMeassage)
input(ErrorMeassage)
except KeyboardInterrupt:
exitAction()
4 changes: 3 additions & 1 deletion module/bililib.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def show(self):
return string
def autodownload(self,qn=80):
for i in range(len(self.video_list)):
self.video_list[i].load()
if not self.video_list[i].AbleToDownload:
self.video_list[i].load()
self.video_list[i].Flv_downloader(qn=qn,auto=True)

class Videos:
Expand All @@ -142,6 +143,7 @@ def __init__(self,avid=None,bvid=None,cid=None,page=1,title=None,subtitle=None):
self.page = page
self.title = title
self.subtitle = subtitle
self.AbleToDownload = False
self.referer = 'https://www.bilibili.com/video/%s?page=%d' % (self.bvid, self.page)
def load(self):
response = requests.get(GET_VIDEO_DOWNLOAD_URL,{
Expand Down

0 comments on commit f680ac5

Please sign in to comment.